That doesn’t mean, however, that the default SSH configuration is the best option for those who are a bit more concerned about the security of their systems. Out of the box, SSH works with traditional user and password logins. And even though those logins are far more secure than they were with telnet, you’re still typing and sending a password across the internet.  Should anyone intercept that password, they could access your machines (so long as they also knew your username).  There’s a much better way. Said way is SSH Key Authentication. With Key Authentication, you bypass the username and password authentication, and replace it with a key pair. Why is this important? The primary reason this adds extra security is that the only way to access those servers (when they are configured properly for SSH key authentication) is by having the matching key pair. Also: How to make SSH even easier to use with config files Here’s how it works: Once configured properly, the only way you’ll be allowed remote access to the server is if you have the matching private key. Without that key, you cannot gain access. So long as you keep that private key private, all is well. But how do you pull this off? Let me show you.

Requirements

To set up SSH key authentication, you’ll need at least two Linux machines, one you log in to and one you log in from. I’ll demonstrate with Pop!_OS as my desktop and Ubuntu Server as my remote server. This should, however, work the same on nearly any Linux distribution. You’ll also need a user with sudo privileges. You’ll also want to make sure you have the same username on both local and remote machines. That’s it. Let’s make some SSH magic. Also: How to install Ubuntu server in less than 30 minutes

How to set up SSH key authentication in Linux for more secure logins

Also: Don’t use these passwords: These are the 10 logins most regularly found for sale online ssh-keygen You’ll first be asked where you want to save the key. I suggest saving it to the default location, so just hit Enter when prompted. You’ll then be asked to type and verify a password for the key pair. Make sure this password is strong and unique. Do not go with an empty password, as that isn’t secure.

How to configure the remote server for SSH key authentication

Now that you have your key copied, log into the remote machine. What we’re going to do now is configure the SSH server to only allow connections via SSH. One thing to keep in mind before you do this is once it’s configured, only those with SSH key authentication set up on the machine will be allowed access. Because of this, you’ll want to make sure you’ve copied SSH keys from all the desktop machines you’ll use to log into the remote server. ssh-copy-id SERVER Where SERVER is the IP address of the remote server. You’ll be prompted for the password for your user on the remote server. Once you’ve successfully authenticated, the public key will be copied and SSH key authentication is ready. When you attempt to log into the remote server, you will now be prompted for your SSH key password and not your user password. Also: How to manage SSH connections on MacOS with Termius With that out of the way, open the SSH daemon configuration file on the remote server with the command: In that file, look for the line: Change that line to: Save and close the file. Restart SSH with: Now, the only way you can successfully remote into that machine is by way of SSH key authentication. Any machine that doesn’t have a matching key pair will be denied access. Congratulations, you’ve just added another layer of security to your Linux servers.