標籤:blog io for 檔案 sp div on log linux
在兩台機器的兩個使用者之間建立安全的信任關係後,可實現執行scp命令時不需要輸入使用者密碼。
1. 在機器Client上root使用者執行ssh-keygen命令,產生建立安全信任關係的認證。
[[email protected] root]# ssh-keygen -b 1024 -t rsaGenerating 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。
[[email protected] 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之間建立安全信任關係。下面我們看看效果:
[[email protected] root]# scp -p text [email protected]:/root
成功了!真的不再需要輸入密碼了。
注意:不要吧使用者目錄的.ssh子目錄中私密金鑰認證id_rsa和密鑰憑證id_rsa.pub刪掉,否則就不好使了
linux下 scp命令不需要輸入使用者密碼