Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set ssh config for 2 different gitlab accounts?

I am setting up my ssh config for 2 different accounts in gitlab.

Host gitlab.com-roulette
    HostName gitlab.com
    User norayr.ghukasian
    IdentityFile /home/norayr_ghukasyan/.ssh/id_ed25519_roulette

Host gitlab.com-devlix
    HostName gitlab.com
    User norayr.ghukasyan
    IdentityFile /home/norayr_ghukasyan/.ssh/id_ed25519_devlix

I am getting a Permission denied error.
The strange thing for me is that the first one is working fine, therefore I think there is some tiny issue in my config that I am not aware of. I guess when the user or the server tries to connect, ssh automatically matches the first config with matched HostName.
How do I set up it properly to work for both of the accounts?

P.S. The Users are different – norayr.ghukasian and norayr.ghukasyan.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Following Use difference accounts on a single GitLab instance you would setup your configuration like so:

Host norayr.ghukasian.gitlab.com
  Hostname gitlab.com
  PreferredAuthentications publickey
  User git
  IdentityFile /home/norayr_ghukasyan/.ssh/id_ed25519_roulette

Host norayr.ghukasyan.gitlab.com
  Hostname gitlab.com
  PreferredAuthentications publickey
  User git
  IdentityFile /home/norayr_ghukasyan/.ssh/id_ed25519_devlix

Then to clone a repo as norayr.ghukasian user:

git clone git@norayr.ghukasian.gitlab.com:gitlab-org/gitlab.git

Using the username as the alias is not absolutely necessary. You can use a different alias if you wish and set it in the Host section of your ssh config.

Key takeaways:

  1. The only thing that you need to tell GitLab who you are is the IdentityFile.
  2. You can direct git/ssh to use a specific identity file by the alias you use for the host configured in the ssh config.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading