How to create SSH key and use for GitLab?
SSH is a preferred way to use Git as compared to HTTP.
SSH key is generated as pair. A public key that is stored on your machine and a private key that is saved in git-based servers such as GitLab or GitHub.
Steps to create & use SSH Key for GitLab:
- Open a terminal on Linux or macOS. Similarly, use command prompts on Windows.
- Generate a new ED25519 SSH key pair with command:
ssh-keygen -t ed25519 -C "username@mail.com"
or Generate RSA:ssh-keygen -t rsa -b 4096 -C "username@mail.com"
- Next, you can simply input a file path to save your SSH key pair or just press
Enter
- Then, you will be asked to set a “passphrase”. This will be used once you use git commands first time after SSH setup.
How to add an SSH key (that generated above) to your GitLab account:
- Get & Copy public SSH key to the clipboard by using following command:
macOS command:pbcopy < ~/.ssh/id_ed25519.pub
Linux command:xclip -sel clip < ~/.ssh/id_ed25519.pub
Linux command:cat ~/.ssh/id_ed25519.pub | clip
- Add your public SSH key to your GitLab account by:
Go to Settings > SSH Key > and press Add key
Now, you should be able to interact (clone, pull, push, etc) with git from the local machine without username and password.
Learn more about the similar topics:
Tutorials |
---|
No Content Found. |
Exercises & Assignments |
---|
No Content Found. |
Interview Questions & Answers |
---|
No Content Found. |