Here are a few ways to make /usr/bin/ssh (and its friends, e.g. scp, sftp) executable only by root on Ubuntu. Pick the one that best fits your environment:
Change traditional UNIX permissions
This is the simplest approach—just remove “execute” bits for group & others and leave only root able to run it:
bash
# verify current perms
ls -l /usr/bin/ssh # e.g. -rwxr-xr-x
# restrict to root only
sudo chmod 700 /usr/bin/ssh
sudo chmod 700 /usr/bin/scp /usr/bin/sftp # if desired
After that, only the file’s owner (root) can execute it. Any normal user will see “Permission denied.”
Use POSIX ACLs for finer control
If you want to forbid specific users (or an entire group) but leave SSH runnable by root—and perhaps one or two other service accounts—ACLs give you that flexibility without touching the global bits:
bash
# remove everyone else’s execute
sudo setfacl -m o:--- /usr/bin/ssh
# explicitly allow root (redundant—root always wins—but shows intent)
sudo setfacl -m u:root:rwx /usr/bin/ssh
# to deny just alice and bob
sudo setfacl -m u:alice:--- /usr/bin/ssh
sudo setfacl -m u:bob:--- /usr/bin/ssh
Check the ACLs afterward with
bash
getfacl /usr/bin/ssh
Wrapper‐script shim
If you need a bit more logic—say, you only want to allow root and one special service account—you can rename the real binary and put a tiny shell wrapper in its place:
bash
sudo mv /usr/bin/ssh /usr/bin/ssh.real
sudo tee /usr/bin/ssh << 'EOF'
#!/bin/sh
if [ "$(id -u)" -ne 0 ]; then
echo "Only root may run ssh" >&2
exit 1
fi
exec /usr/bin/ssh.real "$@"
EOF
sudo chmod 755 /usr/bin/ssh
sudo chmod 700 /usr/bin/ssh.real
Now any non‐root invoking ssh will get your custom error.
Important caveats
• A savvy user could recompile or install their own SSH client in ~/bin unless you also remove it from their PATH or lock down compilation tools.
• You might also want to do the same for scp, sftp, ssh-keygen, etc., depending on how strict you must be.
• Changes to system binaries may be overwritten by package updates—consider using dpkg-divert or an APT hook if you need the lockdown to survive upgrades.
Pick the method that matches your security policy. Let me know if you need help bundling this into a configuration-management tool or if you want to lock down other SSH‐related commands! 🚀