Skip to content

Instantly share code, notes, and snippets.

@praveen-webartisan
Last active March 22, 2024 15:33
Show Gist options
  • Save praveen-webartisan/058203d0e140f1e109caec6fd0ffa744 to your computer and use it in GitHub Desktop.
Save praveen-webartisan/058203d0e140f1e109caec6fd0ffa744 to your computer and use it in GitHub Desktop.
Custom SSH Command: Customize SSH command in Bash script to access Nodes easily
#!/bin/bash
# To Run this file as a Command, Create ~/.bash_aliases file and put the following:
# alias ssh='/path to customSSHCommand.sh ssh'
# alias sftp='/path to customSSHCommand.sh sftp'
type="$1"
provider="$2"
if [ -z "$type" ] || [ -z "$provider" ]
then
echo "Invalid SSH/SFTP command!"
echo ""
echo "First parameter should be either ssh or sftp."
echo "Second parameter should be the provider name defined in $0 file."
exit 1
fi
portOption="-o StrictHostKeyChecking=no -p"
cmdName="ssh"
if [ "$type" = "ftp" ] || [ "$type" = "sftp" ]
then
portOption="-P"
cmdName="sftp"
fi
case "$provider" in
"server1")
sshpass -p 'PASSWORD' $cmdName $portOption 22 user1@server1
;;
"server2")
sshpass -p 'PASSWORD' $cmdName $portOption 22 user2@server2
;;
*)
echo "Given SSH option is not in the List!"
# Fall to default SSH command
ssh "$@"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment