Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've generated keys and had them approved for access with my corporate IT team. However, I need to add them to my terminal every time I start my machine (the script i've been given to get around this isn't working for me yet). So for now I have to issue ssh-add ~/.ssh/keyfolder/private_key every time I start my machine up.

Today however, I started getting this error:

~/.ssh/keyfolder/private_key: Permission denied

I've tried issuing a chmod 777 on that private key but no luck.

What have I done/am I doing wrong?

$sudo ls -lha ~/.ssh/keyfolder/private_key
-rwxrwxrwx 1 rabdelaz staff 1.7K 2013-07-29 10:19 /home/rabdelaz/.ssh/keyfolder/private_key

ANSWER: I needed the right permission levels in the right places (obviously).

so what I did was was set the "keyfolder" and key itself to 600.

not sure what the permsions were before...

share|improve this question
    
Provide ls -lha ~/.ssh/keyfolder/private_key ... its possible your chmod isn't taking. –  mikebabcock Sep 9 '13 at 16:00
    
posted the output –  Ramy Sep 9 '13 at 16:02
1  
I am confused, your ls command refers to ~/.ssh/deployed/2013-07-29 but the output lists /home/rabdelaz/.ssh/keyfolder/private_key what's going on? –  terdon Sep 9 '13 at 16:09
1  
that's because i'm a dumbass and didn't alias everything that needed to be aliased. –  Ramy Sep 9 '13 at 16:14
    
Posted implied answer as actual answer –  mikebabcock Sep 10 '13 at 13:13
add comment

3 Answers

up vote 1 down vote accepted

You want both the key folder and the key itself to only be readable by the user. I always do chmod 700 ~/.ssh; chmod 600 ~/.ssh/* myself, where you'll obviously want to change those directories to suit your own use case.

share|improve this answer
add comment

Never do a chmod 777 on your private key! It makes it (possibly) publicly readable, and you don't want that. Furthermore, SSH will in some cases even refuse to use a file with too permissive permissions, so you could be shooting yourself in the foot with this.

If the file's permissions aren't the issue, there can be several other causes. You could have incorrect permissions set on any of the directories ~/.ssh or ~/.ssh/keyfolder (technically also on ~ but then this wouldn't be the only symptom). Use ls -adl to inspect those directories. They should have rwx for you, but --- for both group and world.

Another issue could be (but this is quite rare) is that the ssh-add binary has the setuid bit set, causing it to run as a different user, and hence have no right to read your private key. Use ls -lh $(which ssh-add) to inspect this.

share|improve this answer
add comment

The first thing to do in this situation is to use the -v option to ssh (adding verbose), so you can look into what types of authentication methods are being tried and what the result is. This may give a subtle information of the possible wrong things that may be going into it. Then you look into the answer given by Sybren

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.