top of page
christiandreschler9

Using SSH keys to communicate with Gitlab.



In the previous post (here) we created a SSH key pair.

Now we're gonna use the generated key pair to communicate with the Gitlab server.


Requirements:

You should already have created a key pair as mentioned (here)


Copying the key into the system clipboard


Follow the below steps:


  1. Open the ~/.ssh/id_ed25519.pub file with your favorite text editor (i.e. xed, gedit, etc...)


  2. Select with your mouse all the content of the file


  3. Right click, and select "copy".

    The content of the file is copied in to the system clipboard.


Adding your public key to the Gitlab server:


  1. Open your web browser and Sign in to Gitlab.com.


  2. On the left sidebar, select your avatar.


  3. Select Edit profile


  4. On the left sidebar, select SSH Keys.


  5. Select Add new key.


  6. In the Key box, paste the contents of your public key. If you manually copied the key, make sure you copy the entire key, which starts with ssh-rsa, ssh-dss, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521, ssh-ed25519, sk-ecdsa-sha2-nistp256@openssh.com, or sk-ssh-ed25519@openssh.com, and may end with a comment.


  7. In the Title box, type a description, like Work Laptop or Home Workstation.


  8. Optional. Select the Usage type of the key. It can be used either for Authentication or Signing or both. Authentication & Signing is the default value.


  9. Optional. Update Expiration date to modify the default expiration date.

    • Administrators can view expiration dates and use them for guidance when deleting keys.

    • GitLab checks all SSH keys at 01:00 AM UTC every day. It emails an expiration notice for all SSH keys that are scheduled to expire seven days from now.

    • GitLab checks all SSH keys at 02:00 AM UTC every day. It emails an expiration notice for all SSH keys that expire on the current date.


  10. Select Add key.


Communicate with the Gitlab server using the key pair

Now that your public key is uploaded to the Gitlab server, you can communicate with it by using ssh.


Use the standard git commands but instead of the http address of your repo use the following syntax:

git clone git@gitlab.com:YourGitUserName/YourRepositoryName

i.e. if your repository is called "mydotfiles" and if your gitlab username is johndoe type:

git clone git@gitlab.com:johndoe/mydotfiles

Notes:

  1. If you sign in to the server for the first time you're asked to confirm the IP for fingerprinting.

    Select Y (yes)


  2. If you need to pull, push, add, commit, or perform any other operation replace the above keyword with the required one.


  3. If you have set up a shell alias for git, you can use that alias instead of the command 'git'.



3 views0 comments

Recent Posts

See All

Comments


bottom of page