1. Two commands for generating keys and distributing public keys
Ssh-keygen-t rsa|dsa-p "Ssh-copy-id-i ~/.ssh/id_dsa.pub"-p2222 [email protected] "
2. Use expect's simple distribution script for automatic interaction
# # #shell Scripts powered by troy####!/bin/bash# #deliver pubkey# #dsa_pub_key = "/home/troy/.ssh/id_dsa.pub" [!-e $dsa _ Pub_key]&&{expect << eofset timeout-1spawn ssh-keygen-t dsa-p "expect" *save the key* "send" \ r "Expect E of; Eof}for IP in $ (awk '/^[^#]/{print $ ' all_client.txt) doport=$ (grep "^${ip}" All_client.txt|awk ' {print $} ') Expect < < Eofset timeout-1spawn ssh-copy-id-i $dsa _pub_key "-p$port [email protected] $ip" expect {"*yes/no*" {send "yes\r"; ex P_continue} "*password*" {send "tobeno.1\r"}}expect eof; Eofdone
3. Distribution of IP port configuration files
Cat All_client.txt #ip port172.16.100.104 2222172.16.100.128 2222
More usage, still learning ...
tbd!
This article is from the "top of Operations" blog, please be sure to keep this source http://trnux.blog.51cto.com/6998102/1660690
Simple script for SSH Key distribution