In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is to share with you the content of an example analysis of the git multi-account login problem. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Same server, same hosting platform, multiple account problems
1. Add key
Let's take oschina as an example for a while. In order to better illustrate the problem, we use the account 111new project test111 and the account 222new project test222 on the oschina platform respectively. Remember that the project is privatized, otherwise we have nothing to say.
Before we want to bring down the project test111 clone, we need to follow these steps to set up the associated key
Ssh-keygen-t rsa-C "111@163.com" / / mailbox is the mailbox corresponding to account number 111,
The whole process is finished by going back to the car, and it is quite easy to operate! But it's not over. You may have noticed that in the process of entering the car, there is a hint like this:
Your public key has been saved in / root/.ssh/id_rsa.pub.
That's right. Let's open this file now.
Cat / root/.ssh/id_rsa.pub
Copy the contents of the file, then open the http://git.oschina.net/keys page, create a new key, and paste the copied contents in.
In this way, we associate the key on the server with the oschina platform.
2. Clone project
Then we use the git clone command to clone the test111 project. Remember that the address of clone is ssh instead of https. At this time, we will be prompted to enter the user name and password, which are the account number and password of oschina, respectively.
If you are cheap to do clone in https, you can reset the remote warehouse address with the following command (if not, you can skip this step)
/ / remove the previous remote warehouse address git remote remove origin// add the remote warehouse address as ssh, not httpsgit remote add origin git@git.oschina.net:wwolf/test111.git
3. Compatibility of multiple accounts
At this point, there is basically no problem with the pull push operation of the test111 project. If user 222wants to manage the project test222 on this server, we report an error after we directly execute git clone git@git.oschina.net:222/test222.git, and the prompt is as follows:
Access denied.fatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.
Why? First of all, the most important question must be the problem of key! Because we did not add the oschina account of key associated with user 222on this server before! Let's re-add a key to the server according to step 1, but it is important to note that the file saved by our key needs to be renamed, otherwise the key created by user 111will be overwritten!
Ssh-keygen-t rsa-C account 222email @ qq.com "/ / then prompt us which file we want to save key in, re-enter the file name and Enter file in which to save the key (/ root/.ssh/id_rsa): / root/.ssh/id_rsa_2// then enter and finish, and say the important words three times!
Then we log in to the oschina account of account 222and add key.
But the problem arises, at this time we re-clone test222 still remind us that we do not have permission, how to return a responsibility? The central theme of this article has been exposed! After a lot of nonsense, I started to get to the point--
In fact, when we clone test222 project at this time, git is compared with the key in the default id_rsa.pub file, which must be problematic, because the key is not added to the 222account! That is to say, if we clone test222 here, let git take the key in the id_rsa_2.pub file to verify, isn't it? Yes, that's it! Let's look at the implementation steps:
First, let's ask git to identify our new key.
Ssh-agent bashssh-add / .ssh/id_rsa_2
Then we create or modify the config file in the ~ / .ssh/ directory
# Host is the address of your remote warehouse. Note that if some servers do ip port forwarding, do not put the port number here. Host git.oschina.net#HostName is the address of the remote warehouse. Similarly, if you do port forwarding, you should not use the port number HostName git.oschina.net#Port port number. If you do forwarding, you need to enter the port number here. If it is not necessary to fill in the file IdentityFile ~ / .ssh/id_rsa# that user User 11 identifies key and points to the same platform, the following Host needs to be dealt with, because when we use this key, we will definitely find the first key first if we use this key from top to bottom. If we do not make any changes, we will definitely find the first key first, which is still invalid. Just change it casually. There is no special treatment for other parameters Host git222.oschina.netHostName git.oschina.net#Port 8800User 222IdentityFile ~ / .ssh/id_rsa_2
As you can see, we have processed the Host of 222users, so we need to change the address of the remote warehouse.
/ / the original warehouse address git@git.oschina.net:222/test222.git// was changed to git@git222.oschina.net:222/test222.git.
That is to say, the user 222 only needs to execute the command at this time.
Git clone git@git222.oschina.net:222/test222.git
Just do it! Just do it!
Cd test222/
/ / found that there is nothing wrong with git pull git push.
Same server, different hosting platforms, multiple account problems
The problem of these multiple platforms is basically simple. In order to illustrate, we use the project test333 of the 333rd account of the gitlab platform to test. Note that we are registering the third account to test on the basis of the above two accounts.
Git clone git@gitlab.com:333/test333.git
/ / it is conceivable that there is also no right.
Because there are not so many mailboxes, we still use the mailbox of user 222when we register gitlab, but this does not affect our operation, it is just to create one more id_rsa_3 file. In view of this, we directly copy the key in id_rsa_2.pub to the gitlab platform.
Then add the configuration of the gitlab platform in the ~ / .ssh / config file
Host gitlab.comHostName gitlab.com#Port 8800User 333Universe / because the mailbox of gitlab is the same as that of user 222.This key is used here. If it is inconsistent, you still need to generate a new key. The new key file IdentityFile ~ / .ssh/id_rsa_2 is referenced here.
Resolution of multiple account conflicts in PS:Git
Because I have two github accounts, when I was in the push project recently, I suddenly found the permission denied. Take a closer look at the original account of another github, which is not the corresponding account of the github where the current origin is located. So look for a stackoverflow above the resolver http://stackoverflow.com/questions/14689788/multiple-github-accounts-what-values-for-host-in-ssh-config.
Clear the global settings for git
Git config-global user.name "your_name" git config-global user.email "your_email"
Then reset the non-global username and mailbox for each project:
Git config user.name "your_name" git config user.email "your_email"
SSH configuration
Under the ~ / .ssh directory, use ssh-keygen-C "your_email"-t rsa to generate public and private keys. When you have multiple github accounts, you can generate multiple rsa company keys. Then configure the ~ / .ssh / config file (if not, create a new one):
# the first github project account Host first_project HostName github.com User first_user IdentityFile ~ / .ssh/id_rsa_first # the second git project account Host second_projectHostName github.com User second_user IdentityFile ~ / .ssh/id_rsa_second
Pull the code from the first project:
Git pull first master, thank you for your reading! This is the end of the article on "example analysis of git multi-account login". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.