Skip to content

Instantly share code, notes, and snippets.

@zxteloiv
Last active January 23, 2016 08:22
Show Gist options
  • Save zxteloiv/4501935 to your computer and use it in GitHub Desktop.
Save zxteloiv/4501935 to your computer and use it in GitHub Desktop.
Shell scripts to securely log in to remote machine from a shared machine.Users can use `ps aux` to see what others are doing. So if you set password to perform auto-login in command arguments, that password will be easily seen by others.expect script can read from file, that means if you stores password in a file, `ps aux` will not expose your p…
# password file that stores user name and password
sessionid 192.168.1.15 user123 pass123
session=$1
col=$2
pfile=$3
# col1 col2 col3 col4
# id ip username passwd
awk '{if ($1 == session) { print $col; exit; } }' session=$session col=$col $pfile
#!/usr/bin/expect -f
set timeout 360
set session [lindex $argv 0]
# col1 col2 col3 col4
# id ip username passwd
set ip [exec bash get_passwd.sh $session 2 door.lst]
set user [exec bash get_passwd.sh $session 3 door.lst]
set pass [exec bash get_passwd.sh $session 4 door.lst]
spawn /usr/bin/ssh -o ServerAliveInterval=120 -l $user $ip
while (1) {
expect {
"*password:" { send "$pass\r"; break; }
"yes/no" { send "yes\r"; break; }
}
}
interact
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment