在兩台機器的兩個使用者之間建立安全的信任關係後,可實現執行scp命令時不需要輸入使用者密碼。
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 root@172.16.100.188:/root/.ssh/authorized_keys
root@192.168.3.206’s password: <– 輸入機器Server的root使用者密碼
在執行上述命令時,兩台機器的root使用者之間還未建立安全信任關係,所以還需要輸入機器Server的root使用者密碼。
經過以上2步,就在機器Client的root和機器Server的root之間建立安全信任關係。下面我們看看效果:
[root@Client root]# scp -p text root@192.168.3.206:/root
成功了!真的不再需要輸入密碼了。