In Linux, how does one manage file and folder permissions?

Source: Internet
Author: User
For many Linux users, it may be difficult to get used to the permissions and ownership of files. People usually think that to enter this level of use, you must use the command line. Although powerful functions and flexibility can always be obtained, running complex commands is not always necessary. for many Linux users, it may be difficult to get used to file permissions and ownership. People usually think that to enter this level of use, you must use the command line. Although it is always possible to obtain much more powerful functions and flexibility, it is not always necessary to run complex commands. With some existing desktop interfaces that are extremely convenient to use, you can get what you want without having to use any command lines, even when managing file permissions and ownership.

Indeed, this may surprise many new users; you can manage files and folders in the file manager. But before we discuss the GUI, we 'd better have a deep understanding of its working mechanism. Therefore, we should start with the command line.

Command line: File permission

The command for modifying file permissions and ownership is as follows:

  • Chmod-change permissions
  • Chown-change ownership

The above two commands are not difficult to use. However, it is important to understand that only the user is the current owner or root user can actually change the permission or ownership of the file. Therefore, if you are a user Bethany, you cannot change the files and folders owned by user Jacob without the root permission (or sudo. For example:

A new folder named/DATA/SHARE is created on the DATA partition. Both Bethany and Jacob must have the permission to read and write the folder. There are many ways to achieve this (one of them is to add two users to a special user group ?? In another article, we will discuss how to manage user groups ). If Bethany and Jacob are the only two users in the system (and you know your network is safe ?? You can change the permissions of the folder and grant them access. Therefore, one method is to execute this command.

 
 
  1. sudo chmod -R ugo+rw /DATA/SHARE 

The detailed breakdown of the above command is as follows:

  • Sudo-this is used to obtain administrator privileges for commands on any system that use sudo (otherwise you have to use 'Su 'to obtain root permissions, run the above command without 'sudo)
  • Chmod-command for modifying permissions
  • -R-This modifies the permissions of the parent folder and its sub-objects.
  • Ugo + rw-This grants read and write access permissions to the User (User), Group (User Group), and Other (Other objects.

You may have guessed that this command is fully open to SHARE folder, so that anyone on the system can access this folder. As I mentioned earlier, a safer way is to use user groups. However, we only use this method for demonstration.

The detailed permission breakdown is as follows:

  • U-user
  • G-user group
  • O-other objects

"Other objects" is a dangerous entry because it actually grants folder/file permissions to everyone. The permissions you can grant to a file or folder are as follows:

  • R-read
  • W-write
  • X-execution

It is important to use the-R option. If you have many subfolders and files in the SHARE directory and want to apply permissions from the parent object (including folders) to sub-objects (subfolders and files), you must use-R (recursion) this parameter option, so that the same permissions can be applied all the way to the deepest folder contained in the parent folder.

Command line: file ownership

It is also easy to change the ownership of a file or folder. Suppose Jacob is Bethany and moves a folder into the SHARE directory, but Jacob still owns the folder. With a simple command, you can change this ownership:

 
 
  1. sudo chown -R bethany /DATA/SHARE 

Let's break down this command in detail.

  • Sudo-The administrator permission is required, because we are dealing with folders belonging to another user.
  • Chown-command for ownership change-R-this Recursive parameter option ensures that all sub-objects have the same ownership change.
  • Bethany-New folder owner
  • /DATA/SHARE-directory to be modified

If Bethany sends the folder back to Jacob, the ownership needs to be changed again (this step can be simplified if the user group is used ).

GUI: user permissions

I am going to use the Nautilus file manager on Ubuntu 13.10 to demonstrate how to change file permissions.

Suppose you need to allow everyone to get the permission to read/write the folder TEST. To do this, take the following steps in the Nautilus file manager:

1. open Nautilus

2. browse to the target file or target folder

3. right-click the file or folder

4. Select Properties)

5. click the Permissions tab.

6. click Access files in the Others (Others) section)

7. select "Create and delete files" (Create and delete files)

8. click Change Permissions for Enclosed Files (Change the permission of the attached file)

9. in the pop-up window, select Read and Write under Files and select Folders) create and delete files under (Create and delete files), as shown in Figure.

10. click Change ).

11. click Close ).

If you need to change permissions that do not belong to your folder, the trick will appear. This can be achieved, but Nautilus must be started with administrator access. To do this, take the following steps:

1. open the terminal window

2. run the sudo-I command.

3. execute the command nautilus

The sudo-I command grants you permanent access to sudo until you enter the exit command to clear the access permission. Once Nautilus is enabled, you can change the folder or file permissions, as described above ?? Even if you are not the owner of the folder or file.

Note: If the release you are using does not use sudo, change the preceding command to the following:

1. open the terminal window

2. run the su command.

3. enter your root password and press enter.

4. execute the command nautilus.

After you complete this task, close the Nautilus window and then close the terminal window.

GUI: change ownership

To change the ownership of a file or folder, you must use the administrator privilege. Therefore, you need to use the method described above to start Nautilus.

To use Nautilus to change the ownership of folders or files, take the following steps:

1. in the Nautilus window opened with administrator permissions, find the corresponding folder or file

2. right-click the folder (or file)

3. click the Permissions tab.

4. select a new Owner from the Owner drop-down list (see)

5. click Close ).

That's it. Now, you can use the command line or GUI to change the permissions or ownership of files or folders. Using user groups allows you to change permissions and ownership, but with more powerful features and higher security ?? We will introduce this in the future. Now, please enjoy the convenience of changing files and folders!

Link: http://www.linux.com/learn/tutorials/760276-how-to-manage-file-and-folder-permissions-in-linux

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.