How to intentionally cause ssh root connection refused

Solution 1:

You can't do that.

Your server has no way of knowing what user the remote connection will try to login as, until after it has already connected!

You should consider using fail2ban to block repeated abusers.

Solution 2:

You can disable root login via ssh by editing /etc/ssh/sshd.conf

Always backup config files before making changes.

sudo cp /etc/ssh/sshd.conf /etc/ssh/sshd.conf.backup

Use whatever editor you like such as nano or vi and edit /etc/ssh/sshd.conf

Find, or add, the following lines;

AllowUsers someuser some_other_user
PermitRootLogin no

Save the file and restart your ssh server.

sudo systemctl restart sshd.service

You can still perform root activities using sudo and you can also switch to the root using by typing su root

Bonus Tip:

While you have the config file open take a moment to examine its contents. You might also find other useful settings. Before changing anything google what it does otherwise you risk locking yourself out.