mac使用ssh-keygen和ssh-copy-id三步实现SSH无密码登录

来源:互联网 发布:群晖网络存储 编辑:程序博客网 时间:2024/05/16 18:56
ssh-keygen :产生公钥与私钥对.
ssh-copy-id :将本机的公钥复制到远程机器的authorized_keys文件中,ssh-copy-id也能让你有到远程机器的home, ~./ssh , 和 ~/.ssh/authorized_keys的权利
以下是实现步骤:
第一步:在本地机器上使用ssh-keygen产生公钥私钥对
  1. zhz@zhz:~/$ ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/zhz/.ssh/id_rsa):
  2. Enter passphrase (empty for no passphrase): [Press enter key
  3. same passphrase again: [Pess enter key]
  4. Your identification has been saved in /home/zhz/.ssh/id_rsa.
  5. Your public key has been saved in /home/zhz/.ssh/id_rsa.pub.
  6. The key fingerprint is:
  7. 用cat命令查看是否生成产生公钥私钥对
  8. zhz@zhz:~$ cat .ssh/id_rsa.pub
  9. 如果生成成功,则进行下一步
  10. 第二步:用ssh-copy-id将公钥复制到远程机器中
  11. 但是默认MAC没有ssh-copy-id命令,但是我们可以手动给心爱的mac安装这个常用到的命令
  12. 这个是github上找到的解决办法https://github.com/beautifulcode/ssh-copy-id-for-OSX
  13. 执行下面的这个命令,请求并执行ssh-copy-id安装命令
  14. sudo curl -L https://raw.githubusercontent.com/beautifulcode/ssh-copy-id-for-OSX/master/install.sh | sh
  15. 本人执行的时候会因为/usr/local下没有bin文件夹而失败,只需要在/usr/local文件夹下sudo mkdir bin新建一个bin目录
  16. 然后出现Installed ssh-copy-id into /usr/local/bin说明安装成功,接下来便可用用ssh-copy-id将公钥复制到远程机器中
  17. ssh-copy-id -i .ssh/id_rsa.pub  用户名字@xxx.xxx.xxx.xxx
  18. 这时候会让你输入登录密码,输入登录密码之后便OK了
  19. 之后再执行ssh 用户名@xxx.xxx.xxx.xxx便不需要密码
0 0
原创粉丝点击