Friday, March 9, 2012

chown,chmod

chown
The chown command (abbreviation for change owner) is used on Unix-like systems to change the owner of a file. In most implementations,[citation needed] it can only be executed by the superuser, to prevent users simply changing ownership of files that aren't their's to access them. Unprivileged (regular) users who wish to change the group of a file that they own may use chgrp.

Usage examples

These examples illustrate typical syntax and use. Modifying permissions requires you are either root or have write access to the file. Changing owner requires root privilege.

Change the owner of /var/run/httpd.pid to 'root' (the standard name for the Superuser).
# chown root /var/run/httpd.pid

Change the owner of strace.log to 'rob' and the group identifier to 'developers'.
# chown rob:developers strace.log

Change the owner of /tmp and /var/tmp to ‘nobody’ (not a good idea), and change the group of /tmp and /var/tmp to ‘nogroup
# chown nobody:nogroup /tmp /var/tmp

Change the group identifier of /home to 512 (regardless of whether a group name is associated with the identifier 512 or not).
# chown :512 /home

Change the ownership of base to the user foouser and make it recursive (-R)
# chown -R foouser base

Change the ownership to newuser and group to newgroup for all of the files and directories in current directory, and all subdirectories (recursively).
# chown -R newuser:newgroup .

CHMOD
Command line examples
command

chmod a+r file                     read is added for all
chmod a-x file                     execute permission is removed for all
chmod a+rw file                  change the permissions of the file file to read and write for all.
chmod +rwx file                  On some UNIX platforms such as BSD, this will restore the permission of the file file to default: -rwxr-xr-x.

chmod u=rw,go= file             read and write is set for the owner, all permissions are cleared for the group and others

chmod -R u+w,go-w docs    change the permissions of the directory docs and all its contents to add write access for the user, and deny write access for everybody else.

chmod file            removes all privileges for all

===========================================================
chmod 777 file
change the permissions of the file file to read, write, and execute for all.

chmod 664 file
sets read and write and no execution access for the owner and group, and read, no write, no execute for all others.

chmod 0755 file
equivalent to u=rwx (4+2+1),go=rx (4+1 & 4+1). The 0 specifies no special modes.

chmod 4755 file
the 4 specifies set user ID and the rest is equivalent to u=rwx (4+2+1),go=rx (4+1 & 4+1).

chmod -R u+rwX,g-rwx,o-rwx directory
set a directory tree to rwx for owner directories, rw for owner files, --- for group and others.

chmod -R a-x+X directory
remove the execute permission on all files in a directory tree, while allowing for directory browsing.

No comments:

Post a Comment