title: How to use multiple ssh keys for multiple gitlab accounts with the same host
body: <p>I want to use 2 accounts in <a href="https://gitlab.com/" rel="noreferrer">Gitlab</a> website, every account with a different ssh key</p>
  
  <p>I generated the keys successfully and add them in <code>~/.ssh</code>  folder
  I created <code>~/.ssh/config</code> file and use one of them , it's works good
  I can also make swapping between the two keys by editing the <code>~/.ssh/config</code> file</p>
  
  <p><strong>The problem is :</strong> I want to use them in the same time , but all the  tutorials i found taking about different hosts :/ </p>
  
  <p>actually my two accounts are in the same host</p>
  
  <p>how can i edit the <code>~/.ssh/config</code> file to accept two accounts for the same host</p>
  
  <p><strong>Note:</strong>  I read <a href="https://stackoverflow.com/q/14888056/3185456">this question</a> but i can't get help from it</p>
  
  <p>My two accounts are <code>username1</code> and <code>username2</code>
  repo URL looks like : <a href="http://git@gitlab.com:username1/test-project.git" rel="noreferrer">git@gitlab.com:username1/test-project.git</a></p>
  
  <p>My current <code>~/.ssh/config</code> file:</p>
  
  <pre><code>Host gitlab.com-username1
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/id_rsa
  
  Host gitlab.com-username2
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/id_rsa_username2
  </code></pre>
  
  <p><strong>Update 1:</strong> </p>
  
  <p>1) When I use one key in the <code>~/.ssh/config</code> file , everything works perfect (but it's very boring to update it every time i want to change the user i use)</p>
  
  <p>2) When i use this lines
  <code>ssh -T git@gitlab.com-username1
  ssh -T git@gitlab.com-username2</code>
  its works good and return a welcoming message</p>
  
  <p>From 1) and 2) , i think the problem is definitely from the <code>~/.ssh/config</code> file , specifically in <code>Host</code> variable </p>
  
  <p><strong>Update 2: (the solving)</strong> 
  the solving was to edit the <code>.git/config</code> file from 
  <code>[remote "origin"]
    url = git@gitlab.com:username1/test-project.git</code> 
  to 
  <code>[remote "origin"]
    url = git@gitlab.com-username1:username1/test-project.git</code></p>
  
  <p>and do the same for the <code>username2</code></p>