validationsshdconfiguration

我如何validationsshdconfiguration

例如,我想确保设置和应用这些设置:

 AllowUsers user1 user2 PasswordAuthentication no PermitRootLogin no 

是手动validation文件sshd_config的内容的唯一方法,或者我可以探测sshd以确保?

有一个扩展的testing模式,使用命令行选项-T调用,它可以做到这一点。 例如:

 % sudo sshd -T | egrep -i 'allowusers|passwordauth|permitroot' permitrootlogin yes passwordauthentication yes 

自2008年以来,这个选项已经存在于Portable OpenSSH中。 https://github.com/openssh/openssh-portable/commit/e7140f20cb2da1456e6080059eef54cf0f3533f2这是在2008年7月发布的5.1p1中发布的。 http://www.openssh.com/txt/release-5.1所以它几乎存在于今天支持的所有OpenSSH服务器安装中。

虽然这不会转储所有的服务器定义,但可以尝试使用详细的debugging标志连接到服务器: ssh -v user@server 。 这会给你很多的信息,将反映在sshdconfiguration中启用的选项。

例如,用-v开关(密钥签名,域和IP地址故意伪装)看看这个连接的输出:

 OpenSSH_6.0p1, OpenSSL 0.9.8w 23 Apr 2012 debug1: Reading configuration data /home/claudio/.ssh/config debug1: /home/claudio/.ssh/config line 13: Applying options for serv01 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Connecting to somedomain.com [185.113.29.221] port 22. debug1: Connection established. debug1: identity file /home/claudio/.ssh/id_dsa type 2 debug1: identity file /home/claudio/.ssh/id_dsa-cert type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9 debug1: match: OpenSSH_5.9 pat OpenSSH_5* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.0 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: sending SSH2_MSG_KEX_ECDH_INIT debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ECDSA 3a:0d:b8:18:ca:67:4c:54:0f:c8:b2:1e:48:53:69:28 debug1: Host '[somedomain.com]:22' is known and matches the ECDSA host key. debug1: Found key in /home/claudio/.ssh/known_hosts:7 Warning: Permanently added the ECDSA host key for IP address '[185.113.29.221]:22' to the list of known hosts. debug1: ssh_ecdsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: Roaming not allowed by server debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Next authentication method: publickey debug1: Offering DSA public key: /home/claudio/.ssh/id_dsa debug1: Server accepts key: pkalg ssh-dss blen 433 debug1: Authentication succeeded (publickey). Authenticated to somedomain.com ([185.113.29.221]:22). debug1: channel 0: new [client-session] debug1: Requesting [email protected] debug1: Entering interactive session. 

从中你可以看到允许的身份validation方法是:publickey,password,keyboard-interactive。 你也可以看到这个服务器不允许漫游,并且该用户claudio可以使用他的公钥进行连接。

您可以增加指定更多“v”字母的信息输出水平,但是您可能会获得比您想要的更低级的信息。

按照其他答案的build议查看/ etc / ssh / sshd_config文件的问题是,它不一定包含整个configuration。 此文件包含要设置为覆盖默认设置的任何configurationvariables的值,并且作为注释包含作为注释的内置于sshd中的默认值。

如果安装了自定义configuration文件而不是已发布的版本,则忽略了编译为sshd的默认configuration文件,如果是自定义configuration,默认configuration可能与sshd_config中的可见configuration不匹配。

此外,使用-f选项运行sshd以替代configuration文件是完全可能的,因此存储在/ etc / ssh / sshd_config中的那个可能不会反映当前的设置。

这使得这个问题相当有效,据我所知,无法得到肯定的回答。

通常在以下文件中findsshd的configuration: /etc/ssh/sshd_config

要查询运行时configuration,可以使用扩展testing模式sshd -T ,它也允许您testing客户端设置的匹配。

没有已知的方式来查询正在运行的sshd实例的configuration,我想,如果您是指的是openssh服务器。 取决于你想要做什么,你可以使用-t标志来testing一个configuration文件,以确保它在重启服务器之前是有效的,这样你就不会被踢出去,尤其是, 如果您没有任何带外访问服务器。