To find SUID files on Linux you need one find command, and three more cover SGID files, world-writable files and files that belong to nobody. These are the permission mistakes that let an attacker who got in as a low-privilege user become root, so the list is worth reading on every server you run. This guide shows the commands, what a normal result looks like on Ubuntu 24.04 and what to change.

All commands were run in our lab on Ubuntu 24.04 in November 2026. Outputs are real. Where we planted a bad file to show the result, we say so.

The short answer

sudo find / -xdev -perm -4000 -type f 2>/dev/null
sudo find / -xdev -perm -2000 -type f 2>/dev/null
sudo find /etc /srv /opt /home /var/www -xdev -type f -perm -0002 2>/dev/null
sudo find / -xdev \( -nouser -o -nogroup \) 2>/dev/null

-xdev keeps find on one filesystem, so it does not wander into /proc or network mounts. Run it once for each mounted disk.

What SUID means

A program with the SUID bit runs with the rights of the file’s owner, whoever starts it. passwd is the usual example: any user can run it, and it has to write to a file only root may change. In a listing the bit shows as an s where the owner’s x would be:

ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 64152 May 30  2024 /usr/bin/passwd

SGID is the same idea for the group. A SUID program owned by root is safe only as long as it does exactly one narrow job. A shell, an editor or a scripting language with that bit gives root to every user on the machine.

Find SUID files and compare with normal

sudo find / -xdev -perm -4000 -type f 2>/dev/null

On our minimal Ubuntu 24.04 lab system this printed 12 files:

/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/polkit-1/polkit-agent-helper-1
/usr/bin/chfn
/usr/bin/chsh
/usr/bin/mount
/usr/bin/passwd
/usr/bin/fusermount3
/usr/bin/sudo
/usr/bin/gpasswd
/usr/bin/newgrp
/usr/bin/su
/usr/bin/umount

A full server install has a few more, such as pkexec and the OpenSSH key-sign helper. All of them sit under /usr. That gives a quick test: list SUID files that are anywhere else.

sudo find / -xdev -perm -4000 -type f ! -path '/usr/*' ! -path '/bin/*' ! -path '/sbin/*' 2>/dev/null
/tmp/.cache-helper

We planted that file for the test. It is a copy of bash with the SUID bit set, hidden with a leading dot in /tmp. An attacker who once had root leaves something like it behind to get root back later. Then ask the package manager who owns each file:

dpkg -S /usr/bin/passwd
dpkg -S /tmp/.cache-helper
passwd: /usr/bin/passwd
dpkg-query: no path found matching pattern /tmp/.cache-helper

A SUID file that no package owns needs an explanation today. On Red Hat family systems use rpm -qf.

For files that do belong to packages, check the name against GTFOBins, a public list of standard programs that can be misused when they carry SUID. If find, vim, python, nmap or cp shows up with the bit set, somebody added it by hand.

Remove a SUID bit you do not need

sudo chmod u-s /path/to/file

Do this for programs nobody on the server uses, for example chfn and chsh on a server with no interactive users. Do not strip the bit from sudo, su or passwd. Package updates can set the bit again, so repeat the check after upgrades.

World-writable files

A world-writable file can be changed by every user and every compromised service on the machine.

sudo find /etc /srv /opt /home /var/www -xdev -type f -perm -0002 2>/dev/null
/srv/app/config.php

That is our planted example: a web application config file set to mode 666, which is what “chmod 777 until it works” leaves behind. Any process on the server could add a line to it. Fix it by removing write access for others, and tighten further if the file holds passwords:

sudo chmod o-w /srv/app/config.php
sudo chmod 640 /srv/app/config.php

World-writable directories are normal in a few places, such as /tmp, and there they carry the sticky bit so users cannot delete each other’s files. Look for the ones without it:

sudo find / -xdev -type d -perm -0002 ! -perm -1000 2>/dev/null
/srv/app/uploads

An upload directory at mode 777 lets any local user replace files that the website then serves. Give it to the web server’s user and close it to everyone else:

sudo chown www-data:www-data /srv/app/uploads
sudo chmod 750 /srv/app/uploads

Files that belong to nobody

sudo find / -xdev \( -nouser -o -nogroup \) 2>/dev/null
/srv/app/old.tar

These files carry a user or group ID that no longer exists, usually after an account was deleted or an archive was unpacked as root. The next account created with that ID becomes their owner. Assign them to the right user with chown, or remove them.

Capabilities, the quieter cousin of SUID

File capabilities give a program one slice of root’s power without the SUID bit, so the commands above do not show them.

sudo getcap -r / 2>/dev/null
/usr/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0/gst-ptp-helper cap_net_bind_service,cap_net_admin,cap_sys_nice=ep

Entries such as cap_net_bind_service on a web server are normal. cap_setuid or cap_dac_override on an interpreter such as Python or Perl is as dangerous as SUID root.

Keep a baseline

The first run tells you what is there. The value comes from the second run, when you can see what changed.

sudo find / -xdev \( -perm -4000 -o -perm -2000 \) -type f 2>/dev/null | sort > suid-baseline.txt

Store the file off the server and compare with diff after every change window, or let a file integrity tool do it. Mounting /tmp, /dev/shm and upload directories with the nosuid option stops SUID files there from working at all. That option is from the mount documentation and was not tested in our lab container.

SSH Hardening Pack, ₹99: tested sshd_config drop-ins, a fail2ban jail, a guided install script that refuses to lock you out, a verify script and a printable checklist. See the pack.

Related guides

Sources

Want a full permission and configuration review? Our Linux server hardening audit reviews accounts, permissions, services and SSH settings on your servers. The free website safety check grades your site from the outside in 30 seconds. Contact us for a quote.

Post author avatar

Bhaskar Soni

Bhaskar Soni is a Security Engineer and the founder of Youngster Company, based in Ahmedabad, Gujarat. He works hands-on with Linux server hardening, vulnerability assessment and penetration testing (VAPT), ISO 27001 compliance and OSINT investigations. He writes practical, tested guides for IT professionals and Indian businesses, and every article on this site is written or reviewed by him.

Leave a Reply