Skip to content

Instantly share code, notes, and snippets.

@weaming
Last active August 17, 2021 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weaming/6988c473ad7e289b6d3a57f52070ccda to your computer and use it in GitHub Desktop.
Save weaming/6988c473ad7e289b6d3a57f52070ccda to your computer and use it in GitHub Desktop.
#!/bin/bash
# macos: brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
user=$1
ip_or_tail=$2
if echo $ip_or_tail | grep -E '\.' >/dev/null; then
user_host=$user@$ip_or_tail
else
user_host=$user@192.168.1.$ip_or_tail
fi
echo $user_host
passwd=$(cat ~/.ssh/passwords | grep "$user_host" | awk '{print $2}')
if [ -z "$passwd" ]; then
echo missing password in file ~/.ssh/passwords:
cat ~/.ssh/passwords
exit 1
fi
shift
shift
sshpass -p $passwd ssh -oStrictHostKeyChecking=no $user_host $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment