Allow password authentication in SSH only when there is no key in authorized_keys

michalhosna

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.

Jakuje

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SSH still prompting for password with authorized_keys

From Dev

SSH key-based authentication: known_hosts vs authorized_keys

From Dev

How to only make one user authenticate via SSH keys and allow password authentication to all others

From Dev

ssh prompts for password despite .ssh/authorized_keys

From Dev

Add ssh key string to .ssh/authorized_keys file

From Dev

How to allow SSH only with RSA key, and SFTP with password and chroot?

From Dev

Public key authentication for LDAP users using local authorized_keys

From Dev

Can't ssh even with public key added to authorized_keys

From Dev

Add a public ssh key to the authorized_keys of a user

From Dev

Only allow internal password ssh logins, always allow external ssh logins with key

From Dev

How can I allow SSH password authentication from only certain IP addresses?

From Dev

Given keys in ~/.ssh/authorized_keys format, can you determine key strength easily?

From Dev

After changing permission of ~/.ssh/authorized_keys and the ~/.ssh directory I get a permission denied (public key)

From Dev

SSH authentication by public key and password in the same time

From Dev

Recovered .ssh/authorized_keys file, but still get Permission Denied (Public Key) message

From Java

Adding a public key to ~/.ssh/authorized_keys does not log me in automatically

From Dev

Why am I still being asked for an ssh password when I'm using private key authentication?

From Dev

Why is SSH key authentication better than password authentication?

From Dev

When using SSH is it possible to prevent password authentication only if a certificate exists in the user's home directory?

From Dev

When setting up an SSH tunnel user, authorized_keys directive "command=" blocks "permitopen" (Ubuntu 19.10)

From Dev

Can you specify git-shell in .ssh/authorized_keys to restrict access to only git commands via ssh?

From Dev

Salt and managing .ssh/authorized_keys

From Dev

how to add commands in .ssh/authorized_keys

From Dev

Redis writing to .ssh/authorized_keys

From Dev

Debian SSH authorized_keys is being ignored

From Dev

How to secure ~/.ssh/authorized_keys file?

From Dev

Still getting a password prompt with ssh with public key authentication?

From Dev

SSH - Key based authentication fails after password prompt

From Dev

scripted ssh should not ask for a password if public key authentication fails

Related Related

  1. 1

    SSH still prompting for password with authorized_keys

  2. 2

    SSH key-based authentication: known_hosts vs authorized_keys

  3. 3

    How to only make one user authenticate via SSH keys and allow password authentication to all others

  4. 4

    ssh prompts for password despite .ssh/authorized_keys

  5. 5

    Add ssh key string to .ssh/authorized_keys file

  6. 6

    How to allow SSH only with RSA key, and SFTP with password and chroot?

  7. 7

    Public key authentication for LDAP users using local authorized_keys

  8. 8

    Can't ssh even with public key added to authorized_keys

  9. 9

    Add a public ssh key to the authorized_keys of a user

  10. 10

    Only allow internal password ssh logins, always allow external ssh logins with key

  11. 11

    How can I allow SSH password authentication from only certain IP addresses?

  12. 12

    Given keys in ~/.ssh/authorized_keys format, can you determine key strength easily?

  13. 13

    After changing permission of ~/.ssh/authorized_keys and the ~/.ssh directory I get a permission denied (public key)

  14. 14

    SSH authentication by public key and password in the same time

  15. 15

    Recovered .ssh/authorized_keys file, but still get Permission Denied (Public Key) message

  16. 16

    Adding a public key to ~/.ssh/authorized_keys does not log me in automatically

  17. 17

    Why am I still being asked for an ssh password when I'm using private key authentication?

  18. 18

    Why is SSH key authentication better than password authentication?

  19. 19

    When using SSH is it possible to prevent password authentication only if a certificate exists in the user's home directory?

  20. 20

    When setting up an SSH tunnel user, authorized_keys directive "command=" blocks "permitopen" (Ubuntu 19.10)

  21. 21

    Can you specify git-shell in .ssh/authorized_keys to restrict access to only git commands via ssh?

  22. 22

    Salt and managing .ssh/authorized_keys

  23. 23

    how to add commands in .ssh/authorized_keys

  24. 24

    Redis writing to .ssh/authorized_keys

  25. 25

    Debian SSH authorized_keys is being ignored

  26. 26

    How to secure ~/.ssh/authorized_keys file?

  27. 27

    Still getting a password prompt with ssh with public key authentication?

  28. 28

    SSH - Key based authentication fails after password prompt

  29. 29

    scripted ssh should not ask for a password if public key authentication fails

HotTag

Archive