Github.com provides the Git version library hosting service, which provides MB free space for open-source projects: laugh:. If you need to expand the space or access a private Git library, Github also provides a paid service. Github.com provides the Git version library hosting service, which provides 300 MB free space for open-source projects: laugh:. If you need to expand the space or access a private Git library, Github also provides a paid service. The official version library address on Github is http://github.com/ossxp-com. But at the same time, I still have some personal data, non-company code for collaborative development, to put it on Github, So I registered a space: http://github.com/jiangxin. The problem occurs:
- Github uses the public key for authentication. Two different Github accounts need to be configured with different SSH public keys. The public key cannot be the same.
- For different Github accounts, one is configured as the rsa public key and the other is the dsa Public Key. However, during authentication, the first public key is used to determine the user identity.
What should I do ?... The new project cannot be pushed to the new github account. The new account jiangxin on Github is used to create a new empty version library freemind-mmx. In the local freemind-mmx project, configure github as a new source. The PUSH fails:
$ git remote add github git@github.com:jiangxin/freemind-mmx.git$ git push github debianERROR: Permission to jiangxin/freemind-mmx denied to ossxp-com.fatal: The remote end hung up unexpectedly
As shown above, authentication fails because the first public key used for authentication when connecting to the jiangxin/freemind-mmx.git repository on github is the public key of ossxp-com. The key to accessing multiple Github accounts in Linux at the same time is how to select different public keys for authentication. That is:
- Multiple public keys coexist under one Linux Account;
- Public Key selection issues when connecting to different servers;
In ~ /. Create multiple public keys in the ssh directory
The default value is ~ /. Ssh has some ssh public keys:
$ ls ~/.ssh/authorized_keys id_dsa id_dsa.pub id_rsa id_rsa.pub known_hosts
Id_dsa and id_dsa.pub are private keys and public keys in DSA format, and id_rsa and id_rsa.pub are public keys in RSA format (the public keys used for ossxp-com account authentication on github)
Create a directory ~ /. Ssh/github1, used to save the public key/private key pair of the ossxp-com account on github
$ mkdir ~/.ssh/github1$ cp ~/.ssh/id_rsa* ~/.ssh/github1/
Create a directory ~ /. Ssh/github2, used to save the public/private key pair of the jiangxin account on github
$ mkdir ~/.ssh/github2$ ssh-keygen -t rsa -f ~/.ssh/github2/id_rsaGenerating public/private rsa key pair.Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /home/jiangxin/.ssh/github2/id_rsa.Your public key has been saved in /home/jiangxin/.ssh/github2/id_rsa.pub.The key fingerprint is:0d:38:95:b2:d7:2b:1d:c8:cb:42:bc:94:bd:50:cb:f3 jiangxin@hpThe key's randomart image is:+--[ RSA 2048]----+| .. || .oo || .oO.+ || B.Ooo || o =S*.o || o = E || . . || || |+-----------------+
Use the IdentityFile command to set the priority of different public keys in ~ In the/. ssh/config file, you can use the IdentityFile command to set the file used for public key authentication. You can use multiple IdentityFile commands to try each public key in sequence. When you use an ossxp-com account to access github.com, modify ~ The/. ssh/config file is:
IdentityFile ~/.ssh/github1/id_rsaIdentityFile ~/.ssh/github2/id_rsaIdentityFile ~/.ssh/id_rsaIdentityFile ~/.ssh/id_dsa
When you use the jiangxin account to access github.com, modify ~ The/. ssh/config file is:
IdentityFile ~/.ssh/github2/id_rsaIdentityFile ~/.ssh/github1/id_rsaIdentityFile ~/.ssh/id_rsaIdentityFile ~/.ssh/id_dsa
That is, each time you connect to a different Github account, you can modify the authentication priority of different public keys. However, this method is not smart enough. I checked the MAN manual of ssh_config. Find the following method. Set the virtual domain name. You can use the Host command to set different Github authentication public keys. In the ssh configuration file, use the Host command to set independent settings for different hosts. With this configuration, You can automatically set the authentication Public Key for different accounts on Github, avoiding the trouble of manually modifying the IdentityFile command each time.
Configuration File ~ Example of setting/. ssh/config:
Host ossxp.github.com User git Hostname github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github1/id_rsaHost jx.github.com User git Hostname github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github2/id_rsa
For the original ossxp-com project, reset the remote URL:$
Git remote-vGithub git@github.com: ossxp-com/redmine-ossxp-hacks.git (fetch) github git@github.com: ossxp-com/redmine-ossxp-hacks.git (push) origin git@bj.ossxp.com: ossxp/redmine-0.8.x.git (fetch) origin git@bj.ossxp.com: ossxp/redmine-0.8.x.git (push) ossxp git@ossxp.com: ossxp/redmine-0.8.x.git (fetch) ossxp git@ossxp.com: ossxp/redmine-0.8.x.git (push) $
Git config remote. github. url ossxp.github.com: ossxp-com/redmine-ossxp-hacks.git$
Git remote-vGithub ossxp.github.com: ossxp-com/redmine-ossxp-hacks.git (fetch) github ossxp.github.com: ossxp-com/redmine-ossxp-hacks.git (push) origin git@bj.ossxp.com: ossxp/redmine-0.8.x.git (fetch) origin git@bj.ossxp.com: ossxp/redmine-0.8.x.git (push) ossxp git@ossxp.com: ossxp/redmine-0.8.x.git (fetch) ossxp git@ossxp.com: ossxp/redmine-0.8.x.git (push)
Use a custom connection URL to submit a github project created using the jiangxin account:
$ git remote rm github$ git remote add github jx.github.com:jiangxin/freemind-mmx.git$ git push github masterCounting objects: 2761, done.Delta compression using up to 2 threads.Compressing objects: 100% (833/833), done.Writing objects: 100% (2761/2761), 31.61 MiB | 64 KiB/s, done.Total 2761 (delta 2076), reused 2378 (delta 1907)To git@github.com:jiangxin/freemind-mmx.git* [new branch] master -> master$ git push github debianCounting objects: 84, done.Delta compression using up to 2 threads.Compressing objects: 100% (77/77), done.Writing objects: 100% (82/82), 115.47 KiB, done.Total 82 (delta 25), reused 0 (delta 0)To git@github.com:jiangxin/freemind-mmx.git* [new branch] debian -> debian$ tg remote --populate githubtg: Remote github can now follow TopGit topic branches.tg: Populating local topic branches from remote 'github'...tg: The remote 'github' is now the default source of topic branches.$ tg -r github push --all......