|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#!/bin/sh
while read ip password
do
expect <<EOF
set timeout 3
#spawn ssh root@$ip
spawn scp /root/.ssh/id_rsa.pub root@$ip:/root/.ssh/authorized_keys
expect {
"*yes/no" {send "yes\r";exp_continue}
"*password:" {send "$password\r"}
}
expect eof
EOF
done < ip.txt
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/bin/bash
#2013-7-17
#version 1.0
autologin(){
expect -c "
set timeout -1;
#a=cat 1.txt
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $1
expect {
"*yes/no" {send "yes"\r;exp_continue}
"*assword*" {send $2\r}
}
interact;"
}
for ((i=1;i<=`cat 1.txt|wc -l`;i++))
do
line=`sed -n "${i}p" 1.txt`
IP=`echo $line|awk '{print $1}'`
PASS=`echo $line|awk '{print $2}'`
autologin $IP $PASS
done
|
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/14710393/viewspace-2118574/ ,如需转载,请注明出处,否则将追究法律责任。