Permissions denied to owner, although it is set to 666 in .ssh directory

17,568

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
Share:
17,568

Related videos on Youtube

SoWhat
Author by

SoWhat

Well, I am a writer. I write code, I write poems, I write essays, I write stories.

Updated on September 18, 2022

Comments

  • SoWhat
    SoWhat almost 2 years

    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
    
  • kos
    kos almost 9 years
    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).
  • Josh
    Josh almost 9 years
    @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.
  • kos
    kos almost 9 years
    @Josh Yep, the layout confused me.
  • SoWhat
    SoWhat almost 9 years
    I managed to fix this before itself, by copying it somewhere else and then copying it back