Skip to content

Instantly share code, notes, and snippets.

@mvidner mvidner/ssh-pass
Created Mar 22, 2012

Embed
What would you like to do?
#!/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

This comment has been minimized.

Copy link

commented Mar 22, 2012

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
You can’t perform that action at this time.