What I'll cover in this article is how to identify permissions for files & directories and how to change them, as well as changing ownerships, groups, etc. Depending on what you want to do, you'll want to make sure you have the appropriate permissions (obviously), so let's find out how to change them.
-rwxrw-r-- file1.txt
4.1 chmod - Using Assignment operator:
The Permission Types that are used here are:
Example:
Using above permission groups and types in chmod we change the permission of the file.
Linux $ ls –l /sample
Linux $ ls –l sample3.txt
Linux $ ls –l /sample
Linux $ ls –l sample1.txt
4.2 chmod - Using Numeric values:
Numeric values for type of permissions are,
Example:
1.
File
Permission Groups
2.
File
Permission Types
3.
Viewing
File Permission
4.
Modifying
File Permission
1. File Permission Groups:
Each file and directory has three user based permission groups:
- owner - The Owner permissions apply only the owner of the file or directory.
- group - The Group permissions apply only to the group that has been assigned to the file or directory.
- all users - The All Users permissions apply to all other users on the system.
Example:
-rwxrw-r-- file1.txt
In the whole we have 10 digits ,
( 1 )First field ( - ) gives the type of file ,
( 2 - 4 ) Next three field tells about Owner’s access on the file .
( 5 - 7 ) Next three fields tells about access of groups on the file .
( 8 - 10 ) Last three fields tells about all other users access on the file . In the above example,
Owner has complete access ie. Read, Write and Execute permission.
Group has read and write permission on the file file1.txt .
All other users have read-only access on the file .
2. File Permission Types:
Each file or directory has three basic permission types:
- read - The Read permission refers to a user's capability to read the contents of the file.
- write - The Write permissions refer to a user's capability to write or modify a file or directory.
- execute - The Execute permission affects a user's capability to execute a file or view the contents of a directory.
Example :
rwxrwxrwx file1.txt
In the above ,
r – Stands for Read access.
w – Stands for Write access.
x – Stands for Execute permission.
3. Viewing File Permission:
ls command helps to list the files in the directory . It also helps to display the files with its permission.
COMMAND:
ls –l helps to list the files with their permissions .
Example:
A directory named sample under root directory contains list of below files.
sample1.txt
sample2.txt
sample3.txt
Linux $ ls –l /sample
rwxrwxrwx sample1.txt
rwxrw-r-- sample2.txt
rwx------ sample3.txt
In sample1.txt , Every users has complete access on it .
In sample2.txt , Owner has complete access , Group has read write access , all others has read only access .
In sample3.txt , Only owner of the file has permission to access the file .
4. Modifying File Permission:
In Linux, File permission can be modified using command chmod. In Linux, chmod stands for change mode.
There are two types of method to change file permission using chmod. They are,
4.1 Using Assignment operator,
4.2 Using Numeric values.
4.1 chmod - Using Assignment operator:
Assignment operators used in modifying file permission using chmod are “+” and “-”.
“+” – This operator helps to provide permission to the file or directory.
“-” – This operator helps to remove permission to the file or directory.
The Permission Groups used here are:
u - Owner
g - Group
o or a - All Users
The Permission Types that are used here are:
r - Read
w - Write
x – Execute
Example:
Using above permission groups and types in chmod we change the permission of the file.
Linux $ ls –l /sample
rwxrwxrwx sample1.txt
rwxrw-r-- sample2.txt
rwx------ sample3.txt
Providing file permission using + operator,
Linux $ chmod a+rw sample3.txt
The above command provides read and write permission to global users.
Linux $ ls –l sample3.txt
rwx---rw- sample3.txt
Removing file permission using - operator,
Linux $ ls –l /sample
rwxrwxrwx sample1.txt
rwxrw-r-- sample2.txt
rwx---rw- sample3.txt
Removing file permission using - operator, Linux $ chmod a-wx sample1.txt
The above command removes read and write access to global users.
Linux $ ls –l sample1.txt
rwxrwxr-- sample1.txt
4.2 chmod - Using Numeric values:
Numeric values for type of permissions are,
r = 4
w = 2
x = 1
Below are the numeric values for different type of permissions,
7 = 4+2+1 (read/write/execute)
6 = 4+2 (read/write)
5 = 4+1 (read/execute)
4 = 4 (read)
3 = 2+1 (write/execute)
2 = 2 (write)
1 = 1 (execute)
Example:
chmod 400 sample.txt – read by owner
chmod 040 sample.txt – read by group
chmod 004 sample.txt – read by anybody (other)
chmod 200 sample.txt – write by owner
chmod 020 sample.txt – write by group
chmod 002 sample.txt – write by anybody
chmod 100 sample.txt – execute by owner
chmod 030 sample.txt – write and execute by group
chmod 001 sample.txt – execute by anybody
chmod 666 sample.txt – read and write by anybody
chmod 755 sample.txt – rwx for owner, rx for group and rx for the world
No comments:
Post a Comment