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:

  1. Open a terminal on Linux or macOS. Similarly, use command prompts on Windows.
  2. Generate a new ED25519 SSH key pair with command: ssh-keygen -t ed25519 -C "" or Generate RSA: ssh-keygen -t rsa -b 4096 -C ""
  3. Next, you can simply input a file path to save your SSH key pair or just press Enter
  4. 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:

  1. Get & Copy public SSH key to the clipboard by using following command:
    macOS command: pbcopy < ~/.ssh/
    Linux command: xclip -sel clip < ~/.ssh/
    Linux command: cat ~/.ssh/ | clip
  2. 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:
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.