Paste_Image.png
1姨涡、生成key
ssh-keygen -t
ls
id_rsa id_rsa.pub
2屎开、使當(dāng)前主機(jī)也可以用剛才生成的key登陸
cat id_rsa.pub > /root/.ssh/authorized_keys
# ls /root/.ssh/
authorized_keys known_hosts
3、下載key
# sz id_rsa
4甫贯、修改ssh配置文件
# vim /etc/ssh/sshd_config
PubkeyAuthentication yes
AuthorizedKeysFile /root/.ssh/authorized_keys
PasswordAuthentication no /*禁止密碼驗(yàn)證登錄
5吼鳞、重啟ssh服務(wù)(非必要)
# service sshd restart
停止 sshd: [確定]
正在啟動(dòng) sshd: [確定]
6、復(fù)制公鑰到其他機(jī)器(104.5為目標(biāo)機(jī)器)
# ssh-copy-id -i ./id_rsa root@192.168.104.5
root@192.168.104.5's password:
Now try logging into the machine, with "ssh 'root@192.168.104.5'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
7获搏、登錄驗(yàn)證
# ssh -i id_dsa root@192.168.104.5
Last login: Mon Dec 28 11:07:31 2015 from 192.168.104.1
[root@host-192-168-104-5 ~]#
8赖条、批量拷貝到其他機(jī)器可以使用
ansible all -i ../iplist -m shell -a "mkdir /home/admin/.ssh" -u admin
ansible all -i ../iplist -m copy -a "src=./online_id_rsa.pub dest=/home/admin/.ssh/authorized_keys" -u admin
ansible all -i ../iplist -m shell -a "chmod 700 /home/admin/.ssh" -u admin
ansible all -i ../iplist -m shell -a "chmod 600 /home/admin/.ssh/authorized_keys" -u admin