4

I tried to generate ssh keys for GitHub (access through SSH in terminal), but I do not have access to the .ssh directory. I tried to ls -l ~/.ssh, but I got this error ls: .ssh: Permission denied

I tried to read on the internet tuns of tutorials and tips for fix it, but unfortunately nothing works me.

What am I doing incorrectly and how can I fix it? I am running on Mac os X 10.6

4

sounds like you don't have eXecute permission on your .ssh folder: try running ls -ld ~/.ssh and verify that the permissions are drwx------, and that the directory is owned by you. If the permissions differ, run chmod -R u+rwX,go-rwx ~/.ssh; if you're not the owner, run chown -R <your account name> ~/.ssh (find out your account name by running whoami).

If either the chmod or chown commands fail due to permission errors, run them again but prefic them with sudo.

3
chown -R YOUR_USER: ~/.ssh
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
1
  • You need 600 permissions on the contents of ~/.ssh, but 700 on the directory itself. ~Daniel Holz's version (with u+rwX) does this right. Nov 8 '11 at 16:35
2

Run

man chown
man chmod

and read how to change the ownership and permissions for the directory.

1
  • I've taken the 'sudo' part out, you don't need sudo to read man pages.
    – nohillside
    Nov 9 '11 at 8:49
1

Go into Terminal and type in:

chmod a+rwx ~/.ssh

And generate your keys.

Once you're done generating your keys, relock your .ssh directory by doing:

chmod go-rwx ~/.ssh    
chmod u+rwx ~/.ssh

The first command removes permissions from "group" and "others" and the second is probably not necessary, but it explicitly sets your own rwx bits.

I'd expect the reason the .ssh directory would be locked to "others" and "groups" would be to keep malicious apps & processes from sniffing out any keys that live in that directory.

3
  • 1
    chmod u+rwx does not remove any access; you need to remove all access for group members and others with something like chmod go=, chmod go-rwx, or chmod 700. Nov 8 '11 at 16:38
  • Yes, you're right Gordon. I'll edit my answer!
    – Michael Dautermann
    Nov 8 '11 at 16:43
  • Why do you 'chmod a+..' in the first place? Shouldn't be necessary....
    – nohillside
    Nov 9 '11 at 8:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .