Git multiple account login problem parsing _linux shell

Source: Internet
Author: User
Tags ssh hosting using git git clone

Same server, same hosting platform, multiple account issues

1, add key

Let's take Oschina for example. In order to better illustrate the problem, we are in the Oschina platform with account 111 new project test111 and Account 222 new project test222, remember the project privatization oh, otherwise we have nothing to say.

Before we want to clone the project test111, we need to set the associated key in the following steps

Ssh-keygen-t rsa-c "111@163.com"//mailbox is the account number 111 corresponding mailbox

The whole process of return to the finished, operation up that is quite simple! But it's not over yet, maybe you noticed, in the process of carriage return, there is a word that prompts:

Your public key has been saved in/root/.ssh/id_rsa.pub.

Yes, we're going to open this file now.

Cat/root/.ssh/id_rsa.pub

Copy the contents of the file, and then open Http://git.oschina.net/keys this page, create a new key, paste the copied content in the good.

As a result, we associate the key on the server with the Oschina platform.

2. Clone Project

Then we clone the TEST111 project by using git clone command, remember that the address of clone is SSH instead of https oh, this time will prompt us to enter username and password, it is Oschina account and password respectively.

If your hand is based on HTTPS, you can reset the remote warehouse address by using the following command (no, you can skip this step)

Remove the previous remote warehouse address
git Remote remove Origin
//Add to the address SSH, non-HTTPS git remote
add Origin git@git.oschina.net: Wwolf/test111.git

3, multiple account compatibility issues

Here, for the TEST111 project pull push operation is basically no problem. If the user 222 want to face the project test222 on this server management, we directly execute git clone git@git.oschina.net:222/test222.git after the error, the prompt is as follows:

Access denied.
Fatal:could not read from remote repository.
Please make sure your have the correct access rights and the repository
exists.

Why, then? The first and most important question must be the key problem! Because we have not previously layer on this server add key to user 222 Oschina account! Then we will follow step 1 again on the server for user 222 add a key bar, but note that our key to save the file to rename, otherwise you can create a user 111 key coverage!

Ssh-keygen-t rsa-c "Account 222 of the mailbox @qq.com"
//Next will be prompted we want to keep the key in which file, re-enter the filename can
enter file in which to save the key (/R OOT/.SSH/ID_RSA):/root/.ssh/id_rsa_2
//Then return to return to enter and return to the finished, important words three times!

Then we login to account 222 Oschina account add key

But the problem arises, this time we re clone test222 still prompts us not to have permission, how to return a matter??? The central theme of this article has been exposed! A pile of nonsense, start to say the key--------------------------

In fact, this time we clone test222 project, Git is to take the default Id_rsa.pub file inside the key to contrast, this must be a problem, because 222 account does not add this key! That means we're here if the clone test222 let git hold the key in the Id_rsa_2.pub file to verify that it is done? Yes, that's it! We look at the implementation steps:

First, we let git identify our new key

Ssh-agent Bash
ssh-add ~/.ssh/id_rsa_2

We then create a new or modified config file in the ~/.ssh/directory.

#Host is your remote warehouse address, note Oh, if some servers do IP port forwarding, here do not bring the slogan
Host git.oschina.net
#HostName is the address of the remote warehouse, the same if you do port forwarding should not be with the port number
HostName git.oschina.net
#Port port number, if there is a forwarding need to fill out the port number here, there is no need to fill
#Port 8800
#用户
User
Identify key file
identityfile ~/.ssh/id_rsa
#都指向同一个平台的话, the following host needs to do a processing, because we are using this key based on the host from top to bottom to find, Do not make changes will first find the first key, still ineffective, just change, other parameters do not do special processing
Host git222.oschina.net
HostName git.oschina.net
#Port 8800
User 222
identityfile ~/.ssh/id_rsa_2

As you can see, we have handled the 222 user's host, so we need to modify the 222 remote warehouse address.

Original Warehouse address
git@git.oschina.net:222/test222.git
//modified to
Git@git222.oschina.net:222/test222.git

Which means that at this point, user 222 only needs to execute commands

git clone git@git222.oschina.net:222/test222.git

You can do it! You can do it,!!!.

CD test222/
There's no problem finding git pull git push

Same server, different hosting platform, multiple account issues

The problem with these multiple platforms is basically simple, for example, we use the Gitlab platform 333 account of the project test333 to test, note Oh, we are registered a third account in the above two account on the basis of the test

git clone git@gitlab.com:333/test333.git
It is conceivable that the same is not right

Because not so many mailboxes, we registered Gitlab still use the user 222 of the mailbox, but this has no effect on our operation, nothing more than to create a id_rsa_3 file, in view of this, we directly copy id_rsa_2.pub inside the key to Gitlab platform.

Then add the Gitlab platform configuration within the ~/.ssh/config file

Host gitlab.com
HostName gitlab.com
#Port 8800 user
333
//Because Gitlab mailbox with the user 2,221, here with this key, if not consistent, You still need to generate a new key, which references the new key file
identityfile ~/.ssh/id_rsa_2

Ps:git Multiple account conflict resolution

Because of own two GitHub account number, recently in the push project, suddenly found always hint permission denied. Look at the original use of another GitHub account, not the current origin in the GitHub corresponding account. So I looked up a stackoverflow on the top of the solution side http://stackoverflow.com/questions/14689788/ Multiple-github-accounts-what-values-for-host-in-ssh-config.

Clear Git's global settings

git config--global user.name "your_name"
git config--global user.email "Your_email"

Then reset the Non-global user name and mailbox for each item:

git config user.name "your_name" 

SSH configuration

Under the ~/.ssh directory, use Ssh-keygen-c "Your_email"-t RSA to generate public and private keys, and when multiple github accounts are available, multiple RSA corporate keys can be generated. Then configure the ~/.ssh/config file (if not, recreate one):

#第一个github项目账号 
Host first_project 
HostName github.com 
User first_user 
identityfile ~/.ssh/id_rsa_ 
#第二个git项目账号 
Host second_project
HostName github.com 
User second_user 

To pull the replacement code from the project:

Git pull-A-master
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.