大网数据广告活动
服务器运维问答

Server allows logging in without supplying a password and no ssh keys were exchanged, what could be the reason?

· 52CE 我爱测

I'm trying to secure an outbound server with Google 2FA solution. For the time being, I'm first configuring everything on a local Vagrant machine and once everything works as intended I'll run it as an Ansible playbook on the rem…

问题原文

原帖链接 · Itai Ganot · CC BY-SA 3.0

I'm trying to secure an outbound server with Google 2FA solution.

For the time being, I'm first configuring everything on a local Vagrant machine and once everything works as intended I'll run it as an Ansible playbook on the remote outbound machine.

I've configured /etc/ssh/sshd_config like so:

Port 22
Protocol 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
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication yes
PasswordAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
Match User rescue
    AuthenticationMethods publickey
Match Group gauth
    AuthenticationMethods publickey,keyboard-interactive

and /etc/pam.d/sshd like so:

auth required pam_google_authenticator.so nullok
account    required     pam_nologin.so
@include common-account
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so close
session    required     pam_loginuid.so
session    optional     pam_keyinit.so force revoke
@include common-session
session    optional     pam_motd.so  motd=/run/motd.dynamic noupdate
session    optional     pam_motd.so # [1]
session    optional     pam_mail.so standard noenv # [1]
session    required     pam_limits.so
session    required     pam_env.so # [1]
session    required     pam_env.so user_readenv=1 envfile=/etc/default/locale
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so open
@include common-password

For some reason, users which are not members of the gauth group are able to log into the machine without supplying any password at all, while looking at the log, I see these lines:

Jun 15 13:35:57 vagrant-ubuntu-trusty-64 sshd[9836]: Accepted keyboard-interactive/pam for ubuntu from 10.0.2.2 port 55495 ssh2
Jun 15 13:35:57 vagrant-ubuntu-trusty-64 sshd[9836]: pam_unix(sshd:session): session opened for user ubuntu by (uid=0)

Since it's a vagrant machine it's important to mention that when I connect to the machine for test matters, I run:

ssh localhost -p 2222 -l username

and not

vagrant ssh machine_name

I've also tried to edit /etc/ssh/sshd_config and edit the PermitRootLogin directive from "without-password" to "no" but to no avail.

I can still login automatically to the machine without supplying any password.

When I remove the "nullok" from the auth line in pam then no user can connect at all and the error message given is:

Permission denied (publickey,keyboard-interactive).

One more thing worth mentioning is that no ssh-keys were exchanged between my Host machine and my Vagrant machine.

已采纳解答

原帖链接 · Jakuje · CC BY-SA 3.0

For some reason, users which are not members of the gauth group are able to log into the machine without supplying any password at all

You removed from the PAM stack @include common-auth line in the start, which takes care of normal authentication. If I am right, PAM checks all auth mechanisms in the PAM stack and if one of them "allows" connection (pam_google_authenticator.so nullok obviously does), it allows the connection. It is out of the scope of openssh to know how PAM authentication succeeded.

I've also tried to edit /etc/ssh/sshd_config and edit the PermitRootLogin directive from "without-password" to "no" but to no avail.

You tried root user? It should be denied.

When I remove the "nullok" from the auth line in pam then no user can connect at all

In this case, the only PAM authentication method was pam_google_authenticator.so (with flag required) and if it failed. You are obviously rejected.

Using public key should work in this case though.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-06-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。