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 assign permissions to the site directory in linux

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

Share

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

Editor to share with you how to assign permissions to the linux Central Construction site directory, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Preliminary work

Create a folder test first

Mkdir test

Create a 1.txt file in this directory and write to

Cat > 1.txt111

Now exit the directory to analyze and change the directory permissions one by one.

Do not use the root user to create the folder because the file permissions configuration is not valid for the root user

Executable permissions of the directory

Chmod 111 test

After testing, only cd test can enter the directory at this time, but it can neither ls the column directory nor touch 2.txt a new file, but cat 1.txt can still read the contents.

So we concluded

The executable permission of the directory is that the user can enter or switch to the directory, but cannot list the directory and create a new file, and the permission to read the original file is set to readable.

Writeable permissions for directories

Chmod 222 test

The most intuitive change is the darker color of the directory (ps, which darkens when files are given executable permissions)

You can try some of our common commands.

Ls testcd testcat test/1.txttouch test/2.txt

The result is that nothing can be done.

Ubuntu@VM-8-81UBUUTU touch test/2.txttouch: $ls testls: cannot open directory test: Permission deniedubuntu@VM-8-81MUBUBUTU: $cd testbash: cd: test: Permission deniedubuntu@VM-8-81MUBUBUTU: $cat test/1.txtcat: test/1.txt: Permission deniedubuntu@VM-8-81MUBUBUTU: cannot touch 'test/2.txt': Permission denied

Now we are adding executable permissions to the changed directory.

Chmod 333 test

It is found that except for the abnormal ls column directory, all the other cd touch cat can be executed, so a summary is drawn.

If the linux folder wants to create a file, it must have writeable executable permission, that is, the permission size is 333.If only write permission is given, nothing can be done.

Readable permissions for the directory

Chmod 444 testubuntu@VM-8-81 murmur ubuntu Permission deniedubuntu@VM-8: $ls testls: cannot access test/1.txt: Permission deniedls: cannot access test/2.txt: Permission denied1.txt 2.txtubuntu@VM-8-81 Mutual ubuntu cat test/1.txtcat: cat test/1.txtcat: test/1.txt: Permission denied

Summary: the readable permissions of a directory can be listed as a directory

The website only has readable permissions and can only list directories, and other cd cat cannot be executed, so what is the permission of the website to set 555?

Ubuntu@VM-8-81 testubuntu@VM-8 chmod 555 testubuntu@VM-8-81 Mutual ubuntu testubuntu@VM-8: $cd test/ubuntu@VM-8-81 cd test/ubuntu@VM-8-81 ubuntu ls1.txt 2.txtubuntu@VM-8: Permission denied

As you can see, all commands can be executed except that the touch command cannot create a new file.

At this point, it is naturally easy to launch a folder with 666 permissions that is readable and writable but does not have executable permissions, and cannot enter the directory, but with readable and writable permissions, basic permissions are also available. 777 permissions is the maximum permission of the folder.

When looking back to analyze the first sentence of the article, the minimum permissions for folders and files are 755 and 644 respectively.

There is a problem of user rights assignment.

When chmod modifies permissions, there are three groups of access rights for each file or directory. Each group is represented by three digits, namely, the read, write and execute permissions of the file owner, the read, write and execute permissions of users in the same group as the master, and the read, write and execute permissions of other users in the system.

Folder permission 7 and file permission 6 are assigned to linux administrative users. Apache defaults to www ordinary users who visit the website, so the file permission 755 means that ordinary users can only view and browse the website, but do not have the permission to create or upload files. Generally, if you need a special folder such as upload or tmp folder to store some temporary files, you need to set the folder permission to 777. File permission 644, that is, can only be viewed but cannot be modified

The above is all the contents of the article "how to assign permissions to the website directory in linux". Thank you for your reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to 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