How to set up authentication for two separate GitHub accounts from same ssh client?

前端 未结 2 1472
伪装坚强ぢ
伪装坚强ぢ 2021-01-07 05:59

The short version:

Is there any way to set up automatic public-key-based ssh authentication from one Linux account to two different Github accounts?

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-07 06:21

    You need to create two sets of (public/private) keys, one for each account.

    You can reference them through an ssh config file, as detailed in "GitHub: Multiple account setup"/

    #Account one
    Host github.com
        HostName github.com
        PreferredAuthentications publickey
        IdentityFile /c/Users/yourname/.ssh/id_rsa
        User git
    
    #Account two
    Host ac2.github.com
        HostName github.com
        PreferredAuthentications publickey
        IdentityFile /c/Users/yourname/.ssh/id_rsa_ac2
        User git
    

提交回复
热议问题