Tuesday, July 31, 2012

expect a pubkey

i have a pubkey. i need to put it all over the place.
but, i have my pubkey on some systems.


first, i cat my favorite pubkeys into authorized_keys2, then i strip my dns zone file and get all my ip addresses. then i feed that list into this script. if the systems blink, i attempt to scp to them. if i get a password prompt, expect will throw the "i already know it password" in and copy over my keys. yeah. you can get fancy and do other things, but this is a start.


for ip_addr in $(cat strippedzonefile) ; do

ping -q -c 1 $ip_addr &&

expect -c "
spawn scp /my/authorized_keys2 account@$ip_addr:/that/account/.ssh/authorized_keys2
expect \"?assword:*\"
send -- \"securepassword\r\"
expect eof
Post a Comment