Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to force specific users to login with public key, while allowing other users to login with password? Since public key authentication (with passphrase) is stronger than password-only authentication, we would like to require sudoers to login with public key. However, it is less convenient to force normal users to do so. In sshd_config, I don't see any policy-related configuration.

share|improve this question

migrated from Feb 22 '11 at 15:53

This question came from our site for professional and enthusiast programmers.

up vote 7 down vote accepted

You have a few options. In this answer I'm going to assume you have a sudoers group defined.

Take a look at the sshd_config man page, and look for the Match directive. This lets you specify configuration blocks that apply only to a subset of your ssh connections. You could do something like this:

Match Group sudoers
PasswordAuthentication no
ChallengeResponseAuthentication no

You could in theory accomplish something similar with a PAM configuration that would simply fail authentication attempts by people in the sudoers group. This would probably involve the pam_succeed_if could add something like this to your auth config for sshd:

auth        requisite user notingroup sudoers quiet

This means that only people not in the sudoers group can authentication via PAM. Note that this is untested. You could also use the pam_listfile module to do something similar.

share|improve this answer
Thanks! I must also note that the Match directive is introduced in OpenSSH 5.0. For conservative distributions like CentOS, it may not be available natively. – Crend King Feb 23 '11 at 8:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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