ssh-copy-id出错: "No such file"

ssh-copy-id命令可以将本地的公钥添加到远程机器的authorized_keys中,从而实现SSH无密码登录。

在使用ssh-copy-id命令时,出现了如下错误:

# 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命令执行时将检查公钥id_rsa.pub所在目录是否存在私钥id_rsa,若没有私钥则会导致命令执行失败。

这个问题的解决办法很简单,使用touch命令在公钥id_rsa.pub所在目录下创建一个空文件“id_rsa”即可。

# touch id_rsa

然后ssh-copy-id命令就可以执行成功了。

# 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/


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group...
    shuff1e阅读 1,810评论 1 11
  • ** SSH(安全外壳协议) **为 Secure Shell 的缩写,由 IETF 的网络小组(Network ...
    linfree阅读 867评论 4 7
  • SSH全称Secure SHell,顾名思义就是非常安全的shell的意思,SSH协议是IETF(Internet...
    StarShift阅读 2,581评论 0 7
  • SSH原理与应用 ssh在程序员的生活中还是非常常见的,ssh具有很多种功能,也可以用在很多种场合。 什么是SSH...
    关玮琳linSir阅读 880评论 1 10
  • 契诃夫曾经说过,“生活是恼人的牢笼。一个有思想的人到成年时期,对生活有了成熟的感觉,他就不能不感到他关在一个无从脱...
    雅楠原创阅读 459评论 2 3