
Generating your SSH key on Unix-like systems
Generating an SSH key on Linux and OS X is easy; they come with a built-in tool to do this, called ssh-keygen
.
How to do it…
In the following steps, we will create an SSH key for your Unix system:
- First, we are going to check whether you have any SSH keys present. Open your terminal and enter the following command:
$ ls ~/.ssh
- If you have a file named
id_rsa.pub
orid_dsa.pub
, you can skip this recipe. - To generate a new SSH key, you need to open your terminal and enter the following command:
$ ssh-keygen -t rsa -C "Comment for key"
The comment can be anything you want; it makes it easier for you to see which key it is when you open the key file.
- Now, we get to the question of what you want to name your key. Just press Enter.
- You will be asked to enter a passphrase. Enter it, and be sure to choose a strong password.
You should see the following screenshot:
Your SSH key is now generated.
How it works…
We just created our personal SSH key: one key is the id_rsa
file and one is the id_rsa.pub
file. Whenever you need to provide your public SSH key, make sure that you use the id_rsa.pub
file. The other file should remain safely on your machine, as this is the private key. If you feel this key has been compromised, you should create a new SSH key and revoke the SSH key on all the systems you used it for.
The SSH key helps you to authorize yourself in your GitLab instance without having to use a username and password.
One thing that is important while creating your SSH key is to remember to enter a passphrase. We use an SSH key because we believe that passwords are less secure, so you might think that if you're using an SSH key, you will be safe. This is not entirely true. When a person takes control over your private key, they have access to every system you have put your public key in. However, when you use a passphrase for your SSH key, not only do they have to steal your private key, but they also know the password that goes with it.