There is a common case that multiple users use the same Linux server account, but they have different github account and their own repo. How to get a solution for this problem?
Given you have already configured an active github account (Alice) on the server with all global git and ssh settings done. We treat Alice as the main account.
Now configuring the ssh settings. We generate one more RSA key pairs.
ssh-keygen -t rsa -C "hello world"
When choosing the save path, be sure save the file to a new name, e.g.
Then we add the private key to ssh settings.
ssh-agent bash ssh-add id_rsa_bob
$ssh-add -l will show the accepted private keys list.
id_rsa_bob.pub to your github ssh key list.
Next, we write the
# email@example.com:Alice Host github-alice User Alice HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa # firstname.lastname@example.org:bob Host github-bob User bob HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_bob
Make sure to give the file a proper authority:
chmod 600 ~/.ssh/config
Alice, as the main user, do not need to change anything. Bob, however, consider he clone a repo
gene-player from his github. Now he need to set the repo’s config file.
git config user.name "bob" git config user.email email "email@example.com" git config remote.origin.url "git@github-bob:bob/gene-player.git"
Note that we need to modify the remote.origin.url, replacing the original domain name “github.com” to “github-bob” as what we set the
Host variable in
Now Bob can play with the repo.