Bo2SS

Bo2SS

Common Scenarios for Special File Permissions

Experimental Environment: Ubuntu 18.04 Remote Server + WSL 2 Local Machine

Evaluation Instructions#

[Version One]

  • Image

[Version Two]

  • Image
  • ⭐ Assess understanding of file permissions, especially special file permissions

  • Once the above is understood, implementing the above functions will be effortless.

Final Effect#

  • Other users cannot enter the Project directory

  • Image
  • TestUser1 created the file u1.txt

  • Image
  • TestUser2 can still edit u1.txt but cannot delete it

  • Image
    • Conversely, the same applies.

Implementation Process#

Preparation Work#

  • Create a new user group TestGroup using the groupadd command; there are some options to check the man manual.
groupadd TestGroup
  • Create two users TestUser1 and TestUser2 belonging to the TestGroup group.
useradd -G TestGroup TestUser1
useradd -G TestGroup TestUser2
    • The group must exist first.
  • Set passwords for login; otherwise, you cannot log in.
passwd TestUser1
---> Enter password: xxx
passwd TestUser2
---> Enter password: yyy
  • Create a Project directory under /opt as the project directory.
cd /opt
mkdir Project

Implement Function 1: Access Permissions#

[Only TestUser1, TestUser2, and root can enter this directory.]

  • Change the group ownership of the Project directory to TestGroup, leaving the user unchanged.
sudo chown :TestGroup Project
  • Remove execute permissions for other users; other users will not be able to enter the directory.
sudo chmod o-x Project
  • The effect is as follows:

  • Image

Implement Function 2: Edit Permissions#

[TestUser1's created files can be edited by TestUser2.]

  • First, add write permissions for the group TestGroup so that users can create files in this directory.
sudo chmod g+w Project
  • Set set_gid, so that operations performed by users entering the directory will be done as the group of the directory.
sudo chmod g+s Project

[PS] Otherwise, the group ownership of the files created by users will belong to the group with the same name as themselves, rather than TestGroup [thus failing to establish a connection between the two users].

  • Permissions are as follows:

  • Image

Implement Function 3: Delete Permissions#

[TestUser1 and TestUser2 can only delete files they created.]

  • Set the sticky bit, so that in this directory, users can only delete content they created.
sudo chmod +t Project
  • Permissions are as follows:

  • Image

[PS] The folder colors have all changed, zsh did a great job.


Points to Consider#

  • In a certain scenario: A user entering a directory does not have write permissions for a certain file but can delete the file. Why?

Additional#

  • The executable permission of a directory represents the permission to enter.

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.