Why not log in as root at all
Working as root deprives the system of two things at once: a trace and a boundary. A trace, because the log shows that root ran the command but not who that was; a boundary, because a typo in a path executes with full rights. sudo solves both: every action is attributed to a person, and the list of what is allowed is limited.
This is not a formality for large teams. Even with a single administrator, a log listing the commands that ran is the only source of an answer to "what changed before it broke".
The right order of steps
A user, a key, group membership, and only then the ban on root login:
adduser --disabled-password --gecos "" deploy
install -d -m 700 -o deploy -g deploy /home/deploy/.ssh
cp /root/.ssh/authorized_keys /home/deploy/.ssh/authorized_keys
chown deploy:deploy /home/deploy/.ssh/authorized_keys
chmod 600 /home/deploy/.ssh/authorized_keys
usermod -aG sudo deployThe check is mandatory before the ban: open a second connection and log in as the new user. Ban root login first and then discover a mistake in the key, and access to the server is lost entirely — you will be restoring it through the provider's console.
How to write sudoers without holes
Edit the rules only through visudo: it checks the syntax before saving. A broken sudoers means sudo stops working for everyone, you included.
visudo -f /etc/sudoers.d/deploy
# contents:
deploy ALL=(root) /usr/bin/systemctl restart nginx, /usr/bin/systemctl reload nginx
deploy ALL=(root) NOPASSWD: /usr/bin/systemctl status nginxFiles in /etc/sudoers.d/ are better than the main one: they are not lost when the package is upgraded. The whole set can be checked like this:
visudo -c
sudo -l -U deployThe second command shows what the user is actually allowed to do — not what you believe you allowed.
Four entries that hand over root
These wordings look like a restriction but are not one:
| Entry | Why this is full root |
|---|---|
NOPASSWD: ALL | Any command without a password: a stolen key is root at once |
/usr/bin/vim | A shell starts from the editor with :!sh |
/bin/chmod * | The pattern accepts any path, system files included |
/usr/bin/find | It can run commands through -exec |
The general rule: you may allow a command with fixed arguments, not a program able to launch other programs. For editing files there is sudoedit — it opens a copy as your own user and puts it back, without granting the editor root.
The 2025 flaws: you need 1.9.17p1 or later
In June 2025 two sudo vulnerabilities were published, and both are closed in release 1.9.17p1. The first, CVE-2025-32463, allowed root because when the --chroot option was used, /etc/nsswitch.conf was read from a user-controlled directory; no sudo rules were needed for the user at all. The second, CVE-2025-32462, concerned the -h option and applied where sudoers names a host that is neither the current one nor ALL.
The scores deserve a separate word, because the numbers in articles disagree, and the disagreement is not a retelling error: each NVD entry carries two CVSS 3.1 scores from different parties. For the chroot flaw it is 9.3 from MITRE and 7.8 from NVD; for the host flaw, 2.8 from MITRE and 8.8 from NVD. The spread in the second pair is particularly wide, so steer by the fact rather than the score: upgrade.
sudo --version | head -1
apt policy sudo 2>/dev/null | head -3The current stable release of the 1.9 branch is 1.9.17p2. The package number in a distribution is usually different: the fix arrives as a backport, and a version like 1.9.16 with a build suffix may already carry the patch. Compare against your distribution's advisory, not only against the number. The --chroot feature itself was marked deprecated after these fixes — better not to use it in new configurations.
The log: who ran what
By default sudo records the fact that a command ran. That is enough for an investigation, provided the log is not overwritten and somebody reads it:
grep -h sudo /var/log/auth.log | tail -20
journalctl _COMM=sudo --since "-7d" | tail -20For sensitive hosts, session input and output recording is added through Defaults log_output, but remember that such a log will also capture passwords typed for other services, so the permissions on the recording directory must be closed.
What sits next to this
sudo limits rights inside the system, while getting into it is closed off by other measures: SSH hardening and Linux file permissions. If you need a stricter separation than a list of commands, that is mandatory access control: configuring SELinux and AppArmor.