2021年7月4日 星期日

[project, ssh] How do I add another ssh key to access the gitlab repository

How do I add another ssh key to access the GitLab repository

井民全, Jing, mqjing@gmail.com


You can use the ~/.ssh/config file to setup the key file (through identifyFile) for authorizing the host that you want to access. Here is the procedure.

Setup

Step 1: Select [Deploy key ] from gitlab

Step 2: Create key by using ssh-keygen with another key file name

Step 3 Setup the ssh config

File: ~/.ssh/config

Host           project1-host

HostName       192.168.1.2

IdentityFile   C:\Users\<user name>\.ssh\id_rsa

User           <user name>



Host           project2-host

HostName       192.168.1.2

IdentityFile   C:\Users\<user name>\.ssh\id_rsa_2

User           <user name>



Usage

# Use the first key for access project 1

## Replace 

git clone git@192.168.1.2:<user name>/xxx.git


## to this 

git clone git@project1-host:<user name>/xxx.git


# Use the second key for access project 2

## Replace 

git clone git@192.168.1.2:<user name>/xxx.git


## to this 

git clone git@project2-host:<user name>/xxx.git



References

  1. https://stackoverflow.com/questions/23537881/fingerprint-has-already-been-taken-gitlab

  2. Using the SSH Config File, https://linuxize.com/post/using-the-ssh-config-file/

  3. SSH config file for OpenSSH client, https://www.ssh.com/academy/ssh/config