First, Set_uid
Set_uid is actually a special permission, we look at a file:
[Email protected] ~]# ls-l/usr/bin/passwd127832 /usr/bin/ passwd
The X-Permission bit of its owner was replaced by S. So what does this s mean? It represents the normal user who executes this command and can temporarily have the identity of the command owner.
As an example, we can change the password by passwd command. Let's take a look at the files stored in the password:
[Email protected] ~]# ls-l/etc/shadow1941 /etc/shadow
We found that this file has a permission of 000, then the average user how to change it? That's the S permission. The normal user has a temporary root identity when executing this command.
Similarly, we know that ordinary users are not allowed to go to the root user's home directory. Well, if we give the LS command set_uid, it should be possible.
[Email protected] ~]# ls-l/usr/bin/ls-rwxr-xr-x.1Root root117616JuneTen the/usr/bin/Ls[[email protected]~]# chmod u+s/usr/bin/Ls[[email protected]~]# !Lsls-l/usr/bin/ls-rwsr-xr-x.1Root root117616JuneTen the/usr/bin/Ls[[email protected]~]# su ruanwenwu[[email protected] root]$ ls/Root1 1. IPT5Application Document.pdf npm-debug.log Ruanwenwu syncwithgit.sh1. cap2a.php a.txt Iptables.bak Oneinstack shellscripts
Second, Set_gid
Set_gid role in the file when the meaning and set_uid basically the same, only the ordinary user when executing it is the identity of the group that the file belongs to.
When Set_gid is acting on a directory, the group name of the new file and directory under the directory will be consistent with that directory:
[Email protected] ~]# Chown:ruanwenwu1[[Email protected]~]# Ls-ld1DRW-rwsrw-4Ruanwenwu Ruanwenwu4096Oct - xx: A 1[[Email protected]~]# Touch1/1. Txt[[email protected]~]# ls-l1 Total A-rw-r--r--1Root Ruanwenwu0Oct - A: - 1. TXTDRWXR-xr-x3Ruanwenwu Ruanwenwu4096Oct - xx: on 4DRWXRWXR--2Root root4096Oct - xx: A 5-rw-rw-r--1Root root2Oct - xx: - 5. Txt[[email protected]~]#
After discovering that Set_gid was set up, the newly created 1.txt owned group in the 1 directory became RUANWENWU.
Third, Stick_bit
Anti-delete bit. Its role is: My files you can not delete. But you can modify it. The/tmp/directory has this anti-delete bit, where other users can execute the permission bit.
[Email protected] ~]# ls-ld/8454656:
Now we use RUANWENWU This user to create a file, and then switch to the test user to see if it can be deleted.
[email protected] tmp]$ LS-L Ruanwenwu.txt-rw-rw-r--1Ruanwenwu Ruanwenwu0Oct - A: ARuanwenwu.txt[[email protected] tmp]$ passwd testpasswd:only root can specify a user name. [email protected] tmp]$ su rootpassword: [[email protected] tmp]# passwd testchanging password foruser test. New Password:bad password:the Password isShorter than8CharactersretypeNewPassword:passwd:all authentication Tokens updated successfully. [email protected] tmp]# su test[[email protected] tmp]$ RM-RF ruanwenwu.txt rm:cannot Remove ' ruanwenwu.txt ': Operation not permitted
Found cannot be deleted, now we delete/tmp/stick_bit, and then try again:
[Email protected] tmp]$ chmod o-t/tmpchmod:changing permissions of '/tmp ': Operation not permitted[[email protected] tmp]$ su rootpassword: [[email protected] tmp]# chmod o-t/tmp/[[email protected] tmp]# ls-LD/tmpdrwxrwxrwx.8www www454656Oct - A: $/tmp[[email protected] tmp]# su test[[email protected] tmp]$ RM-RF Ruanwenwu.txt [[email protected] tmp]$ ls Aegis-<guid (5a2c30a2-a87d-490a-9281-6765EDAD7CBA) >iZ25lzba47vZ.root.history-timestampiZ25lzba47vZ.ruanwenwu.history-timestampiZ25lzba47vZ.test.history-timestampmysql.socksystemd-Private-39567547dfdf4a37b00906a534c87627-ntpd.service-qxsgfm
After removing the anti-delete bit, the test user can delete the Ruanwenwu file.
Four, soft connection
Soft links are equivalent to shortcuts in Windows. How he is generated:
[[email protected] tmp]# ln-s/tmp/a.txt/-L/1ten:55 /ccc.txt-/tmp/a.txt
The soft connection is characterized by a small footprint. When creating a soft connection, use absolute paths whenever possible, so that when you move a soft connection, the link is not invalidated.
Five, hard links
Hard links and original files occupy the same inode address:
[[email protected] tmp]# ln a.txt c.txt[[email protected] tmp]# ls-L./ Total theSRWXR-xr-x1Root root0Oct - xx: ,Aegis-<guid (5a2c30a2-a87d-490a-9281-6765EDAD7CBA) >-rw-rw-r--2Test test0Oct - A: thea.txtlrwxrwxrwx1Test test5Oct - A: WuB.txta.txt-rw-rw-r--2Test test0Oct - A: theC.txt-rw-r--r--1Root root52645Oct - A: -iz25lzba47vz.root.history-timestamp-rw-rw-r--1Ruanwenwu Ruanwenwu5616Oct - A: theiz25lzba47vz.ruanwenwu.history-timestamp-rw-rw-r--1Test test2110Oct - A: -iz25lzba47vz.test.history-timestampsrwxrwxrwx1MySQL MySQL0Oct - -: OneMysql.sock-RW-------1www www0Oct - A: -sess_vi5k84ucsecldno3kg6edqdh72drwx------3www www4096May5 .systemd-Private-39567547dfdf4a37b00906a534c87627-ntpd.service-qxsgfm[[email protected] tmp]# ls-I./268133Aegis-<guid (5a2c30a2-a87d-490a-9281-6765EDAD7CBA) >267465a.txt271484B.txt267465C.txt271661iz25lzba47vz.root.history-timestamp272224iz25lzba47vz.ruanwenwu.history-timestamp271368iz25lzba47vz.test.history-timestamp271787Mysql.sock271481sess_vi5k84ucsecldno3kg6edqdh721052102systemd-Private-39567547dfdf4a37b00906a534c87627-ntpd.service-qxsgfm[[email protected] tmp]# ls-I a.txt c.txt267465A.txt267465C.txt
If we delete one of the files, will the other file be affected?
[Email protected] tmp]# RM-- 10: c.txt
Found, and did not affect another file.
The directory is not hard to link, because the directory has its own inode system.
Hard links cannot span partitions because each partition has its own inode system.
Linux Learning (ix) Set_uid, Set_gid, stick_bit, soft links, hard links