-1

i want to use 2 diferent username on same server gitlab.com this is my actual config file :

Host gitlab.com
    HostName gitlab.com
    User username1
    IdentityFile ~/.ssh/id_rsa.username1
    IdentitiesOnly yes


Host gitlab.com
    HostName gitlab.com
    User username2
    IdentityFile ~/.ssh/id_rsa.username2
    IdentitiesOnly yes

if i push code in first account, working if i try to push code in second account not working (because use key of first account) working only for first position account on config file.

how i can use both account without this problems ?

  • Possible duplicate of [Multiple github accounts on the same computer?](https://stackoverflow.com/questions/3860112/multiple-github-accounts-on-the-same-computer) – phd Jul 19 '18 at 13:59
  • https://stackoverflow.com/questions/2419566/best-way-to-use-multiple-ssh-private-keys-on-one-client – phd Jul 19 '18 at 13:59

1 Answers1

1

You have to change the Host to make it uique:

Host username1.gitlab.com
    HostName gitlab.com
    User username1
    IdentityFile ~/.ssh/id_rsa.username1
    IdentitiesOnly yes


Host username2.gitlab.com
    HostName gitlab.com
    User username2
    IdentityFile ~/.ssh/id_rsa.username2
    IdentitiesOnly yes

then change the host names in your local git repository:

user1/project>git remote -v 
origin git@gitlab.com/... (fetch)
origin git@gitlab.com/... (push)

user1/project>git remote remove origin
user1/project>git remote add origin git@username1.gitlab.com/...

Of cause a project alias instead of the user name will do too...

Timothy Truckle
  • 15,071
  • 2
  • 27
  • 51
  • how i can do this with ssh link ? git@gitlab.com:usename/video-app.git because in this way not working git@username.gitlab.com:usename/video-app.git – Bello Daniel Jul 19 '18 at 09:56
  • 2
    @BelloDaniel what does "not working" mean? did you use the same `Host` in your `.ssh/config` and the repositoty URI (like `username**1**.gitlab.com`)? – Timothy Truckle Jul 19 '18 at 10:07