Linux免密登录

Linux下生成秘钥

执行如下命令:

ssh-keygen -t rsa
Linux免密登录_第1张图片
2016101217190931.png

执行之后会在用户的根目录生成一个 “.ssh”的文件夹


Linux免密登录_第2张图片
图片.png

进入“.ssh”会生成以下几个文件


Linux免密登录_第3张图片
图片.png

远程免密登录

通过ssh-copy-id上传远程服务器

命令: ssh-copy-id -i ~/.ssh/id_rsa.put

举例:

[root@test .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.91.135 
[email protected]'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 [email protected]
Last login: Mon Oct 10 01:25:49 2016 from 192.168.91.133
[root@localhost ~]#

Linux免密登录_第4张图片
图片.png

通过ssh 登录测试

常见错误:

[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下实现免密码登录(超详细)

你可能感兴趣的:(Linux免密登录)