13

I recently messed around with the .ssh directory. Made some permission changes, I think and now it won't let me access it anymore. I can access it as the root user (sudo -i) but not as user1

I get permission denied when listing or cding into .ssh even though it shows the files

ls: cannot access /home/user1/.ssh/amazon.pem: Permission denied
ls: cannot access /home/user1/.ssh/id_rsa: Permission denied
ls: cannot access /home/user1/.ssh/known_hosts: Permission denied
ls: cannot access /home/user1/.ssh/id_rsa.pub: Permission denied
total 0
-????????? ? ? ? ?            ? amazon.pem
-????????? ? ? ? ?            ? id_rsa
-????????? ? ? ? ?            ? id_rsa.pub
-????????? ? ? ? ?            ? known_hosts

Logging in as root and ls gives following results

# ls -l /home/user1/ -a |grep ssh
drw-rw-rw-  2 user1 user1 4096 Aug 27 15:45 .ssh

Even the files inside are .ssh are owned by user1:user1 and chm

-rw-rw-rw- 1 user1 user1 1692 Aug 27 15:45 amazon.pem
-rw-rw-rw- 1 user1 user1 1675 Aug 25 20:01 id_rsa
1

2 Answers 2

28

Steeldriver is right. On directory you need also x access flag to be able to list files inside.

Fixing the directory using chmod 700 ~/.ssh should help you to get into this (correct) state:

$ ls -ld ~/.ssh
drwx------. 2 user user 4096 Aug 26 10:37 /home/user/.ssh

Also you should fix your keys using chmod 600 ~/.ssh/id_rsa and chmod 644 ~/.ssh/*.pub to get this:

$ ls -l ~/.ssh/
-rw-------. 1 user user  1766 Mar  7  2014 id_rsa
-rw-r--r--. 1 user user   415 Mar  7  2014 id_rsa.pub
1
  • I managed to fix this before itself, by copying it somewhere else and then copying it back
    – SoWhat
    Aug 29, 2015 at 8:37
-2

When you run command ls -l on any directory the first column is the permission column which is interpreted as follows:

1-------------2 3 4-------5 6 7-------8 9 10

(TYPE)----(user)-----(group)----(others)

TYPE : If '-', it is a file. If 'd' it is a directory.

Permissions: read: 4, write: 2, execute: 1

So for read, write and execute your permissions will be 7 in user group.

You can use

sudo chmod 7 6 6 file_name 

or

sudo chmod -R u+x /home/somesh/.ssh 

-R – this modifies the permission of the parent folder and the child objects within

3
  • 2
    I don't understand the TYPE part; also chmod 700 file_name and chmod u+x file_name do two completely different things. The first one sets the permissions to rwx/---/---, the second one just sets the x bit for the owner (and starting from 666 it will change the file to 766, not to 700).
    – kos
    Aug 27, 2015 at 13:50
  • 1
    @kos, s/he means the first field in the string indicates the type of file entry. A - character means it's a "normal" file. A d means it is a directory. There are others, too, like c, l (for symbolic link), s, and even more for other OSes.
    – Josh
    Aug 28, 2015 at 0:22
  • @Josh Yep, the layout confused me.
    – kos
    Aug 28, 2015 at 3:45

You must log in to answer this question.

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