Skip to content

Instantly share code, notes, and snippets.

@matti
Created July 10, 2015 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matti/f93a46602c914dc986e4 to your computer and use it in GitHub Desktop.
Save matti/f93a46602c914dc986e4 to your computer and use it in GitHub Desktop.
expect send authorized_keys before
#!/usr/bin/expect -f
# NOTE: ..and then I discovered ssh-copy-id && sshpass: sshpass -p raspbian ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 root@pi
set rpi_host [lindex $argv 0];
set rpi_host_port [lindex $argv 1];
set authorized_key [lindex $argv 2];
spawn scp -P $rpi_host_port -o PubkeyAuthentication=no -r $authorized_key root@$rpi_host:authorized_keys
expect "assword:"
send "raspbian\r"
expect "*\r"
expect "\r"
spawn ssh -o PubkeyAuthentication=no root@$rpi_host -p $rpi_host_port
expect "assword:"
send -- "raspbian\r"
sleep 1
expect "Debian"
send "mkdir -p .ssh\r"
send "mv authorized_keys .ssh\r"
send "chmod -R u=rw,go= .ssh\r"
sleep 1
send "ls -la .ssh\r"
expect "authorized_keys"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment