Hi everyone, I started my DevOps journey a few weeks ago, and I have decided to share what I learn to document my progress and help the community. I also hope that this will make me understand new concepts better.
SSH, or Secure Shell, is a network protocol that enables users to securely connect to and control their remote servers. It also allows data encryption so that attackers would not have access to server passwords and user information.
SSH can be used to securely connect to your GitHub repositories so you don’t need to type your credentials in every time.
SSH can also be used to connect to another computer remotely. This is exactly what we are going to discuss in this article (P.S.: Your servers are practically just computers that exist elsewhere).
SSH can be set up to make logging into servers from local machines (i.e. your laptop) a much easier process.
The first step to doing this is editing the SSH config files. I’ll use vim in this tutorial, but you’re free to use nano or any text editor you’re comfortable with.
So, to begin, open the SSH config file by typing the following command into the terminal:
We will then proceed to enter the following lines into the file:
Host * IgnoreUnknown UseKeychain UseKeychain yes Host loginServer HostName <your_server_ip_address> User <your_preferred_user> IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes
Be sure to replace
<your_preferred_user> with your actual server IP address and user name. If this is your first time dealing with SSH, your only user is likely to be
To explain some of the lines above,
UseKeychain is useful if you are using macOS, to secure and save passwords for any host we login to over ssh.
However, it will throw an error if you are on the Windows or Ubuntu operating systems.
This can be fixed using the
IgnoreUnknown option to ignore
UseKeychain on Windows and Ubuntu. This won’t have any effect on macOS.
You can also simply remove
IgnoreUnknown option if you’re running macOS.
loginServer as a variable name of the server we’re trying to set up. You may name this anything of your choosing.
HostName is the server IP address as explained previously.
User is the server username.
IdentityFile is the local machine's private key. This file is created when you generate an SSH key for the first time.
IdentitiesOnly is set to yes to make sure that we login with the private key.
After all of this, we can save the file, exit the vim, and simply login to the server with the following command:
(P.S. If you’re like me and forget how to exit vim, I got your back. First press ESC to exit editing mode and then enter Shift + Z, twice.)
If you’re feeling adventurous, you can check out other options that can be added to your config file with:
And that’s it. This is all you need to do in order to SSH into your remote servers easily.
If you found this article helpful, please leave a heart or a comment. If you have any questions, please let me know in the comment section.
Also, don’t forget to follow me for more articles. Thank you.