Updated March 30, 2023
Definition of GitLab add SSH Key
Gitlab add SSH key is defined as a method to add SSH keys to the Gitlab server through which Gitlab communicates securely with Git. The distributed version amongst the Git and Gitlab is Git, where developers can work locally and post the developments done locally the changes can be “pushed” to the server, which in this case is the Gitlab. Through the usage of SSH keys to authenticate the remote server (Gitlab), one wouldn’t need the username and password every time to authenticate. In this article, we will look into the various aspects of the Gitlab and SSH keys through the various elements that constitute the integration.
What is GitLab add SSH key?
Now that we know the essential definition of how SSH and Gitlab are connected, it is now time to get a bit granular into the details of SSH in Gitlab. To start off, we need to understand the pre-requisites of using SSH in Gitlab. Below are the pointers that need to be kept in mind:
• One needs to have the OpenSSH client, and it usually comes pre-installed in the Windows, macOS, Linux version of operating systems.
• One needs to have an SSH version of 6.5 or higher. Any of the earlier versions of SSH contains MD5 signature that is not considered a secure one in today’s world. In order to know the ssh version in the system, one can execute the command ssh -V.
Once the pre-requisites are fulfilled, we need to also check if there is an existing SSH key pir present in the corresponding directory in the operating system. For this one can go to the .ssh/ directory and look for the corresponding SSH key. In case the sub-directory .ssh/ doesn’t exist either we are looking at the wrong home directory or we haven’t used ssh earlier. In the later case, we will follow the next steps mentioned in the upcoming paragraphs!
How to generate GitLab add SSH key?
Now, in this section, we will look at generating the SSH key pair for the 2 types of SSH keys we discussed above viz. ED25519 and RSA. For DSA and ECDSA, since both are either depreciated or no longer widely used we would skip them for the discipline reasons of the article.
- Step 1: The terminal in the operating system needs to be opened.
- Step 2: Here, we would need to type in the ssh-keygen -t command followed by the SSH key type and the comment that goes with the key file. Below we will demo the 2 SSH keys individually.
o For ED25519: ssh-keygen -t ed25519 -C “Comment Goes here”
o For RSA: ssh-keygen -t rsa -b 2048 -C “Comment Goes here”
- Step 3: After entering the above command we would need to press enter, post which a file name will be asked to be entered which will contain the key.
- Step 4: Post pressing enter after the next step, the user will be prompted to enter a paraphrase (twice).
- Step 5: After entering the passphrase and then re-entering, one would need to press enter, post which a confirmation will be displayed and will contain the information on where the files will be stored.
Adding your SSH key to GitLab
Now that we have understood how to create the SSH keys for Gitlab, we would need to copy the key into the Gitlab account. The steps are:
- Step 1: The content of the file needs to be copied from <filename>.pub file either by using the command line tool viz. cat (Windows), xclip (Linux), tr (macOS).
- Step 2: Now that the contents of the file are copied, we would now have to sign in to our Gitlab account.
- Step 3: The avatar on the top right corner needs to be selected and then click on Preferences.
- Step 4: The left sidebar contains the option SSH keys which need to be selected now.
- Step 5: Here, the contents of the file that was copied from the 1st step need to be pasted. The contents in the file start with ssh-<key type> and end with the comment we had passed while we were creating the SSH key.
- Step 6: In the title box, the description needs to be entered which will signify the type of machine uniquely and it will help in managing things later easily. Post that one can, optionally, enter the expiration date in the Expires at the box.
- Step 7: Finally one needs to click on the Add key to complete the procedure!
Supported SSH key types in Gitlab
There are a multitude of SSH keys that are present, but only a handful of them are recognized by Gitlab and they are:
1. ED25519 SSH Keys: This type of key was introduced in OpenSSH 6.5 as an elliptic curve signature scheme that enables better security than some of the other existing keys like ECDSA and DSA along with better performance. The USP of this SSH key is the speed and the non-stop runtime.
2. RSA SSH Keys: Lesser in terms of security than ED25519, but in lieu RSA provides the best compatibility of all algorithms. And hence, in order to perform the job, the key size is considerably larger to provide the security required.
3. DSA SSH Keys: Similar to the schema of RSA, uses a different algorithm than RSA. This type of key is depreciated in Gitlab 11.0.
4. ECDSA SSH Keys: Expanded as Elliptic Curve Digital Signature Algorithm, is one of the Legacy SSH keys that was introduced in OpenSSH 5.7 and it has a clear consensus that ED25519 is technically superior and hence must be preferred.
Generate an SSH key pair (screenshot)
Screenshot for ED25519:
Screenshot for RSA:
Conclusion
With this article, we have looked at the various aspects of adding SSH key in a Gitlab account along with going through the pre-requisites and the important to-do’s that needs to be followed before we generate or use any of the SSH keys in Gitlab!
Recommended Articles
This is a guide to GitLab add SSH Key. Here we discuss the definition, What is GitLab add SSH key, Supported SSH key types in GitLab for better understanding. You may also have a look at the following articles to learn more –