Using Debian 8.

I need a myuser user, which should have no password, just key file based SSH login.

My /etc/passwd contains the following:


How can I set SSH private key file to a different directory?

I tried to add a specific path to /etc/ssh/sshd_config

AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 /my/specific/path/.ssh/authorized_keys

but doesn't authenticate when trying to login to SSH with myuser username.

But I get:

ssh myuser@
myuser@'s password:

EDIT1: The .ssh dir permission:

ls -la /my/specific/path
drwx------ 2 myuser myuser    4096 Apr 23  2018 .ssh

The authorized_keys file permission:

ls -la /my/specific/path/.ssh
-rw------- 1 myuser myuser  101 Jun 15 19:51 authorized_keys

But still can not login. How to fix?

  • 1
    The most likely cause is permissions. You probably don't need to change AuthorizedKeysFile at all. Try with ssh -vv myuser@ and also watch the log file that sshd writes to (journalctl -f -u sshd for a systemd system). – NickD Jun 15 '19 at 18:39
  • 2
    You don't need to change the sshd configuration at all. The /my/specific/path/.ssh/authorized_keys is already searched since it's the default .ssh directory in the user's home directory (in fact, changing the config would make the SSH daemon check that file for every user that connects) Just make sure that the file itself has the correct permissions (rw for owner only). – Kusalananda Jun 15 '19 at 18:41
  • 1
    N.B. Even if you authenticate, you're not going to be able to open an ssh session with /usr/sbin/nologin as your login shell (with the exception of SFTP, if the server is configured properly). – Kenster Jun 15 '19 at 19:15
  • Edited question. Added permission info. What should I use instead of /usr/sbin/nologin? – klor Jun 15 '19 at 19:20
  • 1
    @klor Use any valid login shell (see /etc/shells). – Kusalananda Jun 15 '19 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.