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

Example Analysis of File permissions in Linux

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Xiaobian to share with you the example analysis of file permissions in Linux, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

Linux's beauty lies in its multi-user, multi-tasking system. Linux generally divides file access identities into three categories: owner, group, and others, and each of the three identities has read, write, and execute permissions.

The three identities of authority

File owner (owner)

User-level file permissions, usually the creator of the file, can change the file owner through chown.

User group (group)

If you think of a user group as a team, the user is a member, and all members of the team have the same permissions on the file. User groups that can modify files via chgrp.

One of the most useful features of user groups is when teams are developing resources. Project1 and project2 are developed by two teams, and then user group permissions 1 and 2 are assigned to the projects respectively, and then the supervisor supports permissions 1 and 2 at the same time, that is, each account can be supported by multiple user groups.

Others (others)

Either the owner of the file and the user group that does not belong to the file, or someone else.

file permissions

Define and view

Execute the following command in the server to view information about the file:

[root@iz2zedcscvry6t0psspzswz ~]# ls -altotal 44dr-xr-x---. 5 root root 4096 Sep 9 12:11 .dr-xr-xr-x. 18 root root 4096 Sep 9 12:39 ..- rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrcdrwx------ 3 root root 4096 Oct 15 2017 .cache-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrcdrwxr-xr-x 2 root root 4096 Oct 15 2017 .pip-rw-r--r-- 1 root root 64 Oct 15 2017 .pydistutils.cfgdrwx------ 2 root root 4096 Sep 9 12:11 .ssh-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc

The following example shows what each column means:

File permissions Number of connections File owner User group File size Modification date File name

drwxr-xr-x 2 root root 4096 Oct 15 2017 .pip

In the file permissions section, drwxr-xr-x, the first letter represents the file type, where d represents the directory. d = directory, - = file, l = linkfile.

The following three are grouped together, the first group rwx represents the file owner permissions, the second group r-x represents the user group permissions, and the third group r-x represents other user permissions.

In the example file, the file owner root has read and write executable permissions, users in the root group have read and executable permissions, and other users have read and executable permissions.

View specific dates of file creation or modification: ls -al --full-time

See detailed usage of ls: man ls or info ls

Modify file permissions

chgrp(change group): Change the user group to which a file belongs

chown(change owner): Change the owner of a file

chmod(change mod): permission to modify files

Modify user groups

chgrp [-R] dirname/filename#Change user group for install.log to userschgrp users install.log

Modify File Owner

chown can also modify the user group to which the file belongs

chown [-R] Account name: group name File or directory #Change user group and owner of install.log to rootchown root:root install.log

changing file permissions

Weight distribution: r:4 w:2 r:1

#Set file permissions to-rwxr-xrchmod 754 filename#Set an executable file so that no one else can modify chmod 755 filename # -rwxr-xr-x

Symbol Type Change File Permission

command identity operation file

chmodu g o a+(add)-(remove)=(set) r w x file or directory

Identity: u = user, g = group,o = other, a = all

#Let file have execute permissions, but do not know the original permissions chmod a+x filename

The meaning of permissions for directories and files

Whether a Linux file is executed is determined by the permissions of the "x" and has no absolute relationship to the file name.

The file is where the actual data is stored, and the main content of the directory is to record the list of file names.

File permissions explained

r: Can read file content

w: File content can be edited

x: File has permissions to be executed by the system

Permission explanation for directory

r: Query the file name data under this directory (can use ls)

w: new, delete, rename, escape

x: Can you access this directory?

Permission profile

Account information: /etc/passwd

Personal password: /etc/shadow

Group Name: /etc/group

[Comprehensive Case]

[Question 1.1] Establish two user groups group1 and group2, and three users dennis, daniel, abigale, and assign the first two users under group1 user group, and the latter user group under group2 user group.

Log in as dennis and create a Hello.java file

Log in as daniel and see if you can access the/home/dennis directory and read or write the Hello.java file you created.

[Question 1.4] Log in as dennis user and modify the read and write permissions of the directory/home/dennis and Hello.java files (correction: when modifying directory permissions, you should use 770 instead of 760, otherwise the permissions are insufficient)

1.5 Repeat 1.3

Change abigale user group from group2 to group1

Then, you can use cat/etc/passwd to check and determine

[Reference]

-groupadd group name, add group in linux

-vi/etc/group, View all group information in linux, You can see can edit

-cat/etc/group, View all group information in linux, Can only see can not edit

-useradd‐g Group name User name, specify which group the user is assigned to when creating the user

-vi/etc/passwd, View all user information in linux, You can see can edit

-cat/etc/passwd, View all user information in linux, Can only see can not edit

The above is "Linux file permissions sample analysis" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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