In this tutorial, we will explain auxiliary file permissions, commonly referred to as “special permissions” in Linux, and also we will show you how to find files which have SUID (Setuid) and SGID (Setgid) set.
What is SUID and SGID?
SUID is a special file permission for executable files which enables other users to run the file with effective permissions of the file owner. Instead of the normal x
which represents execute permissions, you will see an s
(to indicate SUID) special permission for the user.
SGID is a special file permission that also applies to executable files and enables other users to inherit the effective GID of file group owner. Likewise, rather than the usual x
which represents execute permissions, you will see an s
(to indicate SGID) special permission for group user.
Suggested Read: Managing Users & Groups, File Permissions & Attributes in Linux
Let’s look at how to find files which have SUID and SGID set using the find command.
The syntax is as follows:
$ find directory -perm /permissions
Important: Certain directories (such as /etc, /bin, /sbin etc.) or files require root privileges in order to be accessed or listed, if you are managing your system as a normal user, use the sudo command to gain root privileges.
How to Find Files with SUID Set in Linux
This below example command will find all files with SUID set in the current directory using -perm (print files only with permissions set to 4000) option.
$ find . -perm /4000
You can use the ls command with -l
option (for long listing) to view the permissions on the listed files as shown in the image above.
How to Find Files with SGID Set in Linux
To find files which have SGID set, type the following command.
$ find . -perm /2000
To find files which have both SUID and SGID set, run the command below.
$ find . -perm /6000
You may also like to read these useful guides about file permissions in Linux:
- How to Set File Attributes and Finding Files in Linux
- Translate rwx Permissions into Octal Format in Linux
- Secure Files/Directories using ACLs (Access Control Lists) in Linux
- 5 ‘chattr’ Commands to Make Important Files IMMUTABLE (Unchangeable) in Linux
That’s it for now! In this guide, we showed you how to find files which have SUID (Setuid) and SGID (Setgid) set in Linux. If you have any questions, use the feedback form below to share any queries or additional thoughts about this topic.
The command to find files that have both SUID and SGID set would be with minus sign like so:
and not with a slash sign like you recommend.
Find files with SUID, SGID and StickyBit set in Linux.
Find directories with SUID, SGID and StickyBit set in Linux.
@ROMSTAT
Many thanks for sharing this.
This is incorrect too. From “man find”:
This is no longer supported (and has been deprecated since 2005).
Use
-perm /mode
instead.The correct answer is :
To find files with SUID, SGID and StickyBit set in Linux.
To find directories with SUID, SGID and StickyBit set in Linux.