Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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

share|improve this question
add comment

migrated from stackoverflow.com Nov 9 '11 at 8:27

This question came from our site for professional and enthusiast programmers.

4 Answers

up vote 2 down vote accepted

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.

share|improve this answer
add comment
chown -R YOUR_USER: ~/.ssh
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
share|improve this answer
    
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. –  Gordon Davisson Nov 8 '11 at 16:35
add comment

Run

man chown
man chmod

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

share|improve this answer
    
I've taken the 'sudo' part out, you don't need sudo to read man pages. –  patrix Nov 9 '11 at 8:49
add comment

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.

share|improve this answer
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. –  Gordon Davisson 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.... –  patrix Nov 9 '11 at 8:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.