知道自动化运维就都知道 Ansible,知道Ansible那类工具就都知道无密码登陆;node
无密码? 还不就是ssh信任么?虽然通常自动化运维都自带一些生成工具,可是不可能仅仅为了2、三台弄的那么麻烦~运维
而其实sshd自带的生成工具很简单!就那么几步解决无密码登陆。ssh
192.168.1.1 ansible工具
192.168.1.2 node1加密
192.168.1.3 node2code
一、 到ansible主机上的sshd_config开启下面的参数并reload sshd。ci
RSAAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys域名
二、 尽可能不用scp,使用原生的ssh-copy-id进行密码传输it
①、使用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
以上!