Skip to content

Instantly share code, notes, and snippets.

@unsafe9
Last active May 29, 2019 11:45
Show Gist options
  • Save unsafe9/89643d2f48a83431203762e33a8558c9 to your computer and use it in GitHub Desktop.
Save unsafe9/89643d2f48a83431203762e33a8558c9 to your computer and use it in GitHub Desktop.
ssh-wrapper (.ssh/config with sshpass)
#!/bin/bash
# echo 'alias ssh=ssh-wrapper' >> ~/.bashrc
# echo 'source ~/.bashrc' >> ~/.profile
password=$(awk '
BEGIN {
# Collect the SSH arguments as keys of a dictionary, so that we can easily
# check for inclusion.
for (i = 2; i < ARGC; i++) {
sshArgs[ARGV[i]] = 1
}
# Only process the first argument; all others are the command-line arguments
# given to ssh.
ARGC = 2
}
/^\s*Host\s*/ {
if ($2 in sshArgs)
inhost=1
else
inhost=0
}
$1 == "Password" && inhost { print $2 }
' ~/.ssh/config "$@")
if [ "$password" ]; then
sshpass -p "$password" "$(which ssh)" "$@"
else
"$(which ssh)" "$@"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment