5

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.

EDIT

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
BANNER
Authenticating with public key "Key name"
Passphrase for key "key name": *******
Welcome
username@hostname:~$

Client without key connects, and goes through process:

login as: username
BANNER
Server refused our key

What I want

client without key connects, and goes through process:

No key, go away.
Just Lucky Really
  • 723
  • 2
  • 10
  • 21
  • See http://stackoverflow.com/questions/20898384/ssh-disable-password-authentication – Panther Sep 01 '14 at 22:26
  • Nah that's to disable the 'password:' prompt – Just Lucky Really Sep 01 '14 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 02 '14 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 homerjsimpson@servername.org – user535733 Oct 19 '20 at 23:43

1 Answers1

5

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.

Jacta
  • 103
  • 2
wxl
  • 901
  • 5
  • 23