ssh-copy-id命令可以將本地的公鑰添加到遠程機器的authorized_keys中,從而實現(xiàn)SSH無密碼登錄惭缰。
在使用ssh-copy-id命令時,出現(xiàn)了如下錯誤:
# ssh-copy-id -i id_rsa.pub kiwenlau@136.187.59.2
/usr/bin/ssh-copy-id: ERROR: failed to open ID file './id_rsa': No such file
命令的輸出信息提示沒有私鑰"id_rsa"文件铡羡∶窦伲可知,ssh-copy-id命令執(zhí)行時將檢查公鑰id_rsa.pub所在目錄是否存在私鑰id_rsa抓于,若沒有私鑰則會導致命令執(zhí)行失敗做粤。
這個問題的解決辦法很簡單,使用touch命令在公鑰id_rsa.pub所在目錄下創(chuàng)建一個空文件“id_rsa”即可捉撮。
# touch id_rsa
然后ssh-copy-id命令就可以執(zhí)行成功了怕品。
# ssh-copy-id -i id_rsa.pub kiwenlau@192.168.59.2
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'kiwenlau@192.168.59.2'"
and check to make sure that only the key(s) you wanted were added.
這時,使用ssh登錄遠程主機將不需要輸入密碼巾遭。
# ssh kiwenlau@192.168.59.2
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-32-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Sat Jun 20 15:39:25 JST 2015
System load: 0.0 Processes: 93
Usage of /: 13.0% of 17.34GB Users logged in: 1
Memory usage: 22% IP address for eth0: 192.168.59.2
Swap usage: 0% IP address for docker0: 172.17.42.1
Graph this data and manage this system at:
https://landscape.canonical.com/
22 packages can be updated.
2 updates are security updates.
Last login: Sat Jun 20 15:39:25 2015 from 192.168.59.3
版權聲明
轉載請注明作者KiwenLau和本文地址:http://kiwenlau.com/2015/06/20/ssh-copy-id-error/