Ask Different is a question and answer site for power users of Apple hardware and software. 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

I have enabled remote login (ssh) on my Mac via System Preferences. But it doesn't work with keys and only works with normal user/pass authentication. I want to disable this behaviour and only allow public key (RSA or DSA) authentication.

I edited /etc/sshd_config and uncommented following lines:

PasswordAuthentication no
PermitEmptyPasswords no

I then restarted the Remote Login service but it didn't help. It still allows password authentication and my keys are rejected.

Could anyone help me set this up?

share|improve this question
Please split of the second part (local network only) into a separate question, makes it easier for people to answer just one of them. – patrix Dec 18 '11 at 19:58
Done -… – Michal M Dec 18 '11 at 20:18
Where and how do you define your authorized keys? Key bases login works fine out of the box. – Gerry Dec 18 '11 at 20:30
@Gerry I have had my personal private/public keys generated for a while now. I used cat >> ~/.ssh/authorized_keys, but no success. – Michal M Dec 18 '11 at 20:35
Did you fiddle with any other sshd settings before? A print out of your sshd_config file could be useful. If not, my guess is your public key is invalid, or does not match your private key, maybe you should try to generate a new key. – Gerry Dec 18 '11 at 21:21
up vote 5 down vote accepted

Allow me to answer myself as I found a resolution.

If PasswordAuthentication no doesn't work on its own (and I read in some situations it may) make sure to uncomment and set to "no" this:

UsePAM no

Kudos for this resolution go to Mac OS X Hints -

share|improve this answer
On OS X El Capitan 10.11.2 the file to edit is /private/etc/ssh/sshd_config – jonatan Feb 28 at 17:24

On Mac OS X 10.8.5 (Mountain Lion) you also need to comment out the following line in /etc/sshd_config:

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys

#AuthorizedKeysFile .ssh/authorized_keys

share|improve this answer

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.