-1

I want to clone a git repository to my ubuntu through ssh, but I'm getting the following error:

Permission denied (publickey). fatal: Could not read from remote repository.

My public key is added in the agent and I have used it already on Windows but when I tried it on Linux it didn't work.

Robin
  • 19
  • 5
  • 1
    When you moved to linux, did you take your private key with you and place it in your `~/.ssh` folder? – Lix Jul 17 '16 at 15:49
  • Yes, and named it: "id_rsa". – Robin Jul 17 '16 at 15:51
  • Take a look at [this answer](http://stackoverflow.com/a/25902177/558021). It allows you to specify a specific ssh key to use when talking to github.com – Lix Jul 17 '16 at 15:55
  • If you're still having trouble, please describe exactly how you created the key, exactly how you set it up on the git server, and exactly how you installed it on the linux system where you're trying to run git. Please include the old and new names from when you renamed the file. – Kenster Jul 17 '16 at 17:28

2 Answers2

1

Every remote git repo is associated with some login that will be performed on the remote system in order to gain access to the repo directory. This login attempt is failing, because (a) your SSH key is not being recognized (or, is not being correctly served by an SSH-agent on your computer), and (b) password-login is not an alternative.

To help diagnose the problem, remove git from the picture. Use git remote -v to find the user/host that is being attempted, and try a direct ssh login to that account. (It will fail.) Diagnose the problem as you would for any similar ssh-only issue. Once you are able to log-in, you will be able to clone.

Mike Robinson
  • 8,490
  • 5
  • 28
  • 41
1

Git does it's thing over ssh (in your case) or https. It's generally better to debug connection problems using the underlying command and not through Git, you'll get better diagnostics and can use normal ssh debugging techniques.

Try connecting to the same remote just using ssh -v (ssh in verbose mode). If it's git clone git@github.com:schwern/dotfiles.git then try ssh -v git@github.com. Just the user and host. And yes, the user should be git, Github identifies you by your ssh key.

You should get something like this...

$ ssh -v git@github.com
OpenSSH_7.2p1, OpenSSL 1.0.2h  3 May 2016
debug1: Reading configuration data /Users/schwern/.ssh/config
debug1: Reading configuration data /opt/local/etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.253.113] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /Users/schwern/.ssh/id_rsa type -1

...a whole lot of ssh looking for your ssh keys...

debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/schwern/.ssh/github
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/schwern/.ssh/id_rsa
debug1: Trying private key: /Users/schwern/.ssh/id_dsa

...a whole lot of trying ssh keys...

debug1: No more authentication methods to try.
Permission denied (publickey).

The important parts are where it looks for and offers keys. If you don't see your Github key in there, then you need to figure out why. If you do see your Github key in there, then you should check that it is what Github thinks is your key.

What you want to see is this.

$ ssh -v git@github.com
OpenSSH_7.2p1, OpenSSL 1.0.2h  3 May 2016
debug1: Reading configuration data /Users/schwern/.ssh/config
debug1: Reading configuration data /opt/local/etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.253.113] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /Users/schwern/.ssh/id_rsa type -1

...ssh finding your keys...

debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/schwern/.ssh/github
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.253.113]:22).

...Yay! You're in!...

debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: network
debug1: Requesting authentication agent forwarding.
PTY allocation request failed on channel 0
Hi schwern! You've successfully authenticated, but GitHub does not provide shell access.
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Connection to github.com closed.
Transferred: sent 2936, received 1796 bytes, in 0.2 seconds
Bytes per second: sent 13380.7, received 8185.2
debug1: Exit status 1
Schwern
  • 153,029
  • 25
  • 195
  • 336