This is probably not a dup; I have read through many similar problems on StackOverflow but not this issue.
I am trying to use multiple git accounts on Ubuntu Linux and whenever I try to push from the 2nd account it thinks that I am still using the username of the first account.
$ git push -u origin master
ERROR: Permission to <act2>/<repo>.git denied to <act1>.
I first tried the multiple SSH key method. When I got the above error I then created a completely new user on my local machine, logged in as that user, recreated the local repo (its the first push) and tried again. Same error. My local .config shows the user as and so does my ~/.gitconfig.
Any ideas?
I do: ssh @localhost then ssh -vvv -T [email protected]
I get this interesting output. It seems to go off and find a key in my account. But somehow it uses a key in my account, which is really shouldn't have access to.
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home//.ssh/known_hosts:1
debug2: bits set: 513/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: Wrote 16 bytes for a total of 1015
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug3: Wrote 48 bytes for a total of 1063
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key:
debug2: key:
debug2: key: /home//.ssh/identity ((nil))
debug2: key: /home//.ssh/id_rsa ()
debug2: key: /home//.ssh/id_dsa ((nil))
debug3: Wrote 64 bytes for a total of 1127
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred gssapi-keyex,gssapi-with-mic,gssapi,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key:
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug3: Wrote 368 bytes for a total of 1495
debug1: Authentications that can continue: publickey
debug1: Offering public key:
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug3: Wrote 368 bytes for a total of 1863
debug1: Remote: Forced command: gerve
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug2: input_userauth_pk_ok: fp
debug3: sign_and_send_pubkey
debug3: Wrote 640 bytes for a total of 2503
debug1: Remote: Forced command: gerve
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug3: Wrote 128 bytes for a total of 2631
debug2: callback start
...
Contributing to two accounts using HTTPS and SSHIf you contribute with two accounts from one workstation, you can access repositories by using a different protocol and credentials for each account. Git can use either the HTTPS or SSH protocol to access and update data in repositories on GitHub.com.
In the menu bar, use the GitHub Desktop drop-down menu, then click Preferences. Choose Accounts to add or remove a GitHub or GitHub Enterprise account.
For most developers, there may be a need to run multiple GitHub accounts on one computer. For instance, you can run an Organization's GitHub account and another one for your personal projects all on the same computer. In this article, you will learn how to use multiple SSH keys for different GitHub accounts.
Most people will use one personal account for all their work on GitHub.com, including both open source projects and paid employment. If you're currently using more than one personal account that you created for yourself, we suggest combining the accounts.
This happens because ssh-agent caches the ssh key (you can even remove the file and it will still allow ssh to connect successfully until the cache is cleared) and will prioritise the cached keys even over the ones specified via IdentityFile. You can see which files are cached by running:
ssh-add -l
You can force ssh-agent to ignore the cache by including IdentitiesOnly "yes" in the .ssh/config for each connection:
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_dsa_work
IdentitiesOnly yes
More information here: http://sealedabstract.com/code/github-ssh-with-multiple-identities-the-slightly-more-definitive-guide/
It took me quite a while to discover this too, hope it helps someone.
To state my assumptions for this answer, it sounds from the question title as if what you really want to do is to be able to push to GitHub being identified as different GitHub users.
If that's the case, you shouldn't create multiple users on your system just in order to push as different GitHub users over SSH. The right way to do this is to set up two aliases for github.com
in ~/.ssh/config
that specify different identity files, as described here. For example, you might have in your ~/.ssh/config
the following:
Host github-act1
HostName github.com
User git
IdentityFile /home/whoever/.ssh/id_rsa.act1
Host github-act2
HostName github.com
User git
IdentityFile /home/whoever/.ssh/id_dsa.act2
Then you can add two remotes to your repository:
git add remote act1 git@github-act1:whoever/whatever.git
git add remote act2 git@github-act1:whoever/whatever.git
Then if you want to push as one user you can do:
git push act1 master
... or as the second account:
git push act2 master
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