How to Add SSH key to GitLab [2 Steps]

In this article we are going to cover How to Create SSH Key in Git, How to Add SSH key to GitLab, Clone Gitlab Repo with SSH and Push Local code to GitLab repository.

What is SSH Key ?

SSH stands for Secure Shell. And it is authenticates to the GitLab server without using username and password each time. And before creating SSH Key you need to install Git on your machine.

Follow below link install git client on Windows or Linux OS

install Git client on as per your OS Environment

Step #1: Open the Git Bash and run the command to run generate SSH key in Git

ssh-keygen
How to Add SSH key to GitLab [2 Steps] 1

Step #2: Now go to GitLab.com and login to your GitLab account and click on profile, click on Edit Profile

Step #3: Now click on SSH Keys at left side of menu

How to Add SSH key to GitLab [2 Steps] 3

Step #4: Go to C:\ drive, click on .ssh folder and open the file with .pub extension and copy the SSH key

How to Add SSH key to GitLab [2 Steps] 4

Step #5:  Add SSH key to GitLab Profile

How to Add SSH key to GitLab [2 Steps] 5

Step #6: Now click on Add key button and add SSH key in GitLab

How to Add SSH key to GitLab [2 Steps] 6

Here you can see our SSH Key has been created successfully.

Step #7: How to Clone Gitlab Repo with SSH

Before Push code firstly you have to config the username and email as shown in below

git config --global user.name "devopshint"
git config --global user.email [email protected]
git config –list
How to Add SSH key to GitLab [2 Steps] 7

Open Git Bash and run the command git clone and your clone with SSH same as shown below

git clone [email protected]:devopshint/demo.git
How to Add SSH key to GitLab [2 Steps] 8

List the repo if it is cloned on your system

ls
How to Add SSH key to GitLab [2 Steps] 9

Step #8: Push Local code to GitLab Repo

Navigate to git repo

cd demo

Create one file or copy any file that repository folder for creating file run the command touch and filename

then run the command git add .

git add.

Run the command git commit –m “you can assign any commit here”.

 git commit –m “you can assign any commit here” 

Run the push command git push –u origin main(main is the branch name if your branch name is master then you have to run the command main)

Conclusion:

We have covered How to Create SSH Key in Git, How to Add SSH key to GitLab, Clone Gitlab Repo with SSH and Push Local code to GitLab repository

Related Articles:

Reference:

GitLab Official Page

Shweta Mamidwar

I am Shweta Mamidwar working as a Intern in Product Company. Likes to share knowledge.

2 thoughts on “How to Add SSH key to GitLab [2 Steps]”

Leave a Comment

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

Share via
Copy link
Powered by Social Snap