Enhancing Security: A Guide To Add SSH Keys to GitHub/GitLab

Want to add SSH Keys To Github/Gitlab? Follow this guide;

In the digital realm, security is crucial. That’s why most websites and web services use HTTPS for data encryption. 

Similarly, many users prefer HTTPS when connecting to GitLab due to its username and password authentication familiarity.

Using SSH keys provides an added layer of security. Enhance the security of your accounts and streamline the authentication process.

What are these keys?

SSH keys are a way to authenticate to a server securely. They use a pair of keys, a public key and a private key. 

The public key is made available to the server, and the private key is kept secret. When you connect to the server, the server will use your public key to encrypt a challenge. 

You then use your private key to decrypt the challenge, and the server will verify that the decryption was successful.

In GitLab, SSH keys are used to authenticate to the GitLab server. It allows you to clone repositories, push changes, and more.

You don’t need to enter your username and password each time. Generate a new SSH key pair on your computer to add an SSH key to GitLab. 

Use the ssh-keygen command. Once you have generated the key pair, you must copy and add the public key to your GitLab account.

Let’s add SSH Keys To Github/Gitlab

Generate a new key if you lack one. Do this by opening your terminal and pasting this code:

ssh-keygen -t ed25519 -C “<comment>”

 In this, we have specified the type of key to generate. The comment is optional; once you click enter, it’s generated.

Get such feedback:

Generating public/private ed25519 key pair.

Enter the file to save the key (/home/user/.ssh/id_ed25519):  Accept the option given or change the directory if you need to.

Now let’s proceed to configure the SSH

To proceed, you will require the text format of your public ED25519 SSH key. You can obtain this by executing the following command in Git Bash:

cat ~/.ssh/id_ed25519.pub | clip

It copies the SSH key in text form to your clipboard. Now let’s proceed to your account:

  • Select your avatar and click on settings
  • Click SSH Keys
  • Paste the SSH key into the Key field
  • Add descriptive text in the title, something that will define you as a user or the computer it is used from
  • Click Add Key

And now you’ve added SSH to Gitlab for more security.

Tips on keeping your GitLab SSH keys safe:

  1. Generate a strong passphrase. The passphrase encrypts your private key, so it is vital to make it strong. A good passphrase should be at least 12 characters long and contain a mix of upper and lowercase letters, numbers, and symbols.
  2. Do not share your private key. Your private key is the most crucial part of your SSH key pair, so it is crucial to keep it safe. Do not share your private key with anyone, not even your friends or colleagues.
  3. Store your private key in a secure location. The best place to store your private key is on a USB drive or in a password manager. Do not store your private key on your computer, which could make it vulnerable to attack.
  4. Keep your SSH key pair up to date. If you lose your private key, you must generate a new one. Regularly update your SSH key pair to keep your account secure.
  5. Use two-factor authentication (2FA). 2FA adds an extra layer of security to your account by requiring you to enter a code from your phone in addition to your password.
  6. Be careful about what websites you visit. Some websites may try to steal your SSH keys, so be careful about what websites you visit and what information you enter.
  7. Keep your software up to date. Software updates often include security patches, so keeping your software up to date is essential.

A final thought: add SSH Keys To Github/Gitlab;

Use the outlined instructions to generate and add SSH keys to your accounts. Ensure secure authentication and streamlined access to these platforms. 

Remember, prioritizing security is essential, and SSH keys are crucial in safeguarding your accounts. 

Take the necessary steps to enhance your authentication process and enjoy the benefits of secure collaboration and version control.

Was this article helpful?

Related Articles

Leave A Comment?