4

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.
  • Nah that's to disable the 'password:' prompt – Just Lucky Really Sep 1 '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 2 '14 at 15:49
4

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

PasswordAuthentication no

then restart the server:

sudo service restart sshd

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. – Just Lucky Really Sep 1 '14 at 21:55
  • Without a key, it should give: Permission denied (publickey). – wxl Sep 1 '14 at 22:43
  • It still shows the 'login as:' prompt – Just Lucky Really Sep 1 '14 at 22:46
  • Edited to provide a more authoritative answer. Sorry for the misunderstanding and thanks for the clarification. – wxl Sep 1 '14 at 22:52
  • 2
    Well that's a kick in the nuts – Just Lucky Really Sep 1 '14 at 23:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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