How To Add An SSH Key In Your GitLab Profile
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed how to create an issue, labels, and milestones in GitLab project.
https://cloudaffaire.com/how-to-create-issue-label-milestone-in-gitlab-using-api/
In this blog post, we will discuss how to add an SSH key in your GitLab profile to enable the cloning of the GitLab project repository using SSH.
Git is a distributed version control system, which means you can work locally but you can also share or “push” your changes to other servers. Before you can push your changes to a GitLab server you need a secure communication channel for sharing information.
The SSH protocol provides this security and allows you to authenticate to the GitLab remote server without supplying your username or password each time. GitLab supports RSA, DSA, ECDSA, and ED25519 keys. Their difference lies on the signing algorithm, and some of them have advantages over the others.
How To Add An SSH Key In Your GitLab Profile:
Step 1: Create an ssh key in your local system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
###################################################### ## How To Clone GitLab Project Repository Using SSH ## ###################################################### ## Prerequisites: GitLab Access Token ## https://cloudaffaire.com/how-to-create-a-gitlab-project-using-api/ ## One CentOS system with internet access ## OpenSSH, git, curl and jq package installed ## ------------------------------------- ## Create a ssh key in your local system ## ------------------------------------- ## Hit enter three times to skip file name and paraphrase ssh-keygen -t ed25519 -C "cloudaffaire@gmail.com" ## Two keys, one public (id_ed25519.pub) and one private (id_ed25519) will be created ls -l .ssh ## Copy the content of your public key cat .ssh/id_ed25519.pub ## ssh-ed25519 AAAAC3NzaC1FHSRFR4sdg7kX543hsjj562FOMgsdcbb0d2xvBw63hbdgF3Ym2jpHLpse cloudaffaire@gmail.com |
Step 2: Log in to your GitLab account and navigate to ‘Settings’.
Step 3: Click on the ‘SSH Keys’ section in the left navigation pane. Provide the key value (copied in step 1) and click ‘Add key’.
Step 4: Test if your ssh key is working.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
## ------------- ## Test your ssh ## ------------- ## Create a project in GitLab ## GitLab Console => Projects => New Project => PROJECT_ID=$(curl --silent --header "PRIVATE-TOKEN: -XPOST "https://gitlab.com/api/v4/projects?name=cloudaffaire&visibility=private&initialize_with_readme=true" | jq '.id') ## Get the ssh clone url of your GitLab project repository ## GitLab Console => Projects => Your Projects => Clone => Clone with SSH SSH_CLONE_URL=$(curl --silent --header "PRIVATE-TOKEN: -XGET "https://gitlab.com/api/v4/projects/$PROJECT_ID" | jq -r '.ssh_url_to_repo') && echo $SSH_CLONE_URL ## Clone your GitLab repository using ssh key git clone $SSH_CLONE_URL |
Hope you enjoyed this article. In the next blog post, we will discuss Groups and Sub-Groups in GitLab.
To get more details on GitLab you can follow the below link.
https://docs.gitlab.com/ee/README.html
To Get more details on Git you can follow the below links.
https://cloudaffaire.com/category/devops/git/