How to limit the access rights of Linux users

  

If you do not want your files to be read, or just do not want a particular user to read the modified files, limiting access is the best way to deal with them. Let me introduce you to the method of restricting user access rights under Linux. Let's learn together.

now we need to limit a user's access to certain directories /files, or to limit a user's access to the range in a directory /file. In reality, you can still meet such requirements. For example, there are multiple login users under ubuntu. By default, user A's working directory (usually /home/A) is available to any other user. Read, but User A may not want other users (or a specific user) to read A's files.

Three solutions are proposed here.

First: Use chmod to change permissions for a specific directory. This can limit the access of certain directories to certain people. The purpose of limiting a user can also be achieved, but other users will be accidentally injured.

Second: use a linux container, such as lxc. It takes a lot of space and the setup is a bit cumbersome.

Third: Use the setfacl command to set access control.

Among them, the third option is the most satisfactory. This article focuses on the specific implementation of the program and tests it on my own. My system is Linux Mint 15 64 bit, the root directory /uses the ext4 file system, the btrfs file system used by /home.

Install acl

The code is as follows:

sudo apt-get install acl

There is information to restart the system, but I found this when testing. It has been installed before (I don't know if it is brought by Mint or I am arbitrarily installed), and no restart is still effective.

Use setfacl

to execute the following command as root:

The code is as follows:

# mkdir /home/test

# touch /home/test/foo.txt

# vim /home/test/foo.txt

# ls -ld /home/test/

drwxr-xr -x 1 root root 14 Jan 16 09:46 /home/test/

# ls -ld /home/test/foo.txt

-rw-r--r-- 1 Root root 6 Jan 16 09:46 /home/test/foo.txt

The above command creates the directory test in the /home directory, creates the file foo.txt in the test directory, and under foo.txt Feel free to add some content. Then access foo.txt as a normal user letian, you can read foo.txt.
Previous12Next Total 2 Pages

Copyright © Windows knowledge All Rights Reserved