知道自動化運維就都知道 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
以上!