How I can verify the configuration of sshd
?
For example, I want to make sure that these settings are set and applied:
AllowUsers user1 user2
PasswordAuthentication no
PermitRootLogin no
Is the only way manually verifying the contents of the file sshd_config
, or can I probe sshd
to make sure?
There is an extended test mode, invoked with the command line option
-T
, which does this. For example:The option has existed in Portable OpenSSH since 2008, cf. commit e7140f2. This was released with 5.1p1, made in July 2008, cf. release notes for 5.1, so it exists in pretty much all OpenSSH server installations supported today.
sshd's configuration is typically found in the following file:
/etc/ssh/sshd_config
.To query the runtime configuration, you can use extended test mode
sshd -T
which also allows you to test client matching of settings.While this won't dump all your server definitions, you can try connecting to the server with a verbose debug flag:
ssh -v user@server
. That will give you a lot of information that will reflect the options enabled in sshd configuration.For example, take a look on the output of this connection with the -v switch (key signatures, domain and IP addresses purposely disguised):
From that you can see the allowed authentication methods are: publickey,password,keyboard-interactive. You can also see that roaming is not allowed by this server, and that user claudio could connect using his public key.
You can increase the level of information output specifying more "v" letters, but then you may get way more low level information than you probably want.
The problem with looking at the /etc/ssh/sshd_config file as suggested by other answers is that it does not necessarily contain the whole configuration. This file contains the values of any configuration variables you want to set to over-ride the defaults, and as shipped contains as comments the defaults that are built in to sshd.
If a custom configuration file is installed in place of the shipped version, you lose sight of the defaults that are compiled in to sshd, and if it is a custom build, the defaults may not match the comments in the sshd_config that are visible.
Additionally, it is perfectly possible to run sshd with an alternate config file with the -f option, so the one stored in /etc/ssh/sshd_config may not reflect the current settings.
This makes the question quite valid, and as far as I know, unable to be answered with any certainty.
there is no known way of querying the config of a running sshd instance, i think, if you are referring the openssh server. depending on what you want to do, you could use the -t flag to test a configuration file to make sure that it is valid before restarting the server, so that you don't get kicked out, esp. if you do not have any out-of-band access to the server.