SUID stands for Set User ID.
In simple words users will get file owner’s permissions as well as owner UID and GID when executing a file/program/command.
Example- 1
When we try to change our password we will use passwd command, which is owned by root. This passwd command file will try to edit some system config files such as /etc/passwd, /etc/shadow etc when we try to change our password. Some of these files cannot be opened or viewed by normal user only root user will have permissions. So if we try to remove SUID and give full permissions to this passwd command file it cannot open other files such as /etc/shadow file to update the changes and we will get permission denied error or some other error when tried to execute passwd command. So passwd command is set with SUID to give root user permissions to normal user so that it can update /etc/shadow and other files.
Example - 2
Similarly if we take ping command, when we have to execute this command internally it should open socket files and open ports in order to send IP packets and receive IP packets to remote server. Normal users don’t have permissions to open socket files and open ports. So SUID bit is set on this file/command so that whoever executes this will get owner (Root user’s) permissions to them when executing this command. So when this command start executing it will inherit root user permissions to this normal user and opens require socket files and ports.
How can I setup SUID for a file?
SUID can be set in two ways
Symbolic way:
chmod u+s file1.txt
chmod 4750 file1.txt
How to Check ?
In simple words users will get file owner’s permissions as well as owner UID and GID when executing a file/program/command.
Example- 1
When we try to change our password we will use passwd command, which is owned by root. This passwd command file will try to edit some system config files such as /etc/passwd, /etc/shadow etc when we try to change our password. Some of these files cannot be opened or viewed by normal user only root user will have permissions. So if we try to remove SUID and give full permissions to this passwd command file it cannot open other files such as /etc/shadow file to update the changes and we will get permission denied error or some other error when tried to execute passwd command. So passwd command is set with SUID to give root user permissions to normal user so that it can update /etc/shadow and other files.
Example - 2
Similarly if we take ping command, when we have to execute this command internally it should open socket files and open ports in order to send IP packets and receive IP packets to remote server. Normal users don’t have permissions to open socket files and open ports. So SUID bit is set on this file/command so that whoever executes this will get owner (Root user’s) permissions to them when executing this command. So when this command start executing it will inherit root user permissions to this normal user and opens require socket files and ports.
How can I setup SUID for a file?
SUID can be set in two ways
1) Symbolic way (s, Stands for Set)
2) Numerical/octal way (4)
Use chmod command to set SUID on file: file1.txt
2) Numerical/octal way (4)
Symbolic way:
chmod u+s file1.txt
chmod 4750 file1.txt
How to Check ?
# ls -l
-rwsr–r– 1 xyz xyzgroup 148 Dec 22 03:46 file1.txt
-rwsr–r– 1 xyz xyzgroup 148 Dec 22 03:46 file1.txt
No comments:
Post a Comment