Creating an SSH Key on macOS for Automatic Login to Linux

Lately I have been working a lot in a terminal, specifically with Linux VMs in my home lab environment. Logging into multiple VMs over and over again over SSH has become fairly repetitive, that is until I created myself an SSH key for automatic login to my VMs.

To make things easier in the future when it comes to logging in via Terminal, you can setup SSH keys, so you won’t need a password when you login.

In my lab I have been primarily working with “minimal” installations of CentOS 6 and CentOS 7. When you do a “minimal” install of CentOS, the installation doesn’t install services like rsync and scp by default.

To install rsync and scp run the following on your CentOS client:

While still connected to my CentOS client, I created a directory to store my RSA keys with the following command:

With the Terminal open on your macOS system, enter the following command to generate an RSA key for login:

Press enter three times to accept the default settings.

On my macOS client, I like to tighten up the file system permission via the following example:

To verify our permissions we can run:

On my macOS client, I see the following:

screen-shot-2016-09-09-at-11-31-06-am

Now that we have a key, the next thing to we need to do is copy the key to a directory on the server we intend to SSH to via Terminal. This will allow for password-less logins. With the IP or DNS name of the server we intend to connect to in mind, we can enter a command similar to the following to copy our key to the CentOS VM:

Like my macOS client where we created the RSA key, I will tighten up my CentOS VM SSH directories with the following commands from my macOS Terminal:

We should now be able to SSH from our macOS client to our CentOS VM without providing a password!