Managing File and Directory Permissions
Explore how to effectively manage and modify file and directory permissions in Linux using chmod. Understand symbolic permissions, recursive changes, and the difference between file and directory access to control user rights and secure system resources.
We'll cover the following...
Checking permissions
If we’re the system administrator, or if we can run the sudo command, we can change the permissions on files and directories anywhere on our system.
The file structure we made in the home directory is something other users on the machine could use, so let’s copy the structure into the /var directory so others can access it. We use the sudo command since we don’t have write access to the /var directory:
$ sudo cp -r ~/files /var/files
Next, we get a long listing of the /var/files directory, showing all hidden files. This lets us view the permissions of the /var/files directory itself:
su temp
sudo mkdir -p files/{movies,music,photos,docs/{diagrams,markdown},code/{go,js,elm}}
clear
sudo cp -r /files /var/files
ls -alh /var/files
Run the complete code on the terminal below for practice.
Recall from Listing Files and Directories that the first entry in the list (.), represents the directory itself, in this case, /var/files. Remember that the permissions break down like this:
File Permissions
User | Group | Others |
|
|
|
In this case, the root user can read, write, and execute files in this directory. Other users on the system can read from this directory structure and execute any files there, but they won’t be able to create new files or even make changes to the contents of the files. Execute permissions on directories also allow users to list their contents.
There are two methods we can use to alter access to this structure. We can change the permissions, or we can ...