I need to setup a ssh server that way, that it will accept password authentication only when there is no key added. So when a new user is created he can copy his key by password-based authentication.

  • 2
    Any hacker will love your arrangement. – MariusMatutiae Dec 23 '16 at 13:16
  • 6
    @MariusMatutiae perhaps you should say a bit more to help out our new member. – uSlackr Dec 23 '16 at 14:12
  • 2
    @MariusMatutiae, it's really small not very used server. Mainly for small personal purposes. But, why it's so bad arrangement? – michalhosna Dec 23 '16 at 15:33

It is not possible with pure openssh. But you might be able to make it working using PAM. Conceptually, you should be able to /etc/pam.d/sshd a line with

password required pam_exec.so /usr/bin/test -s ~/.ssh/authorized_keys

I didn't test it, but you should be able to make up missing bits, if some.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.