How to change the default position of ssh/authorized_keys file

authorized keys

Sometimes you might need to change the default position of the authorized_keys file. You might have an encrypted home directory (unless you have another session already opened, you would never enter automagically since the key file would be unreachable).

You could create a folder:

/etc/ssh/authorized_keys

 And in this folder create a new folder for each user containing their authorized_keys file. You need to set the owner and group of the folder to the user as well.

Then you need to edit /etc/ssh/sshd_config with your favorite editor and find or add the line AuthorizedKeysFile:

AuthorizedKeysFile  %h/.ssh/authorized_keys /etc/ssh/authorized_keys/%u/authorized_keys
(NOTE: it should all be on one line)

This will make the ssh server first to look at the usual location /home/<user>/.ssh/ and if not found or accessible it will continue to look in the /etc/ssh/authorized_keys/<user> folder. 

After this modification you need to restart the ssh server:

sudo service ssh restart

That’s all folks!

Cheers
/jima 

2 thoughts on “How to change the default position of ssh/authorized_keys file”

  1. Should be

    “`
    AuthorizedKeysFile %h/.ssh/authorized_keys /etc/ssh/authorized_keys/%u/.ssh.authorized_keys
    “`

Leave a Reply to Rodrigo Cancel reply

Your email address will not be published. Required fields are marked *