I've set OpenSSH server with private/public keys, with password login disabled.

I was wondering if there was a way to not even show the 'login:' prompt when someone without a key tries to connect.


Okay ... There seems to be some confusion as to what I'm trying to achieve. So, here's a better explanation (I hope) ...

Current setup

Client with key connects, and goes through the process:

login as: username
Authenticating with public key "Key name"
Passphrase for key "key name": *******

Client without key connects, and goes through process:

login as: username
Server refused our key

What I want

client without key connects, and goes through process:

No key, go away.
  • See stackoverflow.com/questions/20898384/…
    – Panther
    Sep 1, 2014 at 22:26
  • Nah that's to disable the 'password:' prompt Sep 1, 2014 at 22:34
  • The keys on the server side are typically stored in ~/.ssh, i.e. a user-specific directory, so it makes sense that you would always have to provide a username one way or another; it has to know which keys to compare. If you have the same username on each machine then SSH without a username assumes the one you are connecting to is the username on your local machine.
    – adamconkey
    Sep 2, 2014 at 15:49
  • How will the Server know which key to try if you have not identified a user? SSH won't run through every key on file in the hope that something fits. That would all kinds of problems. The simplest way to avoid the login prompt is to include the username in the ssh connection command: ssh [email protected]
    – user535733
    Oct 19, 2020 at 23:43

1 Answer 1


On the server side, edit /etc/ssh/sshd_config so that you have the line:

PasswordAuthentication no

then restart the server:

sudo service sshd restart

That will remove the ability to authenticate without a key.

However, you will always have to identify yourself, so you can't remove the login prompt.

If you use ssh username@hostname to connect, you'll never see it, but others will if they connect to the hostname with no username.

You can limit access to only your username with a key if you add to the above:

AllowUsers username

For this and other things, see the Ubuntu wiki page for SSH.

  • Erm ... Yeah I've already done that ... But doesn't change the normal behavior of showing the 'login:' prompt when someone connects to the server. Sep 1, 2014 at 21:55
  • Without a key, it should give: Permission denied (publickey).
    – wxl
    Sep 1, 2014 at 22:43
  • It still shows the 'login as:' prompt Sep 1, 2014 at 22:46
  • Edited to provide a more authoritative answer. Sorry for the misunderstanding and thanks for the clarification.
    – wxl
    Sep 1, 2014 at 22:52
  • 2
    Well that's a kick in the nuts Sep 1, 2014 at 23:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .