+2 votes
in General IT Tips by (71.8k points)
I want to generate an SSH key pair for Gitlab. What are the steps?

1 Answer

+1 vote
by (353k points)
selected by
Best answer

Follow these steps to generate your SSH key pair for Gitlab:

1. Go to your command line (terminal).

2. To generate a new ED25519 SSH key pair, type the following command:

ssh-keygen -t ed25519 -C "email@example.com"

Or, if you want to use RSA, type the following command:

ssh-keygen -o -t rsa -b 4096 -C "email@example.com"

The -C flag adds a comment in the key in case you have multiple of them and want to tell which is which. It is optional.

3. You will be prompted to input a file path to save your SSH key pair to. If you don’t already have an SSH key pair and aren’t generating a deploy key, use the suggested path by pressing Enter. Using the suggested path will normally allow your SSH client to automatically use the SSH key pair with no additional configuration.

4. Next, you will be prompted to input a password to secure your new SSH key pair. It’s a best practice to use a password, but it’s not required and you can skip creating it by pressing Enter twice.

If, in any case, you want to add or change the password of your SSH key pair, you can use the -p flag:

ssh-keygen -p -o -f <keyname>

5. Now you can add the newly created public key to your GitLab account. Copy the newly created public key from /home/username/.ssh/id_ed25519.pub or the file where you saved the key.

6. Go to your Gitlab account -> settings -> SSH keys (most probably URL should be https://gitlab.com/profile/keys ). In the textbox for key, paste the public key and press 'Add key' to add the public key to your Gitlab account.

Now you do not have to type password every time you try to access your Gitlab account from command line.

Source: https://docs.gitlab.com/ee/ssh/README.html#generating-a-new-ssh-key-pair