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.
First check if you have the snippet listed below inside your '.bashrc' file. It is used to include the aliases file, so if you don't have it, please paste it in.
if [ -f ~/.bash_aliases ]; then
Now you can create .bash_aliases in your home folder and define the alias for an SSH connection using the template below:
alias a_name_for_the_alias='sudo ssh -p PORT_NUMBER -o IdentityFile=~/.ssh/YOUR_PRIVATE_KEY_FILE YOUR_REMOTE_USERNAME@THE_REMOTE_SERVER'
Finally you need to refresh the configuration by executing .bashrc.
Update ... achieve the same by using your SSH configuration file
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
Then, typing `ssh to_dev` will take you to your remote server.