Home > database >  How to set ssh config for 2 different gitlab accounts?
How to set ssh config for 2 different gitlab accounts?

Time:11-10

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.

CodePudding user response:

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 [email protected]: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.
  • Related