brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: AllowUsers in sshd_config means only the accounts you name can log in over SSH

Network and access
~/tips/tip-ssh-allowusers-sshd-config

AllowUsers alice [email protected]/24

Limits SSH logins to a short list of user names, optionally from specific addresses.

Most servers have far more accounts than people who should log in over SSH. Service accounts, old users, things a package created. I’d rather name the few that may log in.

# /etc/ssh/sshd_config
AllowUsers alice [email protected]/24

The sshd_config man page says it takes a list of user name patterns separated by spaces, and when it is set, only matching users can log in. The USER@HOST form checks the user and the host separately, and the host can be a CIDR range. So here alice can log in from anywhere and deploy only from the LAN.

AllowGroups does the same for group names, which is easier to manage when several people need access: put them in an ssh-users group and allow that group.

Before you reload, test the config:

sudo sshd -t
sudo sshd -T | grep -i allowusers

-t only checks that the file is valid. -T also prints the effective configuration, so you see what sshd will really use.

Caveats. Keep your current session open and test a new login before you close it, or a typo locks you out. The man page says AllowUsers is not consulted for users already matched by DenyUsers, so a deny wins. Only names work, not numeric user IDs. And USER@HOST patterns can make sshd do DNS lookups, so I’d stick to IP ranges.

Further reading: sshd_config manual, sshd manual: -t and -T, On this site: ssh-audit lists the weak algorithms your server offers

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link