File/Folder Permission in Linux (Ubuntu)
===========================
Step 1. View File Permission
Step 2. Change File Permission
(+ for add permission, - for remove permission, = for set permission)
Step 2.a. Remove Read Permission from owner
Read restricts or allows viewing the directories contents, i.e. ls command
Step 2.b. Add Read Permission to owner
Step 2.c. Remove Write Permission from owner
Write restricts or allows creating new files or deleting files in the directory
Step 2.d. Add Write Permission to owner
Step 2.e. Remove Execute Permission from owner
Execute restricts or allows changing into the directory, i.e. cd command
Step 2.f. Add Execute Permission to owner
Step 2.g. Remove all Permission to owner from file
Step 2.h. Add all Permission to owner to file
Step 3. Alternate Way
Add write permission for groups owner, remove write permission for user owner.
Step 3.a. View Folder Permission
(d indicate directory, Owner (rwx), Group (r-x), Other (r-x), Link, User_name, Group_name, Size, mod date, folder_name)
Step 3.b. Remove Read Permission for Group
Step 3.c. Add Read Permission for Group
Step 4. Add Single Permission to a File/Directory
Changing permission to a single set. + symbol means adding permission. For example, do the following to give execute permission for the user irrespective of anything else:
Step 5. Add Multiple Permission to a File/Directory
Use comma to separate the multiple permission sets as shown below.
Step 6. Remove Permission from a File/Directory
Following example removes read and write permission for the user.
Step 7. Change Permission for all roles on a File/Directory
Following example assigns execute privilege to user, group and others (basically anybody can execute this file).
Step 8. Make Permission for a File same as another File (using reference)
If you want to change a file permission same as another file, use the reference option as shown below. In this example, file2′s permission will be set exactly same as file1′s permission.
Step 9. Apply the Permission to all the Files under a Directory recursively
Use option -R to change the permission recursively as shown below.
Step 10. Change Execute Permission only on the Directories (Files are not affected)
On a particular directory if you have multiple sub-directories and files, the following command will assign execute permission only to all the sub-directories in the current directory (not the files in the current directory).
Note: If the files has execute permission already for either the group or others, the above command will assign the execute permission to the user
(taken help from net)
------------------------ arahman.iit@gmail.com
===========================
Step 1. View File Permission
=> ls -l name_of_file
e.g:
=> root@ubuntu10:~# ls -l examples.desktop
-rw-r--r-- 1 mukul mukul 179 2012-02-11 13:33 examples.desktop
(-indicate File, Owner (rw-), Group (r--), Other (r--), Link, User_name, Group_name, Size, mod date, file_name)Step 2. Change File Permission
(+ for add permission, - for remove permission, = for set permission)
Step 2.a. Remove Read Permission from owner
Read restricts or allows viewing the directories contents, i.e. ls command
=> chmode u-r name_of_the_file
=> root@ubuntu10:~/Desktop# ls -l file1.txt
-rw-r--r-- 1 root root 0 2012-04-01 12:54 file1.txt
=> root@ubuntu10:~/Desktop# chmod o-r file1.txt
=> root@ubuntu10:~/Desktop# ls -l file1.txt
-rw-r----- 1 root root 0 2012-04-01 12:54 file1.txt
Step 2.b. Add Read Permission to owner
=> chmode u+r name_of_the_file
=> root@ubuntu10:~/Desktop# chmod o+r file1.txt
=> root@ubuntu10:~/Desktop# ls -l file1.txt
=> -rw-r--r-- 1 root root 0 2012-04-01 12:54 file1.txt
Step 2.c. Remove Write Permission from owner
Write restricts or allows creating new files or deleting files in the directory
=> chmode u-w name_of_the_file
=> root@ubuntu10:~/Desktop# chmod u-w file1.txt
=> root@ubuntu10:~/Desktop# ls -l file1.txt
-r--r--r-- 1 root root 0 2012-04-01 12:54 file1.txt
Step 2.d. Add Write Permission to owner
=> chmode u+w name_of_the_file
=> root@ubuntu10:~/Desktop# chmod u+w file1.txt
=> root@ubuntu10:~/Desktop# ls -l file1.txt
-rw-r--r-- 1 root root 0 2012-04-01 12:54 file1.txt
Step 2.e. Remove Execute Permission from owner
Execute restricts or allows changing into the directory, i.e. cd command
=> chmode u-x name_of_the_file
=> root@ubuntu10:~/Desktop# chmod u-x file1.txt
=> root@ubuntu10:~/Desktop# ls -l file1.txt
-rw-r--r-- 1 root root 0 2012-04-01 12:54 file1.txt
Step 2.f. Add Execute Permission to owner
=> chmode u+x name_of_the_file
=> root@ubuntu10:~/Desktop# chmod u+x file1.txt
=> root@ubuntu10:~/Desktop# ls -l file1.txt
-rwxr--r-- 1 root root 0 2012-04-01 12:54 file1.txt
(color of the file1.txt will be green)
Step 2.g. Remove all Permission to owner from file
=> chmode u-rwx name_of_the_file
=> root@ubuntu10:~/Desktop# chmod u-rwx file1.txt
=> root@ubuntu10:~/Desktop# ls -l file1.txt
----r--r-- 1 root root 0 2012-04-01 12:54 file1.txt
Step 2.h. Add all Permission to owner to file
=> chmode u+rwx name_of_the_file
=> root@ubuntu10:~/Desktop# chmod u+rwx file1.txt
=> root@ubuntu10:~/Desktop# ls -l file1.txt
-rwxr--r-- 1 root root 0 2012-04-01 12:54 file1.txt
Step 3. Alternate Way
Add write permission for groups owner, remove write permission for user owner.
=>chmod u-w,g+w name_of_the_file
Step 3.a. View Folder Permission
=> ls -l name_of_directory/folder_name
=> root@ubuntu10:~/Desktop# ls -ld test/
drwxr-xr-x 2 root root 4096 2012-04-01 13:03 test/
(d indicate directory, Owner (rwx), Group (r-x), Other (r-x), Link, User_name, Group_name, Size, mod date, folder_name)
Step 3.b. Remove Read Permission for Group
=> root@ubuntu10:~/Desktop# chmod g-r test/
=> root@ubuntu10:~/Desktop# ls -ld test/
=> drwx--xr-x 2 root root 4096 2012-04-01 13:03 test/
Step 3.c. Add Read Permission for Group
=> root@ubuntu10:~/Desktop# chmod g+r test/
=> root@ubuntu10:~/Desktop# ls -ld test/
drwxr-xr-x 2 root root 4096 2012-04-01 13:03 test/
Step 4. Add Single Permission to a File/Directory
Changing permission to a single set. + symbol means adding permission. For example, do the following to give execute permission for the user irrespective of anything else:
=> chmod u+x filename
Step 5. Add Multiple Permission to a File/Directory
Use comma to separate the multiple permission sets as shown below.
=> chmod u+r,g+x filename
Step 6. Remove Permission from a File/Directory
Following example removes read and write permission for the user.
=> chmod u-rx filename
Step 7. Change Permission for all roles on a File/Directory
Following example assigns execute privilege to user, group and others (basically anybody can execute this file).
=> chmod a+x filename
Step 8. Make Permission for a File same as another File (using reference)
If you want to change a file permission same as another file, use the reference option as shown below. In this example, file2′s permission will be set exactly same as file1′s permission.
=> chmod --reference=file1 file2
Step 9. Apply the Permission to all the Files under a Directory recursively
Use option -R to change the permission recursively as shown below.
=> chmod -R 755 directory-name/
Step 10. Change Execute Permission only on the Directories (Files are not affected)
On a particular directory if you have multiple sub-directories and files, the following command will assign execute permission only to all the sub-directories in the current directory (not the files in the current directory).
=> chmod u+X *
Note: If the files has execute permission already for either the group or others, the above command will assign the execute permission to the user
(taken help from net)
------------------------ arahman.iit@gmail.com
No comments:
Post a Comment