Linux shared permission settings

Source: Internet
Author: User
Linux sharing permission settings-general Linux technology-Linux technology and application information. For details, refer to the following section. The author of this article is Venmos, not TualatriX. Thank you for writing this article for Linuxer.

Preface:
This is a basic but easy-to-learn Linux directory permission setting article. I used to use Windows Server to Manage File Access Permissions On a GUI. later I learned about the GUN/Linux Server and found that the permission management settings of GUN/Linux are very powerful and convenient. however, I found that no article on the Internet is a complete description + which is easy for readers to understand. So I wrote this simple and easy-to-understand Linux folder permission setting, hoping to help you.

What are the benefits of permission settings?
As computers become increasingly popular, there is more than one computer in the family, and it is increasingly common for friends to take their laptops together. but when I shared my favorite winter with my family or friends on my computer, did I encounter access failures? No File Execution permission? Or do you want your family and friends to see the winter and winter on their computers and share with them what they want to see?

If you have encountered the above problems and haven't solved them yet, you can continue to read them. I believe I can solve your problem!

First
Make sure that the computer system you want to set is GUN/Linux. You have administrator permissions or an account that can use the sudo command in the computer system you want to set.

In Linux, the use of terminal command lines is far easier than the graphical interface, so this article is all done in the terminal.

Some commands can also be used in Unix or Mac OS x Leopard 10.5. If this command is also available in Unix or Mac OS X Leopard 10.5, I will mark it at the end of the command.

Now, open your terminal.

First, enter su and your administrator account password. If you are using sudo, enter sudo su and enter your account password to log on.

Wait until the command prompt is changed to # And then perform the following operations.

Enter the folder you want to share, preferably in the/home Directory, which is good at management. If you do not have a folder dedicated for sharing, you can create one.

Go to the directory where you want to create a shared folder. the cd path command can help you go to any directory you want. For example, cd/var/www is used to enter the www folder in the var folder under the root directory. if you do not know the name of the directory you want to go to, you can cd/enter the root directory, and then enter the ls command to view all the folder names in the root directory, then run the cd command to enter the folder [Linux/Unix/Mac]

Cd... allows you to return to the upper-level directory. For example, if you enter cd... in the/var/www directory, it will be returned to the var directory. If you enter cd... /Blog/will enter the blog folder in the/var/directory.

Enter the name of the shared folder you want to create, such as mkdir sharing [Linux/Unix/Mac]

Now, the shared folder has been created. however, this folder is created with the administrator account. It cannot be accessed or modified directly in the graphic interface of normal account logon. It may be difficult to copy and modify files. so we need to modify the permission of this shared folder so that you can access and modify the file in the graphical interface.

Chown is a command used to modify the owner of a file or folder and all groups. if your user name is jack, your shared folder directory is/home/sharing/. Then you can enter the chown jack/home/sharing command to replace the owner of the sharing folder with jack. after changing the user, you also need to add the user's read and write permissions on the folder, and enter chmod + 700/home/sharing. Okay, now you have full permissions on the file shelf. now let's put the data you want to share with friends and family members.

After setting up the data you want to share, you can create a shared account for your friends or family.

Enter useradd test to create a test account. Of course, you can also create another name, such as useradd hello, so that a hello account is created. create a password for this account, enter passwd test and press enter, and then press Enter. after entering the password once, create the password for the test account.

Create a group and input groupadd testing to create a testing group. then enter gedit/etc/group to find the line testing in the Open Text Editor, add test to the end, save the file, and exit the editor. in this way, the test account is added to the testing user group.

What are the advantages of creating a group?

For example, you have a directory in the shared folder that stores movies. You want your friends or family to access and play these movies, but do not want to grant them the permission to write them, for fear that they may accidentally delete files.

For example, if your movie directory is/home/sharing/movie, you can enter chown jack: the movie directory testing/home/sharing/movie can be accessed by users in jack's account and testing. If there are other directories in your movie, add the-R parameter after chown.-R indicates modifying the Directory and all its branch directories and files. for example, if chown-R jack: testing/home/sharing/movie, all the files and directories in movie and movie are changed to jack accounts and testing group users.

After entering chmod 755/home/sharing/movie, jack's account will have full permissions on the movie directory, but the testing user group has only the access and execution permissions. similarly, this command can add-R to allow all directories and files under the movie directory to modify permissions at the same time.

Of course, you can set different groups and users to achieve different effects, I believe that using the smelly and long super instructions can help users who log on to Linux and open terminals understand how to set different folders and grant different access permissions? If you have thoroughly studied the above... Then you can learn the following commands.

Ls to list folders and files in the current directory

Ls-l: view the access permission of the current directory. After ls-l is input, a row such as-rw-r? Text such as-indicates the type, the middle-rw indicates the owner, the third-rw indicates the group, and the last r? All users in the system. r indicates that the file can be read, w indicates that the file can be written, and x indicates that the file can be executed.-indicates that the file is empty.

Command for chmod to modify file or folder Permissions
Chmod-R is the permission to modify the file shelf and all files and directories under this folder.

U represents the file owner g Represents the user group o represents all accounts except the file owner and all file groups
A Indicates all accounts in the system.

R indicates file readable w indicates file writable x indicates file executable

Add-delete

Chmod o + w test.txt grants the permission to write the test.txt file to all users in and out of the file.

Chmod go-rw test.txt Delete the owner of the file test.txt and the read and write permissions of all groups.

You can also set the directory, for example, set the movies directory to chmod go-rw movies.

Chown is used to modify the owner and all groups of files and folders.

Chown jack: testing movies is to replace the owner of the movies directory with jack, and replace all the groups with testing. Note that you must add one before the Group Name: otherwise, the system will not recognize it...
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.