12

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...

2
  • Provide ls -lha ~/.ssh/keyfolder/private_key ... its possible your chmod isn't taking. Sep 9, 2013 at 16:00
  • 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, 2013 at 16:09

3 Answers 3

20

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.

Alternatively, you can chown -R $USERNAME ~/.ssh; chmod -R go-rwx ~/.ssh

The chown can be necessary when the key file was downloaded or installed as root for instance.

4

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.

0

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

1
  • 1
    ssh-add doesn't support -v flag. May 21, 2018 at 17:23

You must log in to answer this question.

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