How to Generate SSH key in GitLab?

I am a software developer.
What is Git?
Git is a distributed version control system, which can help you to work locally on your computer, then share or “push” your changes to a server (Nothing but our GitLab).
Now What is SSH key?
It is basically a protocol to build secure communication with Git. While choosing SSH keys to authenticate to the GitLab remote server, you don’t have to use your username and password always.
Types of SSH keys
There are 4 types of supported SSH keys(but 2 are important).
1. ED25519
Ed25519 is intended to provide attack resistance comparable to quality 128-bit Symmetric ciphers. As security features, Ed25519 does not use branch operations and array indexing steps that depend on secret data, so as to defeat many side channel attacks.
2. RSA
Today, the RSA is the most widely used public-key algorithm for SSH key. But compared to Ed25519, it's slower and even considered not safe if it's generated with the key smaller than 2048-bit length. The Ed25519 public-key is compact. It only contains 68 characters, compared to RSA 3072 that has 544 characters.
3. DSA
4. ECDSA
Steps to follow in SSH key-pair generation
- Open a terminal.
- Type ssh-keygen -t followed by the key type a. Also you can add an optional comment which is included in the .pub file(public key) that’s created.
for ED25519:
ssh-keygen -t ed25519 -C "<comment>"
For RSA:
ssh-keygen -t rsa -b 2048 -C "<comment>"
3.
You will get output like this:
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
4. Press enter to choose the default directory to save your private and public ed25519/rsa keys. (unless you don't want it to save in any specific directory. In that case provide the path.)
5.
Specify a passphrase(it is basically same as password) if you want otherwise just press enter for setting by default empty passphrase. Enter same passphrase or press Enter if you are choosing default passphrase.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Configure SSH to point to a different directory
If you did not save your SSH key pair in the default directory, configure your SSH client to point to the directory where the private key is stored.
- Open the terminal and run this command:
eval $(ssh-agent -s)
ssh-add <directory to private SSH key>
- Save these settings in the ~/.ssh/config file.
# GitLab.com
Host gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_com_rsa
# Private GitLab instance
Host gitlab.company.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/example_com_rsa
Public SSH keys must be unique to GitLab because they bind to your account. Your SSH key is the only identifier you have when you push code with SSH. It must uniquely map to a single user.
Add an SSH key to your GitLab account
You will get 2 keys(public and private) save in your directory. Copy public key and paste it in your Gitlab account and keep the private key secure.
- Go to profile -> user settings -> SSH key
and paste your copied public key in the space given. Then scroll down you will see add key button click on that.

Troubleshooting SSH connections:
When you run git clone(by ssh keys), you may be asked for a password, like git@gitlab.example.com's password:. This indicates that something is wrong with your SSH setup.
Ensure that you generated your SSH key pair correctly and added the public SSH key to your GitLab profile.
Try to manually register your private SSH key by using ssh-agent.
Try to debug the connection by running ssh -Tv git@example.com. Replace example.com with your GitLab URL.
