您的位置:首页 > 运维架构 > Linux

Centos 无密码登录

2016-04-01 17:15 447 查看
知道自动化运维就都知道 Ansible,知道Ansible那类工具就都知道无密码登录;

无密码? 还不就是ssh信任么?虽然一般自动化运维都自带一些生成工具,但是不可能仅仅为了二、三台弄的那么麻烦~

而其实sshd自带的生成工具很简单!就那么几步解决无密码登录。

192.168.1.1 ansible

192.168.1.2 node1

192.168.1.3 node2

1、 到ansible主机上的sshd_config开启下面的参数并reload sshd。

RSAAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

2、 尽量不用scp,使用原生的ssh-copy-id进行密码传输

①、使用ssh-keygen -d 生成DES加密公钥;

②、使用将域名写入hosts文件后使用ssh-copy-id进行登录与公钥传输;

node1:

[root@localhost ~]# ssh-copy-id -i .ssh/id_dsa.pub root@node1
The authenticity of host 'node1 (192.168.1.2)' can't be established.
RSA key fingerprint is 28:7f:ab:9a:76:08:0d:5b:55:5c:c5:c9:a0:04:b2:15.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node1,192.168.1.2' (RSA) to the list of known hosts.
root@node1's password:
Now try logging into the machine, with "ssh 'root@node1'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[root@localhost ~]# ssh node1
Last login: Sat Apr  2 00:48:09 2016
[root@node1 ~]# logout
Connection to node1 closed.
[root@localhost ~]# clear


node2:

[root@localhost ~]# ssh-copy-id -i .ssh/id_dsa.pub root@node2
The authenticity of host 'node2 (192.168.1.3)' can't be established.
RSA key fingerprint is 28:7f:ab:9a:76:08:0d:5b:55:5c:c5:c9:a0:04:b2:15.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2,192.168.1.3' (RSA) to the list of known hosts.
root@node2's password:
Now try logging into the machine, with "ssh 'root@node2'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[root@localhost ~]# ssh node2
Last login: Sat Apr  2 00:49:19 2016
[root@node2 ~]# logout
Connection to node2 closed.
[root@localhost ~]# clear


以上!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: