Linux下生成秘钥
执行如下命令:
ssh-keygen -t rsa
2016101217190931.png
执行之后会在用户的根目录生成一个 “.ssh”的文件夹
图片.png
进入“.ssh”会生成以下几个文件
图片.png
远程免密登录
通过ssh-copy-id上传远程服务器
命令: ssh-copy-id -i ~/.ssh/id_rsa.put <romte_ip>
举例:
[root@test .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.91.135
root@192.168.91.135's password:
Now try logging into the machine, with "ssh '192.168.91.135'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[root@node3 .ssh]# ssh root@192.168.91.135
Last login: Mon Oct 10 01:25:49 2016 from 192.168.91.133
[root@localhost ~]#
图片.png
通过ssh <ip>登录测试
常见错误:
[root@node1 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.91.135
-bash: ssh-copy-id: command not found //提示命令不存在
解决办法:yum -y install openssh-clients
参考链接:Linux下实现免密码登录(超详细)