Same server,The same hosting platform,Multiple account issues
Let's take oschina as an example. To better illustrate the problem,We use the account 111 to create a new project test111 and account 222 to create a new project test222 on the oschina platform.Otherwise we have nothing to say.
Before we want to clone the project test111,You need to follow the steps below to set the associated key
The whole process is completed with a carriage return,It's quite simple to operate! But it's not over yet,Maybe you noticed,During the carriage return,One sentence is prompted like this:
your public key has been saved in /root/.ssh/id_rsa.pub.
Yes we open this file now
Copy the contents of the file, Then open this page,Create a new key and paste the copied content in.
Thus,We associate the key on the server with the oschina platform.
Then we cloned the test111 project using the git clone command. Remember that the clone address is ssh instead of https. At this time, we will be prompted to enter a username and password.They are oschina account and password.
If your hands are cloned in https, you can reset the remote warehouse address by the following command (skip this step if there is no)
//Remove the previous remote warehouse address git remote remove origin //Add remote warehouse address as ssh, not https git remote add origin [email protected]:wwolf/test111.git
3. Multiple account compatibility issues
access denied. fatal:could not read from remote repository. please make sure you have the correct access rights and the repository exists.
why?First of all, the most important problem is definitely the problem of the key! Because we didn't add the key to this server oschina account of user 222 before! Then we follow step 1 to add a key for user 222 again on the server, but it should be noted thatThe file saved by our key is renamed,Otherwise, the key created by user 111 will be overwritten!
ssh-keygen -t rsa -c "Email address [email protected]" //Next we will be prompted which file we want to save the key in,Just re-enter the file name enter file in which to save the key (/root/.ssh/id_rsa):/root/.ssh/id_rsa_2 //then enter and finish. Important words three times!
Then we log in to the oschina account of account 222 and add the key
But the problem appeared,At this time we re-clone test222 still reminds us that we do not have permission,what happened???The central theme of this article is exposed! A bunch of nonsense,Start talking about the point --------------------------
In fact, at this time when we clone the test222 project, git uses the key in the default id_rsa.pub file for comparison.This is definitely a problem,Because 222 account did not add this key! That is to say, if we let git hold the key in the id_rsa_2.pub file to verify when we clone test222, wouldn't it be complete?Yes, that's it! We look at the implementation steps:
First we let git recognize our new key
ssh-agent bash ssh-add ~/.ssh/id_rsa_2
Then we create or modify the config file in the ~/.ssh/directory
#host is the address of your remote repository,Note that if some servers do IP port forwarding,Do not bring the port number here host git.oschina.net #hostname is the address of the remote repository,Similarly, if you do port forwarding, you should not carry the port number hostname git.oschina.net #port port number, if there is a forwarding need to fill in the port number here,No need to fill in #port 8800 #user user 111 #Identify the key file identityfile ~/.ssh/id_rsa #All points to the same platform,The following host needs to be processed,Because when we use this key to search from top to bottom according to the host,If you do not modify it, you will find the first key first, which is still invalid. Just change it,No special treatment for other parameters host git222.oschina.net hostname git.oschina.net #port 8800 user 222 identityfile ~/.ssh/id_rsa_2
can be seen,We processed the host of 222 users,Then we need to modify the remote warehouse address of 222
//original warehouse address [email protected]:222/test222.git //change into [email protected]:222/test222.git
In other words, the user 222 only needs to execute the command at this time.
That's it! That's it! !! !!
cd test222 /
//I found no problem with git pull git push
Same server,Different hosting platforms,Multiple account issues
The problem with these multiple platforms is basically simple,To illustrate,We used the test333 project of the 333 account on the gitlab platform for testing.Note that we are registering a third account to test on the basis of the above two accounts
//As you can imagine,Same right
Because there are not so many mailboxes,We still use the mailbox of user 222 to register for gitlab, but this has no effect on our operation.It is nothing more than creating an additional 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 gitlab platform in ~/.ssh/config file
host gitlab.com hostname gitlab.com #port 8800 user 333 //Because gitlab's mailbox is consistent with user 222, this key is used here. If they are not consistent,You still need to generate a new key, reference the new key file here identityfile ~/.ssh/id_rsa_2
ps:git multiple account conflict resolution
Since I have two github accounts, I recently discovered permission denied when I was pushing the project. Take a closer look at the other github account that was originally used, not the account corresponding to the current origin.So I found a solution on stackoverflowhttp://stackoverflow.com/questions/14689788/multiple-github-accounts-what-values-for-host-in-ssh-config.
Clear git global settings
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"
Under the ~/.ssh directory,Use ssh-keygen -c "your_email" -t rsa to generate public and private keys,When there are multiple github accounts,Can generate multiple sets of rsa company keys.Then configure ~/.ssh/config file (if not, please recreate one):
#First github project account host first_project hostname github.com user first_user identityfile ~/.ssh/id_rsa_first #Second git project account host second_project hostname github.com user second_user identityfile ~/.ssh/id_rsa_second
Pull the code from the first project:
git pull first master
- python 3x - typeerror: 'method' object is not subscriptable
- python - you may need to restart the kernel to use updated packages error
- xcode - pod install [!] no `podfile 'found in the project directory
- android studio - unresolved reference comes out in kotlin
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - emulator: dsound: could not initialize about the error message directsoundcapture
- django - oserror: [winerror 123] the file name, directory name, or volume label syntax is incorrect : '<frozen importlib_boot
- mysql startup failed [error] innodb: the innodb_system data file 'ibdata1' must be writable
- python - importerror: cannot import name md5 error cannot be resolved