#!/usr/bin/expect
# Connects via SSH to the host passed as argument
set timeout 60
set server [lindex $argv 0]
set username <USERNAME>
set password [exec sudo cat <PATH_TO_YOUR_PASSWORD_FILE>]
spawn ssh $username@$server
expect {
"yes/no" { send "yes\r" ; exp_continue }
"\*?assword" { send "$password\r" }
}
interact
Edit: Please remove all permissions from the password file with: chmod a-rwx <PATH_TO_PASSWORD_FILE>
I’m also assuming you run this script on an environment you control and trust. Be wary of your password.
A bit more context if it matters, I use it very lightly, and I’m interested on ease of use and ability to have a DB attached to it (I was using PostgreSQL, but any SQL DB would do it).