How do you apply different sshd rules for different users or networks?
IntermediateProductionSSH & Access Hardening
Answer
Use Match blocks at the end of the config:
Match Group sftp-only
ChrootDirectory /srv/sftp/%u
ForceCommand internal-sftp
AllowTcpForwarding no
Match Address 10.0.0.0/8
PasswordAuthentication no
The chroot directory must be owned by root and not group/other-writable. Test a user's effective settings with sudo sshd -T -C user=bob,host=x,addr=10.1.2.3.
More on SSH & Access Hardening
What are the first sshd_config changes you make on a new production server?BeginnerWhy use a drop-in file in /etc/ssh/sshd_config.d/ instead of editing sshd_config?IntermediateWhy disable SSH password authentication entirely?BeginnerShould you change the SSH port from 22?IntermediateWhat are SSH certificates and why do large fleets use them?AdvancedHow do you restrict what a specific SSH key can do?Advanced