Skip to content

Instantly share code, notes, and snippets.

@jackie-do
Last active March 12, 2018 08:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackie-do/63ae722f5e785fa2b3ea212775e91bda to your computer and use it in GitHub Desktop.
Save jackie-do/63ae722f5e785fa2b3ea212775e91bda to your computer and use it in GitHub Desktop.
Grant and update user permission in Linux

Changing a file/directory ownership

  1. Check file's permissions and ownership
ll
  1. Changing A File Ownership
sudo chown <user>:<group of user> <path file>

example:

chown willem:willem config_file
  1. Changing A Directory Ownership (option -R)
chown -R <user>:<group> <path file>"

example:

chown -R deploy:deploy /home/config_directory

=================

One permission will be applied for 3 divisions: Owner, Group, Others

Permission Table

Permission String Octal code Meaning
rwxrwxrwx 777 Read, write, and execute permissions for all users
rwxr-xr-s 755 Read and execute permissions for all users, the file's owner also has write permission
rwxr-x--- 775 Read and execute permissions for the owner and group. The file's owner also has write permission. Usesr who aren't the file's owner or members of the group have no access to the file
rwx------ 700 Read, write, and execute permissions for all users. All others (included the group) have no access
rw-rw-rw- 666 Read and write for all users. No execute permissions for anybody
rw-rw-r-- 664 *Read and write for the owner and group. Read only permission for all others.
rw-rw---- 660 Read and write for the owner and group. No permission for others
rw-r--r-- 644 Read and write for the owner only. Read only permission for others (included the group)
rw-r----- 640 Read and write for the owner only. Read-only permission for the group. No permission for the rest
rwx------ 600 Read and write for the owner only. No permission for others (included the group)
r-------- 400 Read permission for the owner only. No permission for others (included the group)

r:

Changing a file's permissions

chmod <octal_code> <file_path>

Example:

chmod 400 pem_key

NOTE

  • r permission ~ Read bit = If set, you can read this list. So, for example, if you have a directory named poems:

    You can ls poems and you'll get a list of items living within (-l won't reveal any details!).

    You can use command-line completion i.e. touch poems/so poems/somefile.

    You cannot make poems your working directory (i.e. cd into it).

  • w permission ~ Write bit = If set, you can modify this list i.e. you can {add,rename,delete} names on it. But! You can actually do it only if the execute bit is set too.

  • x permission ~ Execute bit = Make this directory your working directory i.e. cd into it. You need this permission if you want to:

access (read, write, execute) items living within. modify the list itself i.e. add, rename, delete names on it (of course the write bit must be set on the directory).

Interesting case 1: If you have write + execute permissions on a directory, you can {delete,rename} items living within even if you don't have write perimission on those items. (use sticky bit to prevent this)

Interesting case 2: If you have execute (but not write) permission on a directory AND you have write permission on a file living within, you cannot delete the file (because it involves removing it from the list). However, you can erase its contents e.g. if it's a text file you can use vi to open it and delete everything. The file will still be there, but it will be empty.

Summary:

Read bit = You can read the names on the list.

Write bit = You can {add,rename,delete} names on the list IF the execute bit is set too.

Execute bit = You can make this directory your working directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment