linux ssh互免密配置
生活随笔
收集整理的這篇文章主要介紹了
linux ssh互免密配置
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、產生背景
????在實際工作中,linux集群需要自動化的管理,市面上較常見的自動化運維工具諸如ansible,puppet,saltstack;輕量級的有pssh系列,這其中大多數工具使用的前提就是集群配置有公鑰機可免密ssh登錄集群內所有服務器,所以要先配置一臺公鑰機使用。
二、配置實例
????1、在除公鑰機外所以服務器生成密鑰
[root@test?~]#?cd?/root/.ssh/ [root@test?.ssh]#?ll 總用量?4 -rw-r--r--.?1?root?root?396?11月??1?2016?known_hosts [root@test?.ssh]#?ssh-keygen?-t?rsa Generating?public/private?rsa?key?pair. Enter?file?in?which?to?save?the?key?(/root/.ssh/id_rsa):? Enter?passphrase?(empty?for?no?passphrase):? Enter?same?passphrase?again:? Your?identification?has?been?saved?in?/root/.ssh/id_rsa. Your?public?key?has?been?saved?in?/root/.ssh/id_rsa.pub. The?key?fingerprint?is: SHA256:cBjbvfy9VkWLQpJESgqLHeq923mm4EF1Vb1L4wGs0IU?root@test The?key's?randomart?image?is: +---[RSA?2048]----+ |???o??..++*o.????| |??+?+?o*oE?+?.??.| |?o?o?o+o+?=?.?o..| |.?.?.?.o?o?o?*?..| |?.?o????S?o?+?+?.| |??.?.??????.?+??.| |???+????????.?..?| |??.?=?.o??????..?| |???o?++??????..??| +----[SHA256]-----+ [root@test?.ssh]#? [root@test?.ssh]#?ll 總用量?12 -rw-------.?1?root?root?1679?11月??2?11:43?id_rsa -rw-r--r--.?1?root?root??391?11月??2?11:43?id_rsa.pub -rw-r--r--.?1?root?root??396?11月??1?2016?known_hosts????2、在第一臺服務器上創建authorized_keys文件,并修改權限,用以保存所有服務器的公鑰
????3、將authorized_keys文件復制到下一臺服務器,并重復以上兩個步驟
[root@test?.ssh]#?scp?authorized_keys?root@192.168.0.11:~/.ssh/????4、重復以上步驟,直至最后一臺服務器,將authorized_keys文件復制到第一臺機器對應目錄下
[root@test?.ssh]#?scp?authorized_keys?root@192.168.0.1:~/.ssh/ [root@test?.ssh]#?chmod?600?authorized_keys????
????5、在第一臺機器上將authorized_keys文件復制給所有機器
[root@test?~]#?pscp?-h?serverlist.txt??/root/.ssh/authorized_keys?/root/.ssh/authorized_keys????6、測試互免密ssh登錄其他服務器即可
三、腳本實現
[root@Nginx?bin]#?yum?install?expect?-y [root@Nginx?bin]#?find?/?-name?expect /usr/bin/expect [root@Nginx?bin]#?touch?/root/.ssh/authorized_keys [root@Nginx?bin]#?vim?self_ssh.sh?1?#!/usr/bin/expect?-f2?#3?set?timeout?34?set?ip_list?[open?/home/jiayimeng/bin/ip?r]5?while?{?[gets?$ip_list?line?]>=0?}?{6?????set?ip?[lindex?$line?0]7?????spawn?ssh?root@$ip8?????expect?"*yes/no:"?{?send?"yes\r"?}9?????expect?"*password:"?{?send?"123456\r"?}10?????expect?"#"11?????send?"cat?/root/.ssh/id_rsa.pub?|?ssh?root@192.168.3.25?'cat?????>>?.ssh/authorized_keys'\r"12?????expect?"*password:"?{?send?"123456\r"?}13?????expect?"#"?{?send?"exit\r"}14?????interact15?}ip中寫明所有機器的ip地址四、總結
????在不連接外部互聯網的特定集群中,公鑰機的使用大大方便了運維人員管理維護集群,系統集成人員集成施工的一系列操作;同時,由于公鑰機的特殊,要做好公鑰機的安全工作。
轉載于:https://blog.51cto.com/jiayimeng/1978370
總結
以上是生活随笔為你收集整理的linux ssh互免密配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: zabbix监控windows进程
- 下一篇: 厉害了黑科技,动态安全下的防拖库原来可以