Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set file permissions in Linux system

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to set file permissions in the Linux system, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

In Linux, each file has specific properties. It mainly includes two aspects: file type and file permission. It can be divided into five different types: normal files, directory files, linked files, device files, and pipe files.

Step 1 check the system core

First check whether the core of your Linux system supports ACL. Because the core of every version of Linux system does not have the function of supporting ACL, the easiest way is to check whether the current core of the system can support it:

[root@mail /] # cat / boot/config-kernel-version | grep-I ext3

CONFIG_EXT3_FS=m

CONFIG_EXT3_IDEX=y

CONFIG_EXT3_FS_XATTR_SHARING=y

CONFIG_EXT3_FS_XATTR_USER=y

CONFIG_EXT3_FS_XATTR_TRUSTED=y

CONFIG_EXT3_FS_ACL=y

At this point, if you can see the above items, it means that the ext3 file system has been compiled into the core, and the ext3 file system supports the ACL function, which can be found in the compilation core options. If you can't find it at compile time, you can go to ACL's official website to install Kernel (acl.bestbits.at/).

Step 2 Mount the partition

You can mount the partition and enable ACL in the following ways:

# mount-t ext3-o acl / dev/sda1 / fs1

You can also write it directly in the / etc/fstab file so that you can support ACL after you turn it on:

# vi / etc/fstab

Step 3 set ACL permissions

ACL is often set up for individual users. Here are several different examples:

For example, if you need to create three users: test1, test2 and test3, you can log in to the system with the identity of root, and then execute the following command to create three usernames and passwords respectively:

[root@mail root] # adduser test1

[root@mail root] # adduser test2

[root@mail root] # adduser test3

[root@mail root] # passwd test1

[root@mail root] # passwd test2

[root@mail root] # passwd test3

Then mount an ext3 file to the directory / fs1:

[root@mail root] # mount-t ext3-o acl / dev/sda1 / fs1

Then set the read and write permissions of the file established by test1 to test2:

[root@mail root] # chmod-R 777 / fs1

Allows all users to increase the permissions of files to the directory:

Log in to the system with test1 and execute the command:

[test1@mail test1] # cd / fs1

[test1@mail fs1] # echo "Create by test1" > test1.txt

[test1@mail fs1] # chmod go-r test1.txt

[test1@mail fs1] # ll test1.txt

-rw- 1 test1 test1 17 Jul 14 22:11 test1.txt

Do the following so that anyone except test1 has read and write permission to test1.txt (except root). Log in to the system with test2 first and execute the following command:

[test2@mail test2] # cd / fs1

[test2@mail fs1] # cat test1.txt

Cat: test1.txt Permission denied

Then log in to the system with test1 and execute the following command:

[test1@mail fs1] # setfacl-m u:test2:rw test1.txt

This modifies permissions to allow test2 to read and write to this file. Take another look at the changes in its file properties:

[test1@mail fs1] # ll

-rw-rw-r--+ 1 test1 test1 10 Feb 16 13:52 test1.txt

You will see the addition of a "+" to indicate that the file uses the property settings of ACL, and then use the command getfacl to see the file property settings of ACL:

[test1@mail fs1] # getfacl test1.txt

# file: test1.txt

# owner: test1

# group: test1

User::rw-

User:test2:rw-

Group::rw-

Mask::rw-

Other::r--

You can see that test2 has permission to read and write to this file.

Let's log in to the system with test2 and execute the following command to see what happens.

[test2@mail test2] # cd / fs1

[test2@mail fs1] # cat test1.txt

Create by test1

It turns out that test2 can read test1.txt files.

[test2@mail fs1] # echo "Modify by test2" > > test1.txt

[test2@mail fs1] # cat test1.txt

Create by test1

Modify by test2

Now test2 can also modify the test1.txt file.

Then log in to the system with test3:

[test3@mail test3] # cd / fs1

[test3@mail fs1] # cat test1.txt

Cat: test1.txt Permission denied

The above is how to set file permissions in the Linux system, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report