Skip to content

Instantly share code, notes, and snippets.

@jkullick
Last active June 25, 2022 18:03
Show Gist options
  • Save jkullick/d37df168b430f3a6611fae68e4501c98 to your computer and use it in GitHub Desktop.
Save jkullick/d37df168b430f3a6611fae68e4501c98 to your computer and use it in GitHub Desktop.
Automate SSH Password Login in Scripts with Expect
  1. Create ssh_wrapper.exp:
#!/usr/bin/expect -f

eval spawn [lrange $argv 1 end]
expect "*?assword:*"
send [lindex $argv 0]
send "\r"
interact
  1. Run chmod +x ssh_wrapper.exp

  2. Run command over SSH with wrapper script:

SSH:

./ssh_wrapper $SSH_PASSWORD ssh -t -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST $COMMAND

SCP:

./ssh_wrapper $SSH_PASSWORD scp -r $LOCAL_DIR/. $SSH_USER@$SSH_HOST:§REMOTE_DIR/

Source

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