Post

Linux .ssh folder permisisons for public private key authentication

Linux .ssh folder permisisons

This one is the classic silent failure: SSH will silently ignore your keys if the permissions on ~/.ssh or authorized_keys are too permissive. No error message, no indication of why — it just falls back to password auth. The correct permissions are 700 for the .ssh directory and 600 for authorized_keys.

  • Login as user for which you are setting .ssh
1
2
3
4
5
6
7
$ ls -lrta

drwx------   2 user user    29 Aug 01 06:20 .ssh

$ #make sure the permisions are same as above else execute the below command to make them so

$ chmod 700 .ssh
  • Enable public private key pair authentication
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ cd .ssh

$ ls -lrt

rw------- 1 user user 560 Aug 01 06:20 authorized_keys

$ #make sure the permisions are same as above else execute the below command to make them so

$ chmod -R 600 authorized_keys

$ # if the authorized_keys file does not exist then make

$ touch authorized_keys

$ # set permissions

$ chmod -R 600 authorized_keys
  • Now add your public key to the authorized_keys file

  • Then use the private key linked to the public key that you added to the authorized_keys file to ssh into the box

This post is licensed under CC BY 4.0 by the author.