• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Linux / UNIX : How to find files which has SUID/SGID set

by admin

Special Permissions – SUID/SGID

There are two special permissions that can be set on executable files: Set User ID (setuid) and Set Group ID (sgid). These permissions allow the file being executed to be executed with the privileges of the owner or the group. For example, if a file was owned by the root user and has the setuid bit set, no matter who executed the file it would always run with root user privileges.

Finding files with SUID/SGID bit set

We can find all the files with SUID SGID permissions using the find command.

1. To find all files with SUID permissions under root :

# find / -perm +4000

2. To find all files with SGID permissions under root :

# find / -perm +2000

3. we can also combine both find commands in a single find command:

# find / -type f \( -perm -4000 -o -perm -2000 \) -exec ls -l {} \;

Removing SUID/SGID

If you want to remove the SGID and SUID permissions on the files, you can follow the steps below. Once you get the list of files, you remove the security bit using chmod command :
For SUID :

# chmod u-s file_name

For SGID :

# chmod g-s file_name

To recursively do it you can execute the following command :

# for i in `find / -perm +4000`
do
	chmod u-s $i
done

Similarly you can change for sgid files also.

# for i in `find / -perm +2000`
do
	chmod g-s $i
done
Note: It will remove all suid of the files. So be cautious before executing the for loop.
What is SUID, SGID and Sticky bit ?
Linux / UNIX : Examples of find command to find files with specific sets of permissions
UNIX / Linux : What is the correct permission of /tmp and /var/tmp directories

Filed Under: Linux

Some more articles you might also be interested in …

  1. kwriteconfig5: command not found
  2. How to uninstall fail2ban on Ubuntu
  3. xargs: command not found
  4. Sample /etc/services file in Linux
  5. hcitool: command not found
  6. How to use ipset Command in Linux
  7. ORA-01031: insufficient privileges when creating a materialized view
  8. nsxiv Command Examples
  9. How to change the NIC device name in CentOS / RHEL 6
  10. dnf: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright