gitlab ssh key code example
Example 1: git clone ssh key
ssh-agent bash -c 'ssh-add /somewhere/yourkey; git clone [email protected]:user/project.git'
Example 2: 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 3: generate an ssh key pair for gitlab
ssh-keygen -t ed25519 -C "<comment>"
Example 4: ssh key for github
SSH stands for Secure Shell.
When working with a GitHub repository,
you'll often need to introduce yourself to
GitHub using your username and password.
SSH key is an alternate way to identify yourself
that doesn't require you to enter you username and password every time.
SSH keys come in pairs, a public key that
gets shared with services like GitHub,
and a private key that is stored only on
your computer. If the keys match, you're granted access.
Example 5: add ssh key to gitlab