3

I've restarted ssh with sudo systemctl restart ssh on xenial 16.04 LTS running a VPS on AWS EC2, yet still get prompted for a password when connecting with ssh. How can I disable root ssh and disable password login?

ubuntu@ip-xxx-xx-x-xx:~$ cat /etc/ssh/sshd_config 
# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
#PermitRootLogin prohibit-password
PermitRootLogin no
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication yes

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes




AllowUsers thufir ubuntu


DenyUsers root
ubuntu@ip-xxx-xx-x-xx:~$ 

Both allowed users belong to the sudo group.

The log at /var/log/auth.log shows:

sshd[2035]: Accepted keyboard-interactive/pam for thufir from xxx.xxx.xxx.xxx port 43986 ssh2

Thufir
  • 4,551
  • 1
    post the output of ssh -vvv – Panther Jan 09 '17 at 19:22
  • @bodhi.zazen I will, want to hide ip/etc. I notice that while one user, thufir, is prompted, the default user, ubuntu is not prompted. Only the default user uses keys...weird, right? – Thufir Jan 09 '17 at 19:28
  • 1
    Your sshd_config is correct. You can set and ChallengeResponseAuthentication no. By default, you need to have correct keys in ~/.ssh folder, for each user. – pa4080 Jan 09 '17 at 19:36
  • cant tell if you are being asked for your key password or not from what you posted. – Panther Jan 09 '17 at 19:57
  • @bodhi.zazen it's weird enough that I asked a slightly different question: http://askubuntu.com/q/869966/ with verbose ssh login. – Thufir Jan 09 '17 at 20:23
  • 1
    @SpasSpasov I tried toggling ChallengeResponseAuthentication but it doesn't seem to fix nor make worse the problem. But, yes, I looked at that line carefully. I'll have to double check, but didn't seem to be problematic. – Thufir Jan 09 '17 at 20:25

2 Answers2

6

How to disable password and root ssh?

Let's rephrase it, and I expect you want

  • Deny all root login
  • Deny all password logins for all users
  • Allow other users with other authentication methods (publickey)

This is achieved using the below configuration options:

PermitRootLogin no
PasswordAuthentication no
ChallengeResponseAuthentication no

If you change your config to have these (not append to the end!) and restart your server, you should achieve the above. If not, please, clarify the question and post the logs as asked already.

Pablo Bianchi
  • 15,657
Jakuje
  • 6,605
  • 7
  • 30
  • 37
0

Open sshd_config:

EDITOR=vim sudoedit /etc/ssh/sshd_config

Note that you can replace vim with whatever editor you chose, like nano. In that file, make sure that PermitRootLogin is disabled:

PermitRootLogin no
cocomac
  • 3,394