permission logic ubuntu

How to find any folder & data permission

Step 1 :- 
:- $ su
:- $ Password ******
:- # cd /go to path
:- # ls -l 

Show all permission

drwxr-xr-x         5 root   root      4096 Dec 24 19:07 apache2
drwxrwxr-x       2 root   root     12288 Dec 24 19:08 bin
drwxr-xr-x        2 root   root      4096 Dec 24 19:08 cgi-bin
-rw-r--r--           1 root   root     86259 Nov 21 06:38 COPYING.thirdparty
-rwxr-xr-x         1 root   root     27372 Dec 24 19:07 ctlscript.sh
drwxrwxr-x       3 root   root      4096 Dec 24 19:08 error
drwxr-xr-x        8 root   root      4096 Dec 30 17:42 etc
drwxr-xr-x        6 jeet   jeet      4096 Dec 30 17:35 htdocs
drwxr-xr-x        3 root   root      4096 Dec 24 19:08 icons
drwxr-xr-x        2 root   root      4096 Dec 24 19:07 img
lrwxrwxrwx      1 root   root        16 Dec 24 19:08 lampp -> /opt/lampp/xampp
drwxr-xr-x       14 root   root     12288 Dec 24 19:08 lib
drwxr-xr-x       2 root   root      4096 Dec 24 19:07 libexec
drwxr-xr-x       2 root   root      4096 Dec 24 19:08 licenses
drwxr-xr-x       2 daemon daemon    4096 Dec 30 19:05 logs
-rwx------         1 root   root   3096815 Jun 10  2013 manager-linux.run
drwxr-xr-x       2 root   root      4096 Dec 24 19:08 modules

chmod
The chmod command is used to change the permissions of a file or directory. To use it, you specify the desired permission settings and the file or files that you wish to modify. There are two ways to specify the permissions, but I am only going to teach one way.
It is easy to think of the permission settings as a series of bits (which is how the computer thinks about them). Here's how it works:
rwx rwx rwx = 111 111 111
rw- rw- rw- = 110 110 110
rwx --- --- = 111 000 000

and so on...

rwx = 111 in binary = 7
rw- = 110 in binary = 6
r-x = 101 in binary = 5
r-- = 100 in binary = 4

Now, if you represent each of the three sets of permissions (owner, group, and other) as a single digit, you have a pretty convenient way of expressing the possible permissions settings. For example, if we wanted to set some_file to have read and write permission for the owner, but wanted to keep the file private from others, we would:

ValueMeaning
777(rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
755(rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
700(rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
666(rw-rw-rw-) All users may read and write the file.
644(rw-r--r--) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
600(rw-------) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.

Directory permissions

The chmod command can also be used to control the access permissions for directories. In most ways, the permissions scheme for directories works the same way as they do with files. However, the execution permission is used in a different way. It provides control for access to file listing and other things. Here are some useful settings for directories:
ValueMeaning
777(rwxrwxrwx) No restrictions on permissions. Anybody may list files, create new files in the directory and delete files in the directory. Generally not a good setting.
755(rwxr-xr-x) The directory owner has full access. All others may list the directory, but cannot create files nor delete them. This setting is common for directories that you wish to share with other users.
700(rwx------) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.

chown owner-user file
chown owner-user:owner-group filechown owner-user:owner-group directory
chown options owner-user:owner-group fileExamplesFirst, list permissions for demo.txt, enter:
# ls -l demo.txt
Sample outputs:
-rw-r--r-- 1 root root 0 Aug 31 05:48 demo.txt
In this example change file ownership to jeet user and list the permissions, run:
# chown jeet demo.txt
# ls -l demo.txt
# ls -l demo.txtSample outputs:-rw-r--r-- 1 vivek root 0 Aug 31 05:48 demo.txtIn this next example, the owner is set to vivek followed by a colon and a group onwership is also set to vivek group, run:# chown jeet:jeet demo.txtSample outputs:
-rw-r--r-- 1 vivek vivek 0 Aug 31 05:48 demo.txtIn this example, change only the group of file. To do so, the colon and following GROUP-name ftp are given, but the owner is omitted, only the group of the files is changed:# chown :ftp demo.txt# ls -l demo.txtSample outputs:
-rw-r--r-- 1 jeet ftp 0 Dec 31 09:20 demo.txt
Please note that if only a colon is given, or if NEW-OWNER is empty, neither the owner nor the group is changed:# chown : demo.txtIn this example, change the owner of /foo to "root", execute:# chown root /fooLikewise, but also change its group to "httpd", enter:# chown root:httpd /fooChange the owner of /foo and subfiles to "root", run:# chown -R root /uWhere,
-R - Recursively change ownership of directories and their contents.
Practical Examples

chmod 400 mydoc.txt read by owner
chmod 040 mydoc.txt read by group
chmod 004 mydoc.txt read by anybody (other)
chmod 200 mydoc.txt write by owner
chmod 020 mydoc.txt write by group
chmod 002 mydoc.txt write by anybody
chmod 100 mydoc.txt execute by owner
chmod 010 mydoc.txt execute by group
chmod 001 mydoc.txt execute by anybody

Wait! I don't get it... there aren't enough permissions to do what I want!

Good call. You need to add up the numbers to get other types of permissions...

So, try wrapping your head around this!!

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)

chmod 666 mydoc.txt read/write by anybody! (the devil loves this one!)
chmod 755 mydoc.txt rwx for owner, rx for group and rx for the world
chmod 777 mydoc.txt read, write, execute for all! (may not be the best plan in the world...)







No comments:

Post a Comment