scp命令不需要輸入用戶密碼傳輸
scp就是secure copy,是用來進行遠程文件拷貝的。數據傳輸使用ssh,並且和ssh 使用相同的認證方式,提供
相同的安全保證 。
與rcp不同的是,scp在進行驗證時會要求你輸入密碼或口令。
在兩臺機器的兩個用戶之間建立安全的信任關係後,可實現執行scp命令時不需要輸入用戶密碼。
服務器端:
1、開啓ssh服務
2、創建文件夾/root/.ssh
客戶機端:(同樣開啓ssh服務)
1. 在機器Client上root用戶執行ssh-keygen命令,生成建立安全信任關係的證書。
[root@Client root]# ssh-keygen -b 1024 -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: ……
注意:在程序提示輸入passphrase時直接輸入回車,表示無證書密碼。
上述命令將生成私鑰證書id_rsa和公鑰證書id_rsa.pub,存放在用戶目錄的.ssh子目錄中。
2. 將公鑰證書id_rsa.pub複製到機器Server的root目錄的.ssh子目錄中,同時將文件名更換爲
authorized_keys。
[root@Client root]# scp -p .ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys
[email protected]’s password: <– 輸入機器Server的root用戶密碼
在執行上述命令時,兩臺機器的root用戶之間還未建立安全信任關係,所以還需要輸入機器Server的root用戶
密碼。
經過以上2步,就在機器Client的root和機器Server的root之間建立安全信任關係。下面我們看看效果:
[root@Client root]# scp -p text [email protected]:/root
iptables 開啓scp服務:(默認是不開啓的)
# iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
注:iptables中允許的服務(端口)要寫在拒絕的上面,可進/etc/sysconfig/iptables裏自行調整。
變相實現本機帶進度拷貝:
# scp /mnt/a.tar.gz [email protected]:/home
scp本機拷貝默認是不帶進度的(如:# scp /mnt/a.tar.gz /home)
scp常用的一些參數:
-v 和大多數 linux 命令中的 -v 意思一樣 , 用來顯示進度 . 可以用來查看連接,認證,或是配置錯誤。
-C 啓用壓縮選項,
-r 傳遞目錄下的所有內容
-P 選擇端口 . 注意 -p 已經被 rcp 使用 .
-4 強行使用 IPV4 地址 .
-6 強行使用 IPV6 地址 .
scp客戶端(基於windows系統)
http://data1.pcdown.net/goodsoft-l23/201106/WinSCP.rar
解壓後雙擊WinSCP.exe-主機名:192.168.1.12 端口:22 用戶名:root 密碼:123456 文件協議:SFTP
- 登錄-是