Did you already lost hours because you lost your information to connect to a server after months not using it?
If it is the case what we will detail in this article will interest you for sure and make you save time for sure.
The problem
Most of time, as a developer we have multiple servers we have to interact with. However our brain has limited capacities and this can rapidly become a mess when we have to interact with server we didn’t worked with since a week or a month.
Often the IP of the server is lost in a mountain of commands and it can be even worse for the key used to connect to the server which can be lost somewhere on the filesystem.
This two problems are a certainly small but really repetitive and over a year it is hours to days you are loosing.
Giving to the IP a name
The first problem we will be solving is the problem with the IP of the server.
What we will do is that we will give it a name that we can remember later.
For that we will have to edit the file /etc/hosts and add this line where:
- xxx.xxx.xxx.xxx is your IP.
- server_name is the name you want to give it.
xxx.xxx.xxx.xxx server_name
Once we have set this now instead of using the ip in our ssh command we can use the name we gave it which is a way easier to remember.
Saving login details
The second thing to do is to find a way to remember our key everytime we connect to the server.
For that we will use ssh configuration file which will help us to set a default password for the server.
For that we will have to add content or create ~/.ssh/config.
To connect to the server then you add the following content:
Host server_name
HostName server_name
User root
Port 22
IdentityFile ~/server_name.pem
Where:
- server_name is the name or the IP of the server.
- ~/server_name.pem is the path to the key to connect to the server.
Now that you know this you won’t have anymore to search for your login when you have to connect to a server by SSH.
I hope you enjoyed this tutorial and it will be useful for you in the future.
Leave a Reply