Create an SSH Key for Git

SSH keys are not just for Git but if you want to use SSH cloming for git, yeah you need em.

To create a new SSH key pair do the following:

1.) Open a terminal on Linux or macOS, or Git Bash / WSL on Windows.

2.) Generate a new ED25519 SSH key pair:

ssh-keygen -t rsa -b 2048 -C "" 
or ssh-keygen -t ed25519 -C ""

3.)  Use the defaults for all options if you like. Doesn’t matter.

Copying SSH Key to Gitlab

Go into the  ~/.ssh folder. On Mac you may need to do the following to see the .ssh folder:

# open the finder dialog
# enter ~/.ssh

# view hidden files

On Linux:

cd ~/.ssh

# on your keyboard hit Ctrl +h

Once you can see the hidden files you should see a file named or something like that. It ends with .pub. Open that file with a text editor and you will see the SSH key you need to copy to your own gitlab account.

Using a Access Token (works too but yuk!)

If you are not using an SSH connection you may need to create a personal access token (image below). Make sure you save the token on your local machine as you will not be able to retreive it once you close the page where you created it on Gitlab.

To clone a repo using an access token, it is similar to cloning with https but the url is slightly different. If your token is for example xSx81KqnADs-mZ4JviHa, the cloning command will be 

git clone

If you were previously using https with a username and password, you will need to update the remote url on your local machine. Once you have created the access token you will need to change the remote origin of your local repo to add the access token.  Here is an example of the old remote url and a new one

# old url

# new url with access token

To set the remote url use the following command as an example:

git remote set-url origin

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *