一、scp 命令:
scp 是 secure copy 的縮寫,scp 是Linux系統下基於 ssh 登入進行安全的遠程文件拷貝命令。
格式為:scp [可選參數] file_source file_target
1、從本地復制到遠程
格式為: scp local_file remote_username@remote_ip : remote_folder
實例為: scp /home/space/music/1.mp3 root@www.runoob.com:/home/root/others/music
2、從遠程復制到本地
從遠程復制到本地,只要將從本地復制到遠程的命令的后2個參數調換順序即可,如下:
scp root@www.runoob.com:/home/root/others/music /home/space/music/1.mp3
如果遠程服務器防火牆有為scp命令設置了指定的端口,我們需要使用 -P 參數來設置命令的端口號,如下:
scp -P 4588 remote@www.runoob.com:/usr/local/sin.sh /home/administrator
使用scp命令要確保使用的用戶具有可讀取遠程服務器響應文件的權限,否則scp命令是無法起作用的
詳細請查看菜鳥教程:https://www.runoob.com/linux/linux-comm-scp.html
[root@WebServer3 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
a2:1d:43:32:26:06:68:48:d5:62:16:6d:a2:c7:53:8c root@WebServer3
輸入 ssh-keygen -t rsa命令后直接都按回車就行。
第一提示是密鑰保存位置
Enter file in which to save the key (/root/.ssh/id_rsa):
直接回車保存到默認地方 /root/.ssh/id_rsa
第二個提示是輸入一個不同於你的password的密碼。直接按回車,不輸入密碼,保持密碼為空。
其中公共密鑰保存在 ~/.ssh/id_rsa.pub
私有密鑰保存在 ~/.ssh/id_rsa
拷貝密鑰文件到目標服務器
[root@WebServer3 ~]#scp ~/.ssh/id_rsa.pub 192.168.0.23:/root/.ssh/authorized_keys
配置完畢,你在這台機器上用scp ssh sftp 命令訪問目標機器的時候就不用輸入密碼了
參考文檔:https://www.cnblogs.com/jikexianfeng/p/5813718.html