ssh connection refused despite PermitRootLogin yes

In /etc/ssh/sshd_config I changed and added the following:

PermitRootLogin no
Match Address 192.168.0.*
    PermitRootLogin yes

When I try to connect via ssh, however, I get Connection refused.

I know that its those lines affecting it because if I remove them and just leave it as

PermitRootLogin yes

I can connect just fine. What's going on here? It seems that SSH is ignoring the Match block.


Connection refused indicates that something at the TCP/IP layer (e.g. L3) stopped you, not that the sshd daemon denied your login.

This is probably due to a firewall or similar somewhere in the path. As long as you get Connection refused the authentication settings are irrelevant; there's no communication between the ssh server and client at that stage.


As pointed out by @vidarlo, Connection refused indicates an issue at the TCP/IP layer; there is no communication between the server and the client occuring, regardless of the settings in the config file, so this indicates a separate problem.

Using sshd -T as pointed out by @Mrwut, it was found that there was an error in the sshd_config file. The error was that a Match block has to go at the end of the sshd_config file, and not in the middle of it. This is because a Match block cannot be manually terminated, so if something is stated after the Match block that cannot be in a Match block, it will throw an error causing the SSH server to be unable to start.

Since the SSH server could not start, a connection to the server could not be established, and thus Connection refused.