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 Linux File permissions

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the example analysis of Linux file permissions, with a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand it.

Every file or directory in linux contains access permissions that determine who can access these files and directories and how.

1. There are seven file types:

D directory l symbolic link (soft and hard connection) s socket file b block device file c character device file p named pipe file-ordinary file, or, more accurately, files that do not belong to the above types

2. File permission settings

Chmod [who] operator [permission] filename

The meaning of who:

U file belongs to sovereignty limit g same group user rights o other user rights an all users (u+g+o)

The meaning of operator:

+ add permissions-cancel permissions = set permissions

The meaning of permission:

R read permission w write permission x execute permission t sticky bit * l to lock the file, making it impossible for other users to access u.g.o operations for file owners, same group users and other users

Sticky bit "t" if the "t" bit appears on a directory, it means that only the owner of the directory can be deleted; if it appears in the file list, it means that the script or program will be placed in the swap area (virtual memory) when executed.

Modify permissions (symbol mode):

Chmod Uprix hello.pychmod + w hello.pychmod-R + x runall.sh:-R indicates recursive modification, including the sub-files under this folder

Modify permissions (absolute mode, different numbers represent different permissions):

Chmod 664 hello.pychmod 777 *

In absolute mode, the permission to modify should have four digits. 664 is actually 0664. The first bit is to set suid and guid. Once this bit is set, a s:suid (permission number 4) appears on the executable permission bit x, which means that if a user sets this permission on his own shell script, other users will have the corresponding permissions of their owners when executing the script. Guid (permission number 2) means that the user executing the corresponding script will have the permissions of the user in the user group to which the file belongs.

Modify the file to which it belongs:

Syntax: chown-R-h owner file

-R means to make the same changes to files in all subdirectories;-h means that changing the owner of a symbolic link file does not affect the target file that the link points to.

Chown root hello.py: change the ownership of the hello.py file to root

Modify the group in which the file belongs:

The syntax is similar to chown

Chgrp root hello.py: change the group of hello.py files to root

Create file default permissions:

The umask command determines the default permissions for creating files. Generally, umask is set in the / etc/profile file, which is referenced by each user when logging in. If umask is set, it can be saved in the .profile or bash_profile file under $HOME.

Thank you for reading this article carefully. I hope the article "sample Analysis of Linux File permissions" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report