SSH keys are a means of identifying a trusted computer on a network without the use of passwords. They are much more secure than using passwords, as there’s no need to send a password over the network. This means interception is almost impossible and brute force attacks have lower chances of correctly identifying your credentials. By using an SSH agent along with an SSH key, you can connect to multiple servers without exposing your password to the world.
This article assumes that you have already downloaded some sort of SSH software. If you have not, there are several open source software programs that you may download to do this.
Generating an SSH Key
To begin with, you’ll need to generate a pair of SSH keys. One is your private key and the other is public. You give the public key to any servers to which you want to connect and keep the private one a secret from everyone you don’t want using your computer on the network.
Step One: Generate The Pair
To generate the pair, enter the command “ssh-keygen” on your workstation/server. This will bring up a prompt asking you where to save the file. You can select a specific path or use the default proposed by ssh-keygen (Ex:”~/.ssh/id_rsa.pub”). Then, it will ask for a passphrase. You are able to press enter for no passphrase. Having the passphrase is an extra level of protection, which is useful if someone else uses your computer and you don’t want them on your secure connection. If that’s the case, not having a passphrase is highly discouraged.
And now, you have your key pair. However, you’re not ready to login quite yet. First, you’ll need to complete the second step.
Step Two: Entering Your Public Key
In order to use your key pair, you have to accept the public key on the remote server after you generated it on your workstation/server. You will enter the command “ssh-copy-id firstname.lastname@example.org” on the local server that you just used to make the pair. This will create “~/.ssh/authorized_keys” on the remote server.
You now have your public key on the remote server, so you’re set to log in to the server at any time now.
Step Three: Log In
Now that you have the key pair generated and the public key entered into the remote server, you are able to login directly on the remote server. Simply enter the command “ssh email@example.com” . If you don’t have a passphrase, you’re logged in! If you do, then you must enter it once prompted after entering the command above.
Note: If you have a different SSH port, you must add the command “-p portnumber” to the ssh-copy-id command. For example, “ssh-copy-id -p 11221 firstname.lastname@example.org” is what you would enter if your port number was 11221.
SSH keys are, as you can see, very easy to generate and use. Enjoy your increased security. If this guide was helpful to you, kindly share it with others who may also be interested.