Skip to content

Instantly share code, notes, and snippets.

@UltimateByte
Last active February 10, 2017 14:06
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save UltimateByte/b261e5e0767e1e9f46673b14451e4750 to your computer and use it in GitHub Desktop.
# Permissions
Change permissions for user, groups, and others on files and directories.
## Command
chmod
## Syntax
chmod -destination+-permissions /path/to/dir/or/file
### Recursive argument
none
### Permissions add
chmod +rwx
#### r stands for "read", w for "write", and x for "execute"
### Permissions remove
chmod -rwx
### Permissions for user/group/others/all
chmod -u+rwx
chmod -g+rwx
chmod -o+rwx
chmod -a+rwx
### Multiple permissions at once
chmod -u+r,g-w,o-rwx
### Copy permissions from a group to another
chmod dest=source
#### Example : chmod -R g=u /home/userdir/subdir
### Set all permissions at once
chmod 777 == chmod -a+rwx
chmod 000 == chmod -a-rwx
#### First number is for user, second is for group, third for others
#### Values
0 no permissions
1 x
2 w
3 wx
4 r
5 rx
6 rw
7 rwx
#### Syntax
chmod xxx /path/to/dir/or/file
#### Recursive
chmod -R xxx /path/to/dir/or/file
### Set GUID
##### No GUID
chmod -R a-s /path/to/dir
chmod -R 0xxx /path/to/dir
###### example : chmod -R 0640 /home/user/website
#### Set UID
##### Files will run as the user
chmod -R u+s /path/to/dir/
chmod -R 2xxx /path/to/dir
#### Set GID
##### Any subdir and subfile will have the same group
chmod -R g+s /path/to/dir/
chmod -R 4xxx /path/to/dir
#### Set GUID
##### Set both UID and GID
chmod -R a+s /path/to/dir/
chmod -R 6xxx /path/to/dir
# Group ownership
Change group ownership on files or directories.
## Command
chgrp
## Syntax
chgrp -Args group /path/to/dir/or/file
### Recursive
chgrp -R group /path/to/dir/
# User and group ownership
Change user ownership for files and directories
## Command
chown
## Syntax
chown -Args user /path/to/dir/or/file
chown -Args user:group /path/to/dir/or/file
### Recursive
chown -R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment