Managing multiple servers can be tedious a lot of times; specially remembering the IPs and the ports for each and every single server.
Let's say your server IP is 184.108.40.206, you use port 500 and you use the username is root.
You will be normally using something like that:
$ ssh firstname.lastname@example.org -p 500
Today we will be discussing 3 different ways to make it easier.
1. Shell aliases
You can just create an alias for that by adding this line to your .bashrc
alias my_server="ssh email@example.com -p 500"
and now you can call it like this:
Now let's analyze this method.
The only advantage of this method is that you add one line and it works.
On the other hand this method offers no flexibility so you can't just use
my_server -i ~/.ssh/keys/work.key and you can also conflict with other commands' names; for example add
alias mysql="ssh firstname.lastname@example.org -p 500" as your mysql remote server alias.
2. SSH config file
~/.ssh/config in your favorite editor and let's start.
To achieve the same results of the previous method we must add
Host my_server HostName 220.127.116.11 User root Port 500
now save and then type this in your terminal
$ ssh my_server
This method allows a lot of flexibility as you can type
ssh my_server -i ~/.ssh/keys/work.key or use any of the options that ssh already provides.
The whole problem is that you will need to maintain this file yourself adding each and every server to it (this needs a one-liner).
This is a method that will maintain your ssh config file with simple commands
sshez my_server email@example.com -p 500
and now you can
you can install sshez by
$ gem install sshez
The only problem that it is currently dependent on ruby which is too much for just a CLT, but there will be a python clone very soon.