How to Setup SSH Key in GitLab [2 Steps]

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

What is SSH keys ?

SSH stands for secure shell or secure socket shell. It is used for managing the networks, operating systems and configurations and also authenticates to the GitLab server without using username and password each time. You can set the SSH keys to provide a reliable connection between the computer and GitLab.

Step #1:How to Create SSh key

To create ssh key/generate ssh key, Firstly open command prompt or Git Bash and run below command

ssh-keygen

After that you will get message about the file location in which file you have to save key. By default your user folder in that another folder called .ssh . Keep as it and press enter. Then directory created in default folder.

Now you will be ask to set a password. Or you will keep as it and enter.

ssh keygen

Now your public and private ssh key has been generated in your default folder.

folder

Step #2:Login your GitLab account

Login GitLab account and go to profile icon –> edit –> SSH keys.

click on ssh key

Step #3:How to Setup SSH Key in GitLab

Go to directory where key is saved and open the Microsoft publisher document in notepad after that copy the id_rsa.pub key.

copy ssh key

And paste in key field after that enter the title, select usage type, expiration date and click on add key.

ssh key paste

SSH key created successfully.

ssh key created

How to clone project from GitLab ?

If you have Clone project from GitLab/clone with ssh gitlab simply you will copy the link of project means its clone with HTTPS link.

copy ssh link

Go to folder where you have clone project and open Git Bash after that using below command you clone the project.

git clone [email protected]:devops2421227/devopshint.git
git clone

Output:

clone 2

How to Push file/code to GitLab using ssh key?

Go to file/code which is you have to push on GitLab and right click on this page open git bash.

Add the files to Git index

git add .

Commit Added Files

git commit -m "another new file added"

To check the git branch

git branch

Push to GitLab

git push origin master
push1

After that you have refresh the GitLab page and you will get file which is git push.

push 21

Conclusion:

We have covered How to Create SSH Key in GitLab, How to Add SSH key to GitLab | How to Setup SSH Key in GitLab, Clone Gitlab Repo using SSH key and Push Local code to GitLab repository.

Related Articles:

How to Create a New Project in GitLab [2 Steps]

Reference:

Use SSH keys to communicate with GitLab

About Priti Adkine

I am Priti Adkine working as Software Engineer and having 1+ years of Experience. Likes to share knowledge.

Leave a Comment

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

Share via
Copy link