Add an SSH key to GitLab Account

SSH Keys



Before you can push(commit) or pull(update) source code in your GitLab project, you should add SSH Keys into you account first.
SSH keys allow you to establish a secure connection between your computer and GitLab.
Before you can add an SSH key you need to generate it.
Note: Here, I am using Window 10 Pro, and using Git Bash :
Locating an existing SSH key pair
Before generating a new SSH key pair check if your system already has one
at the default location by opening a shell, or Command Prompt on Windows,
and running the following command:


Using Git Bash on Windows
cat ~/.ssh/id_rsa.pub

If you see a string starting with ssh-rsa you already have an SSH key pair and you can skip the generate portion of the next section and skip to the copy to clipboard step. If you don't see the string or would like to generate a SSH key pair with a custom name continue onto the next step

Generating a new SSH key pair

1. To generate a new SSH key pair, use the following command:
    Git Bash on Windows / GNU/Linux / macOS:
ssh-keygen -t rsa -C "your.email@example.com" -b 4096

2. Next, you will be prompted to input a file path to save your SSH key pair to.

If you don't already have an SSH key pair use the suggested path by pressing
enter. Using the suggested path will normally allow your SSH client
to automatically use the SSH key pair with no additional configuration.

If you already have a SSH key pair with the suggested file path, you will need
to input a new file path and declare what host this SSH key pair will be used
for in your .ssh/config file, see Working with non-default SSH key pair paths
for more information.

3. Once you have input a file path you will be prompted to input a password to
secure your SSH key pair. It is a best practice to use a password for an SSH
key pair, but it is not required and you can skip creating a password by
pressing enter.

Note:

 If you want to change the password of your SSH key pair, you can use

ssh-keygen -p <keyname>
4. The next step is to copy the public SSH key as we will need it afterwards.

To copy your public SSH key to the clipboard, use the appropriate code below:

Git Bash on Windows / Windows PowerShell:
cat ~/.ssh/id_rsa.pub | clip

5. The final step is to add your public SSH key to GitLab.

Navigate to the 'SSH Keys' tab in your 'Profile Settings'.
Paste your key in the 'Key' section and give it a relevant 'Title'.
Use an identifiable title like 'Work Laptop - Windows 7' or
'Home MacBook Pro 15'.

If you manually copied your public SSH key make sure you copied the entire
key starting with ssh-rsa and ending with your email.

And now you are done, That's it!
Enjoy doing your project in GitLab as a group or whatever up to you...
Previous Post Next Post