Created
June 10, 2014 16:11
-
-
Save marcoemorais/b81e77c9e68f930732b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat copy_ssh_keys.sh | |
#!/usr/bin/env bash | |
file="$1" | |
if [ ! -f "$file" ] ; then | |
echo "Usage: $0 [FILE]" | |
exit 1 | |
fi | |
user=`whoami` | |
echo "password: \c" | |
read password | |
while read host ; do | |
echo $host | |
./copy_ssh_keys_expect.sh $user $password $host | |
done <$file | |
$ cat copy_ssh_keys_expect.sh | |
#!/usr/bin/expect | |
set user [lindex $argv 0] | |
set password [lindex $argv 1] | |
set host [lindex $argv 2] | |
set timeout 60 | |
spawn scp $env(HOME)/.ssh/authorized_keys $user@$host:./.ssh/authorized_keys | |
while {1} { | |
expect { | |
eof {break} | |
"The authenticity of host" {send "yes\r"} | |
"password:" {send "$password\r"} | |
"*\]" {send "exit\r"} | |
} | |
} | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment