How to generate and use RSA SSH keys to communicate with GitLab

If you use Gitlab for your projects, you must have typed your username and password several times to perform a git operation. Typing username and password so many times is an annoying task. Using SSH keys to log in to Gitlab, one can save time spent on typing username and password.

In this post, I will show how to generate RSA SSH keys and add SSH keys to Gitlab.

Generate an SSH public and private key pair:

  • Run the following command on the terminal to generate 4096-bit RSA key pair.
ssh-keygen -t rsa -b 4096 -C ""
  • It will ask for the file name in which you want to save the key. Keep pressing Enter until it asks to enter a “passphrase.” You can enter a passphrase or press Enter to continue.
  • Public and private keys are generated. It will show you the filename in which public and private keys are saved.
  • Open the public key file and copy the whole key.

Add SSH public key to Gitlab:

  • Log in to your Gitlab account.
  • On the top-right corner, you will find a gear button for settings. Click on the button and select Preferences from the menu.
  • After clicking Preferences, you will see a menu bar on the left side of the page. In the menu bar, click on the link for SSH keys. It will open a page to add an RSA public key. The page will look like the following:
Add SSH public key to Gitlab:
  • Enter your public key in the text box and click the “Add key” button.

That’s it. Now you do not have to type a username and password to perform a git operation. Please let me know if you find any issues.

Similar Posts

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.