On Git, when users deal with larger projects, they often work on their local machine and then push it to the centralized server, such as GitLab and many more. While doing so, they get irritated each time when they need to type the username name, and password. To overcome these issues, they are required to create their public and private key pair which is known as SSH key. Then, they are required to configure them by adding them to GitLab.
This post will illustrate the procedure of generating an SSH key for GitLab.
How to Generate SSH Key for GitLab?
To make an ssh key for GitLab, check the “ssh-keygen -t <ssh-key-type> -C <“commit”>” command can be used. It will create the private and public key pair.
Let’s check out the provided instructions for a better understanding!
Step 1: Move Toward Git Root Directory
First of all, move toward the Git root directory by running the “cd” command:
Step 2: Generate SSH Key
Then, execute the provided command to make a new SSH key:
Here:
- “ssh-keygen -t” is a command that is used for generating SSH key pairs(public and private).
- “ed25519” is the SSH key type.
- “-C” flag is optional, however, it is recommended to make the user key more identifiable along with the commit message if they already have the generated key.
When the above command is executed:
- The next prompt will ask you where to save the generated key, press the “Enter” key to accept the default filename.
- Then, again press the “Enter” key twice for leaving the passphrase empty and making without a password SSH key pair.
- As a result, the private key and public key will be generated, and their store location will be displayed:
Step 3: View Public Key
After doing so, execute the “cat” command along with the file where the public key has been saved:
As you can see, the generated public key has been shown in the terminal:
That’s it! We have described the easiest method to generate an SSH key for GitLab.
Conclusion
The SSH key is a combination of public and private key pair. It is used for authentication against GitLab servers. To generate this key pair, first, launch the Git utility and navigate to the Git root directory. Then, run the “ssh-keygen -t <ssh-key-type> -C <“commit”>” command. After that, display the generated public key by using the “cat” command along with the file where the key is saved. This blog illustrated the generating SSH key for GitLab.