Skip to content

Instantly share code, notes, and snippets.

@mvidner
Created March 22, 2012 13:00
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 mvidner/2158225 to your computer and use it in GitHub Desktop.
Save mvidner/2158225 to your computer and use it in GitHub Desktop.
#!/usr/bin/expect
# usage: ssh-password mysecret command...
# where command is ssh user@machine
# or ssh-copy-id user@machine
# ...
match_max 100000
set timeout -1
set password [lrange $argv 0 0]
spawn {*}[lrange $argv 1 end]
# Look for passwod prompt
expect "*?assword:*"
# Send password aka $password
send -- "$password\r"
interact
@jreidinger
Copy link

Well, my own version. Work well with unknown hosts, skip passphrase check ( can be modified ) and play nicely when command is given so e.g. ssh root@machine cat /etc/issue in this case your doesn't work

#!/usr/bin/expect
#usage ssh-autologin pwd [command]
set timeout -1
set password [lindex $argv 0]
spawn {*}[lrange $argv 1 end]
while {1} {
  expect "*assword:"             { send "$password\r" } \
    "Are you sure you want to continue connecting (yes/no)?" { send "yes\r" } \
    "Enter passphrase for key " { send "\r" } \
    eof { 
      set interact 0
      break
    } \
    "Last login" { 
      set interact 1
      break 
    }
}
if { $interact == 1 } {
  interact
} else {
  wait
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment