Git GitLab Add SSH
Copy the SSH Public Key
In the previous chapter, we created an SSH key pair.
Now we will use the clip <
command to copy the public key to our clipboard:
Example
clip < /Users/user/.ssh/id_rsa.pub
Go to GitLab, navigate to the lower left corner, click your profile, and select: Edit profile:
Then select "SSH keys". Select a title, and paste the public SSH key into the "Key" field, and click "Add Key":
You will be prompted to supply your SSH passphrase.
You will see your new SSH key added:
Test SSH Connection to GitLab
Now we can test our connection via SSH to GitLab:
Example
ssh -T git@gitlab.com
The authenticity of host 'gitlab.com (172.65.251.78)' can't be established.
ECDSA key fingerprint is SHA256:*******************************************.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitlab.com,172.65.251.78' (ECDSA) to the list of known hosts.
Enter passphrase for key '/Users/user/.ssh/id_rsa':
Welcome to GitLab, @w3schools-test!
If the last line contains your username on GitLab, you are successfully authenticated!
Add New GitLab SSH Remote
Now we can add a new remote via SSH to our Git.
First, get the SSH address from our repository on GitLab:
Then use that address to add a new origin:
Example
git remote add ssh-origin git@gitlab.com:w3schools-test/hello-world.git
Note: You can change a remote origin from HTTPS to SSH with the command: git remote set-url remote-name git@gitlab.com:username/repository.git
Example
git remote set-url origin git@gitlab.com:w3schools-test/hello-world.git