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

10,016

Make sure you only have /c/Users/firstname.lastname/.ssh your public and private keys id_rsa and id_rsa.pub (no id_dsa file)

Even if your key has been uploaded to heroku, double-check that heroku keys:add see your public keys (heroku key management), and recognized it already had been published on Heroku side. (And that it is the right one)

Make sure the environment variable HOME is set at all time to /c/Users/firstname.lastname in your git-bash session.

Make sure your ssh keys aren't passphrase protected (at first, for testing) and that you don't have an ssh agent which might get confused with the ssh key used: see "Unable to push git repo to Heroku, despite valid SSH keys".

you can also try and reset the keys.

Share:
10,016
Sharethefun
Author by

Sharethefun

Updated on June 04, 2022

Comments

  • Sharethefun
    Sharethefun almost 2 years

    I've read most of the related issues and tried most of the solutions but nothing has worked for me.

    I have installed Rails and Git through RailsInstaller and I'm trying to upload my rails application into heroku from Windows 7 but I keep getting Permission denied (publickey) although my keys are uploaded into heroku.

    Here is the log of how I've tried uploading my ssh keys the last time:

    firstname.lastname@LONMAX-LTETB9X /c/Users/firstname.lastname/mytinyurl
     (master)
    $ heroku keys:clear
    Removing all SSH keys... done
    
    firstname.lastname@LONMAX-LTETB9X /c/Users/firstname.lastname/mytinyurl
     (master)
    $ heroku login
    Enter your Heroku credentials.
    Email: [email protected]
    Password (typing will be hidden):
    Could not find an existing public key.
    Would you like to generate one? [Yn] Y
    Generating new SSH public key.
    Uploading SSH public key C:/Users/firstname.lastname/.ssh/id_rsa.pub... done
    Authentication successful.
    
    firstname.lastname@LONMAX-LTETB9X /c/Users/firstname.lastname/mytinyurl
     (master)
    $ git init
    Reinitialized existing Git repository in c:/Users/firstname.lastname/myti
    nyurl/.git/
    
    firstname.lastname@LONMAX-LTETB9X /c/Users/firstname.lastname/mytinyurl
     (master)
    $ git add .
    
    firstname.lastname@LONMAX-LTETB9X /c/Users/firstname.lastname/mytinyurl
     (master)
    $ git commit -m "first"
    On branch master
    nothing to commit, working directory clean
    
    firstname.lastname@LONMAX-LTETB9X /c/Users/firstname.lastname/mytinyurl
     (master)
    $ git push heroku master
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    
    firstname.lastname@LONMAX-LTETB9X /c/Users/firstname.lastname/mytinyurl
     (master)
    $ heroku keys
    === [email protected] Keys
    ssh-rsa AAAAB3NzaC...rJqQanPQ== firstname.lastname@LONMAX-LTETB9X
    

    Can anyone see what I'm doing wrong or has any suggestions?

    Update

    Here are some more details on what log i get when i runshh on verbose

     $ ssh -vvv [email protected]
    
    OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
    debug2: ssh_connect: needpriv 0
    debug1: Connecting to heroku.com [50.19.85.132] port 22.
    debug1: Connection established.
    debug1: identity file /h/.ssh/identity type -1
    debug3: Not a RSA1 key file /h/.ssh/id_rsa.
    debug2: key_type_from_name: unknown key type '-----BEGIN'
    debug3: key_read: missing keytype
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug3: key_read: missing whitespace
    debug2: key_type_from_name: unknown key type '-----END'
    debug3: key_read: missing keytype
    debug1: identity file /h/.ssh/id_rsa type 1
    debug1: identity file /h/.ssh/id_dsa type -1
    debug1: Remote protocol version 2.0, remote software version Twisted
    debug1: no match: Twisted
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_4.6
    debug2: fd 3 setting O_NONBLOCK
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-g
    roup-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
    debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
    debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour1
    28,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-c
    tr,aes192-ctr,aes256-ctr
    debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour1
    28,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-c
    tr,aes192-ctr,aes256-ctr
    debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@open
    ssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@open
    ssh.com,hmac-sha1-96,hmac-md5-96
    debug2: kex_parse_kexinit: none,[email protected],zlib
    debug2: kex_parse_kexinit: none,[email protected],zlib
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit: first_kex_follows 0
    debug2: kex_parse_kexinit: reserved 0
    debug2: kex_parse_kexinit: diffie-hellman-group1-sha1
    debug2: kex_parse_kexinit: ssh-rsa
    debug2: kex_parse_kexinit: aes256-ctr,aes256-cbc,aes192-ctr,aes192-cbc,aes128-ct
    r,aes128-cbc,cast128-ctr,cast128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc
    
    debug2: kex_parse_kexinit: aes256-ctr,aes256-cbc,aes192-ctr,aes192-cbc,aes128-ct
    r,aes128-cbc,cast128-ctr,cast128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc
    
    debug2: kex_parse_kexinit: hmac-sha1,hmac-md5
    debug2: kex_parse_kexinit: hmac-sha1,hmac-md5
    debug2: kex_parse_kexinit: none,zlib
    debug2: kex_parse_kexinit: none,zlib
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit:
    debug2: kex_parse_kexinit: first_kex_follows 0
    debug2: kex_parse_kexinit: reserved 0
    debug2: mac_init: found hmac-md5
    debug1: kex: server->client aes128-cbc hmac-md5 none
    debug2: mac_init: found hmac-md5
    debug1: kex: client->server aes128-cbc hmac-md5 none
    debug2: dh_gen_key: priv key bits set: 133/256
    debug2: bits set: 529/1024
    debug1: sending SSH2_MSG_KEXDH_INIT
    debug1: expecting SSH2_MSG_KEXDH_REPLY
    debug3: check_host_in_hostfile: filename /h/.ssh/known_hosts
    debug3: check_host_in_hostfile: match line 1
    debug3: check_host_in_hostfile: filename /h/.ssh/known_hosts
    debug3: check_host_in_hostfile: match line 3
    debug1: Host 'heroku.com' is known and matches the RSA host key.
    debug1: Found key in /h/.ssh/known_hosts:1
    debug2: bits set: 499/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
    debug2: set_newkeys: mode 0
    debug1: SSH2_MSG_NEWKEYS received
    debug1: SSH2_MSG_SERVICE_REQUEST sent
    debug2: service_accept: ssh-userauth
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug2: key: /h/.ssh/identity (0x0)
    debug2: key: /h/.ssh/id_rsa (0xa01a528)
    debug2: key: /h/.ssh/id_dsa (0x0)
    debug1: Authentications that can continue: publickey
    debug3: start over, passed a different list publickey
    debug3: preferred 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: Trying private key: /h/.ssh/identity
    debug3: no such identity: /h/.ssh/identity
    debug1: Offering public key: /h/.ssh/id_rsa
    debug3: send_pubkey_test
    debug2: we sent a publickey packet, wait for reply
    debug1: Server accepts key: pkalg ssh-rsa blen 277
    debug2: input_userauth_pk_ok: fp ac:2f:88:b3:69:96:c5:f4:ba:f6:f6:9d:e6:ea:8f:cf
    
    debug3: sign_and_send_pubkey
    debug1: read PEM private key done: type RSA
    debug1: Authentications that can continue: publickey
    debug1: Trying private key: /h/.ssh/id_dsa
    debug3: no such identity: /h/.ssh/id_dsa
    debug2: we did not send a packet, disable method
    debug1: No more authentication methods to try.
    Permission denied (publickey).
    

    Thanks in advance

  • Admin
    Admin almost 10 years
    SSH keys for a user should go into that user's home folder, not into a system-wide folder. As VonC pointed out in his answer, Git Bash will look for SSH keys in the user's home folder.