用户在“AllowUsers”列表中时被拒绝 ssh 访问

用户在“AllowUsers”列表中时被拒绝 ssh 访问

我继承了工作场所 Linux 盒子的管理权;它是由一位现已去世的同事设立的。最近,我向系统添加了一个新用户,并尝试为她提供 ssh 访问权限;大多数使用机器的人访问它的方式。这下我没法上班了

发生的情况如下:

scmb-bkobe03m:~ xzhang$ ssh -v -X -p 22 arwen@myServer
OpenSSH_5.2p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to myServer [152.98.xx.xx] port 22.
debug1: Connection established.
debug1: identity file /Users/xzhang/.ssh/identity type -1
debug1: identity file /Users/xzhang/.ssh/id_rsa type 1
debug1: identity file /Users/xzhang/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5p1 Debian-6+squeeze2
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '[myServer]:22' is known and matches the RSA host key.
debug1: Found key in /Users/xzhang/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/xzhang/.ssh/identity
debug1: Offering public key: /Users/xzhang/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/xzhang/.ssh/id_dsa
debug1: No more authentication methods to try.

现在,我当然已将她的公共 ssh 密钥添加到authorized_keys文件中。所以我查看了 /var/log/auth.log 并发现

Jan  7 11:37:12 sauron sshd[5002]: User arwen from myClientMachine not allowed because not listed in AllowUsers

这很有趣,因为我确实将她添加到AllowUsers

daniel@sauron:~$ sudo more /etc/ssh/sshd_config | grep AllowUsers
AllowUsers jonathan daniel rafael simon thomas li arwen

我不知道从这里该去哪里。有接受者吗?

答案1

如果您绝对确定已重新启动 SSH 服务器或通过向其发送 SIGHUP 告诉其重新加载其配置文件...

也许AllowUsers是在一个Match部分?如果存在先前的Match指令,则可能会导致乔纳森、阿尔文和其他人仅在某些情况下被允许,例如


Match localhost PasswordAuthentication yes

# Whitelist users who may ssh in
AllowGroups admin
AllowUsers jonathan daniel rafael simon thomas li arwen

(该注释具有误导性:这些AllowGroupsAllowUsers指令仅在登录到本地主机时适用。该Match localhost指令应移至这些指令下方。)

答案2

如果你在 Ubuntu 下,你可能会遇到和我一样的问题。有两个服务定义 /etc/init.d/ssh 和 /etc/init/ssh.conf 。像(旧式)一样重新启动服务

/etc/init.d/ssh restart

不执行任何操作(并且状态命令不显示任何内容)。直接重启Upstart服务就好

service ssh restart

做这件事。由于操作系统重新启动对您的情况有所帮助,这似乎是一个问题。

另外,请检查用户是否以空格分隔,而不是以逗号分隔。 SSH 守护进程不会显示任何警告。

答案3

免费名额可能是问题所在。

在 sshd_config 或 ssh_config 中,如果注释了AllowGroups 或AllowUser,则这些也适用于 ssh 远程会话。如果您已注释 PermitRemotelogin No,请将 No 更改为 Yes。

“您还可以注释掉该语句并重新启动 ssh,看看是否存在问题,然后再尝试更改其他内容。要注释掉,只需在注释前添加主题标签

#AllowGroups Group1 <- made up group
#Allow User User1

AllowGroups Group1
AllowUser User1

检查用户组,确保您尝试登录的用户名位于该组中。

vi /etc/group

Group1:100:user1,root, etc <- 如果此处未列出任何内容,那么它是拒绝允许声明。

对 sshd_config 或 ssh_config 进行任何更改后,您必须重新启动 ssh。

svcadm restart ssh

其他值得一看的地方:

vi /etc/defalut/login
vi /etc/pam.config
vi /etc/sshd_config

相关内容