I recently ran into an issue where I could not push changes into a repository I had cloned down as another user from the first user I pushed with in git on my desktop.
Basically it went like this,
Attempt to push changes to repo and receive error that the original username does not have permission, even though this was cloned using the second user and more specifically an ssh key.
Clearing the git entries in the windows credential manager did not resolve this issue.
Clearing the global user name and email did not resolve this issue
I was finally able to push my changes using the following:
GIT_SSH_COMMAND="ssh -i <path to private ssh key for second user>" git push
I am posting this both for others who have experienced this issue and also to ask a few questions,
I understand this command is essentially specifying the key for the ssh connection to use when it makes it's push, but why is this key not already targeted if it was cloned using that same identity file?
Are there any alternatives to this or better approaches that are not tedious work like manually changing config values or removing entries from the windows credential manager?
So the goal would be to push changes to multiple github accounts without having to do things like temporarily specify the ssh key to use.
https://github.com/schwaggs/testssh
https://github.com/jjschweigert/testrepo
[email protected]:schwaggs/testssh.git
[email protected]:jjschweigert/testrepo.git
$ cat ~/.ssh/config
Host jjschweigert
HostName github.com
User git
IdentityFile ~/.ssh/jjschweigert_key
Host schwaggs
HostName github.com
User git
IdentityFile ~/.ssh/jjschweigert_key
$ git clone jjschweigert:jjschweigert/testrepo.git
Cloning into 'testrepo'...
remote: Enumerating objects: 28, done.
remote: Counting objects: 100% (28/28), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 28 (delta 0), reused 28 (delta 0), pack-reused 0
Receiving objects: 100% (28/28), done.
$ git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 261 bytes | 43.00 KiB/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To jjschweigert:jjschweigert/testrepo.git
c082e38..31b7830 master -> master
$ git clone schwaggs:schwaggs/testssh.git
Cloning into 'testssh'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 21 (delta 0), reused 18 (delta 0), pack-reused 0
Receiving objects: 100% (21/21), done.
$ git push
ERROR: Permission to schwaggs/testssh.git denied to jjschweigert.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
$ ssh -T jjschweigert
Hi jjschweigert! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T schwaggs
Hi jjschweigert! You've successfully authenticated, but GitHub does not provide shell access.
Clearing the git entries in the windows credential manager did not resolve this issue.
If you are using ssh URL ([email protected]:<user>/<repo>
), the credential manager is not involved: it provides credentials for https://
URLS only.
Use git for the first time which asks for github credentials when pushing to a repository.
That would be the case only if the remote origin URL is an https one.
So the goal would be to push changes to multiple github accounts without having to do things like temporarily specify the ssh key to use.
That is done through an ssh config file: see as practical examples:
From the edit
Host user1
HostName github.com
User git
IdentityFile ~/.ssh/iser1_key <<====
Host user2
HostName github.com
User git
IdentityFile ~/.ssh/user1_key <<==== same key!? Meaning same user!
you cannot expect push as user2, if the SSH config for user2 entry refers to user1 private key.
Per the conversation with VonC you can clearly see in the ssh config file the identity file for the second user was incorrect as it pointed to the first users file. The second entry was copied from the first and this value was not changed.
After modifying the value to point to the correct key i.e. ~/.ssh/schwaggs_key I could clone and push without issue. As a side note I have to set the user's email and name properties in git for each repository pulled from each user i.e once inside the repo,
git config user.email "github account email"
git config user.name "github account username"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With