Hostwinds Tutorials
Search results for:
Table of Contents
Linux is designed to manage multiple users efficiently, ensuring that only authorized individuals can access or modify specific files. This is done through a system of file ownership and permissions that helps protect system and user data. Understanding these mechanisms helps maintain system security and ensure proper file management.
In Linux, every file and directory is associated with an owner and a group. Access to these files is controlled through permissions, which determine whether a user can read, write, or execute a file.
Key Concepts:
To view the ownership and permissions of a file/directory, use the 'ls -l' command:
ls -l filename
-rwxrw-r-- 1 foo bar 1024 Jan 1 00:00 filename
To list details of all files in a directory, simply use 'ls -l' without specifying a filename. For directories, this command lists contents with the same detailed output.
For more details on ls, use 'ls --help' or 'man ls' commands.
Only the root user or users with appropriate sudo privileges can modify file ownership. To change ownership, use the 'chown' command:
chown [user]:[group] filename
chown newowner filename
chown :newgroup filename
chown newowner:newgroup filename
To apply changes to ownership recursively to a directory and its contents, use the '-R 'option:
chown -R newowner:newgroup /path/to/directory
For more information on 'chown', use 'chown --help' or 'man chown'.
File permissions can be adjusted using the 'chmod' command. There are two main methods:
Symbolic Mode
Numeric Mode
Adjust permissions using symbolic representations.
chmod u+x filename
chmod ug+rw filename
chmod o-r filename
Numeric mode allows you to set permissions using a three-digit number. Each digit represents permissions for the owner, group, and others respectively. The value for each digit is the sum of the numbers representing which permissions are allowed for that role, with a max value of 7 (seven) for each digit. 0 (zero) represents no permissions.
Numeric representation for each permission type:
For example, to give the user read and write access, the group only read access, and other users no access, the number to represent that would be 740.
Here are a few more examples:
chmod 000 filename
chmod 777 filename
chmod 640 filename
Written by Hostwinds Team / August 29, 2018