Linux – ssh via public key if there is no home directory on the remote system

homekey-authenticationlinux

I currently have to ssh with user FOO then sudo to user BAR.

I would like to ssh using a public key, but on the remote system there is no home directory for user FOO, so obviously no .ssh/authorized_keys. Where can I put my public key ?

The /home directory is empty, so it seems no home directories are created for any user, and I don't have root on that system.

Thanks.

Best Answer

Assuming your username is testssh:

  • create /etc/ssh/authorized_keys_testssh and put your key there
  • add the following in /etc/ssh/sshd_config:
Match User testssh
    AuthorizedKeysFile  /etc/ssh/authorized_keys_%u

and restart sshd. Your user will be able to ssh with his private key.

Related Question