1.生成密钥和分发公钥的两条命令
ssh-keygen -t rsa|dsa -P ‘‘ ssh-copy-id -i ~/.ssh/id_dsa.pub "-p2222 [email protected]"
2.使用expect的简单分发脚本,实现自动交互
###shell scripts powered by troy### #!/bin/bash ##deliver pubkey## dsa_pub_key="/home/troy/.ssh/id_dsa.pub" [ ! -e $dsa_pub_key ]&&{ expect << EOF set timeout -1 spawn ssh-keygen -t dsa -p ‘‘ expect "*save the key*" send "\r" expect eof; EOF } for ip in $(awk ‘/^[^#]/{print $1}‘ all_client.txt) do port=$(grep "^${ip}" all_client.txt|awk ‘{print $2}‘) expect << EOF set timeout -1 spawn ssh-copy-id -i $dsa_pub_key "-p$port [email protected]$ip" expect { "*yes/no*" {send "yes\r";exp_continue} "*password*" {send "tobeno.1\r"} } expect eof; EOF done
3.分发的ip端口配置文件
cat all_client.txt #ip port 172.16.100.104 2222 172.16.100.128 2222
更多的用法,还在学习当中。。。
TBD!
时间: 2024-10-09 02:48:06