In this article we will explain how to generate SSH keys on your computer. SSH keys are normally used to establish a secure communication between two hosts, that’s why they’re so important in our day-to-day work.
You can learn more about the SSH protocol here.
Let’s see how can we generate them!
Knowing how to generate SSH keys is quite important, as we will need to generate them every time we need to be able to connect securely to a remote server.
In this article we will show the simplest way to generate an SSH key in a secure manner.
1 – Generation
The first thing you will need is an SSH key that will be added to your corresponding Github account. We will use Github in this example, but the process will be very similar if you are using a different Git service.
We will be using ed25519 protocol to encrypt our key. To create a new SSH key on your computer, run the following command using your account’s email address:
ssh-keygen -t ed25519 -C "email@example.com"
This will prompt you for a location and filename where to store the new SSH key. If you don’t have an existing SSH key using the default name, just click ENTER. Otherwise, specify a filename for your key:
Generating public/private ed25519 key pair. Enter file in which to save the key (/Users/theboreddev/.ssh/id_ed25519):
In our case, we already have an SSH key with that name, we will provide a different name for it. For instance:
2 – Check keys
You can check that you’re new SSH has been created why listing the content in the
$ ls -larth ~/.ssh total 64 -rw------- 1 theboreddev staff 464B 18 Oct 17:07 id_ed25519 -rw-r--r-- 1 theboreddev staff 100B 18 Oct 17:07 id_ed25519.pub -rw------- 1 theboreddev staff 1.7K 25 Nov 15:27 known_hosts -rw------- 1 theboreddev staff 464B 28 Dec 23:13 id_boreddev -rw-r--r-- 1 theboreddev staff 105B 28 Dec 23:13 id_boreddev.pub -rw-r--r-- 1 theboreddev staff 385B 29 Dec 11:30 config drwx------ 10 theboreddev staff 320B 29 Dec 11:30 . drwxr-x---+ 78 theboreddev staff 2.4K 29 Dec 13:40 ..
The content should be something similar to what’s shown above. You should contain a file named
id_boreddev containing the private key and a file named
id_boreddev.pub containing the public key.
Make sure that only you can read or write the private key, this should be specified in the permissions in the left-hand side. It should look like this one:
-rw------- 1 theboreddev staff 464B 28 Dec 23:13 id_boreddev
3 – Add SSH Key to Agent
The final step we will need is to add our key to our SSH agent. We can achieve that by running the following:
This will allow us to be able to connect to the remote servers we are authorised to access without needing to introduce our username or password.
In this article we have learned how to generate an SSH key from our terminal to be able to connect to remote server in a secure manner.
That’s all from us today! We hope you’ve found this article useful!
Thanks for reading us!