connect to gitlab with ssh code example
Example 1: ssh gitlab
1) Open Git Bash (Download and Install Git Bash; You can use any *nix based command prompt).
2) Type
cd ~/.ssh
This will take you to the root directory for Git (Likely C:\Users[YOUR-USER-NAME].ssh\ on Windows).
3) In the .ssh folder you should find these two files: id_rsa and id_rsa.pub. These files tell the computer how to communicate with GitHub, BitBucket, or any other Git based service.
Those files were obviously missing from my computer so I had to create them.
ssh-keygen -t rsa -C "[email protected]"
Type this to create those two files
Once you entered that command, you will get a few more questions:
Enter file in which to save the key (/home/demo/.ssh/id_rsa):
You can press enter here, saving the file to the user home (in this case, my example user is called demo).
Then this will be shown:
Enter passphrase (empty for no passphrase):
The only downside, of course, to having a passphrase, is then having to type it in each time you use the key pair. I suggest you to use a passphrase though, due to security concerns.
In the end, the entire process looks like this:
Enter file in which to save the key (/home/demo/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/demo/.ssh/id_rsa.
Your public key has been saved in /home/demo/.ssh/id_rsa.pub.
The key fingerprint is:
4a:dd:0a:c6:35:4e:3f:ed:27:38:8c:74:44:4d:93:67 demo@a
The key's randomart image is:
+--[ RSA 2048]----+
| .oo. |
| . o.E |
| + . o |
| . = = . |
| = S = . |
| o + = + |
| . o + o . |
| . o |
| |
+-----------------+
The public key is now located in /home/demo/.ssh/id_rsa.pub. The private key (identification) is now located in /home/demo/.ssh/id_rsa.
4) Copying the public key to GitLab
Go and open the id_rsa.pub file (you can use any text editor you want).
Copy the entire content of that file and then open https://gitlab.com/profile/keys.
How GitLab SSH Keys page looks
Paste the content you copied from id_rsa.pub in the Key input (don't add extra spaces or characters).
Give your key a descriptive name and then Add the key.
5) Try to git clone or git push.
I really hope this will help someone because this article is what I needed last week when I couldn't put things together and all seemed to be way harder than it actually is.
Example 2: add ssh key to gitlab
#1- Open GitLab and go to your account settings
#2- Click on SSH.
#3- Click on Add SSH Key