How to add ssh key to github or gitlab ?

  1. Open a terminal on Linux or macOS, or Git Bash on Windows.
  2. if you have already created ssh key and want to use that, skip the 3,4 and 5 step.
  3. Generate a new ED25519 SSH key pair: ssh-keygen -t ed25519 -C "email@example.com" Or, if you want to use RSA: ssh-keygen -t rsa -b 4096 -C "any comment or email-id" if you dont want to add any comment you can remove -C flag and comment.
  4. It will ask for path to store the key, go with the default so that no extra configuration need to be done.
  5. Once path is set, it will ask for password for security of key-usage(Password is not mandatory you can skip by pressing twice enter key)
  6. Now the key is generated to specified location (C:\Users\username\.ssh). go to the folder there will be two key id_rsa and id_rsa.pub, open the rsa.pub and copy whole content(Do not modify anything by mistake).
  7. For gitlab : go to gitlab -> settings -> SSH key -> Paste the key in specified area

Give a title and add the key.

For github users: go to github settings https://github.com/settings/keys

Give a title and paste your ssh key and add SSH key.

Test the ssh : ssh -T git@gitlab.com for gitlab users and ssh -T git@github.com for github users.

Can we use same ssh key for gitlab and github or other vcs ?
yes we, for that we need to configure the ~/.ssh/config.
For gitlab users add copy and paste the below:

 gitlab.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfuCHKVTjquxvt6CM6tdG4SLp1Btn/nOeHHE5UOzRdf
gitlab.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsj2bNKTBSpIYDEGk9KxsGh3mySTRgMtXL583qmBpzeQ+jqCMRgBqB98u3z++J1sKlXHWfM9dyhSevkMwSbhoR8XIq/U0tCNyokEi/ueaBMCvbcTHhO7FcwzY92WK4Yt0aGROY5qX2UKSeOvuP4D6TPqKF1onrSzH9bx9XUf2lEdWT/ia1NEKjunUqu1xOB/StKDHMoX4/OKyIzuS0q/T1zOATthvasJFoPrAjkohTyaDUz2LN5JoH839hViyEG82yB+MjcFV5MU3N1l1QL3cVUCh93xSaua1N85qivl+siMkPGbO5xR/En4iEY6K2XPASUEMaieWVNTRCtJ4S8H+9
gitlab.com ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBFSMqzJeV9rUzU4kWitGjeR4PWSa29SPqJ1fVkhtj3Hw9xjLVXVYrU9QlYWrOLXBpQ6KWjbjTDTdDkoohFzgbEY=
 

Hope this may help someone.

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *