Question

I have the following error when I tried to push:

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

Please make sure you have the correct access rights
and the repository exists

I know what it means. However, id_rsa.pub does exist locally and it's copied to bitbucker as well, they are both identical. The repository exists also.

What could the cause?

Was it helpful?

Solution

Public Key issues

  1. Check that you're putting in the correct remote repository path (i.e. git@github.com:username/reponame).

  2. Debug the connection with ssh git@somehostname.com -T -vv to get verbose mode. Check the output. It will tell you what's going on. If you're still stuck, post it here and we can have a look.

  3. ssh will often complain if your private key or its parent directories leading to the private key have higher permissions set than they ought to.

    1. The key itself should be set with chmod 0600 ~/.ssh/id_rsa, and the ~/.ssh directory to 0700 at most.
    2. The ~ and ~/.. (parent directory, often /home on Linux and /Users on Mac OS X) should be set to 744 at most.
    3. Also check that the group and user permissions are set correctly on the key and its parent directories:

      $ id -un && id -ug   # check output of this command before using!
      username
      groupname
      $ chown --recursive $(id -un):$(id -gn) ~   
      

      This will reset all permissions on your home directory so your current user and group own all files. This may not be what you want. See man chown.

  4. You may also want to check the ~/.ssh/authorized_keys file on the remote host if you're still having trouble. Its permissions are also a point of failure.


Repairing OSX directory permissions

@AlexanderSupertramp, I said the permissions should be 744 'at most,' yes, referring to the requirements for SSH only. But I did not suggest that you should chmod the /home directory to that number. Each operating system has its own requirements for directory permissions, and I could only provide generic instructions since you didn't provide much information about your system. In any case, I am terribly sorry that my answer was not clear.

It is possible that your mac is failing to boot because 744 is too liberal. But I cannot be sure. To resolve this you may want to pay a visit to the Genius Bar at an Apple Store or contact an authorized repair technician. You may also be able to fix the directory permissions automatically using built-in tools as follow:

  1. Boot into single-user mode by pressing Command+S at the same time as the power button to turn on your mac, as explained in this article.
  2. Launch the OSX Disk Utility from the menu bar, and then use the repair permissions tool as described in this Apple KB
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top