Most programs in /usr/bin
should have permissions 755 — readable and executable by all, writable only by their owner, which is root. A few programs are setuid or setgid: they have extra privileges, which are confered by the setuid or setgid bit in the permissions. /usr/bin/sudo
is one of them; it needs to be setuid root: chmod 4755 /usr/bin/sudo
restores it.
If you only have official packages from Debian (as opposed to packages in distributions derived from Debian or from other sources), then you can find out which ones contain setuid/setgid binaries by going through the Lintian reports: setuid, setgid, both. In principle, all these packages should come with a file in /usr/share/lintian/overrides
that declares the setxid binary (the tag “overridden” on these pages indicates the presence of such a declaration), but some packages don't comply (including ubiquitous ones such asat
and xserver-xorg
).
The following script prints out a shell script that executes the chmod
command to restore files in /usr/bin
to their default permissions, if their default permissions includes the setuid or setgid bit.
wget -q -O - https://lintian.debian.org/tags/set{uid,gid,uid-gid}-binary.html |
sed -n 's~^.*> *\(usr/bin/[^ ]*\) \([0-7][0-7][0-7][0-7]\).*~[ -e /\1 ] \&\& chmod \2 /\1~p'
In addition, some permissions can be configured locally. These permissions are registered with `dpkg-statoverride. You can list them with
dpkg-statoverride --list '/usr/bin/*'
and you can reapply these permissions with
dpkg-statoverride --list '/usr/bin/*' |
awk 'system("chmod " $3 " " $4)'
If you have packages not from Debian, the only way to be sure to get correct permissions is to reinstall them with apt-get --reinstall install PACKAGE-NAME
.
sudo
) and setgid (needed forlocate
) so those have to be manually fixed. Runningrpm -a --setugids
first might fix this. – rjh Nov 08 '22 at 22:43