In today's tutorial I will show you how to use Bash aliases to create 'shortcuts' to your ssh connections on Ubuntu. This will save you a lot of typing and remembering which private key is used for which server.
All you need to do that is to type a few simple commands, so open up your terminal and follow the steps below. I also made a video so you can just watch the screen-cast at the bottom of the article.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
alias a_name_for_the_alias='sudo ssh -p PORT_NUMBER -o IdentityFile=~/.ssh/YOUR_PRIVATE_KEY_FILE [email protected]_REMOTE_SERVER'
source ~/.bashrc
Thanks to mooism2 who pointed out a better way of doing this, I am updating this article with a snippet that should be added to your SSH configuration file.
# contents of $HOME/.ssh/config
Host to_dev
HostName dev.yourdomain.com
Port 22000
IdentityFile ~/.ssh/some.key
User username
Then, typing `ssh to_dev`
will take you to your remote server.