How to change owner and permissions in Linux

In order to change owner and permissions on files and folders in Linux, you need first to login the server via SSH.

  1. To change the owner of the file/s and folder/s you need to execute the following command:
  •  sudo chown username:group file/directory

If you use the -R key, it will make it recursively. Also if you use * for the name, it will change the owner for all items in current directory. Example:


  1. To change the permissions of files and folders you need to use the following command:
  • sudo chmod XXX file/directory

where XXX represents rights for Owner/Group/World. Rights can be assigned via decimal digits:

  • chmod 644 filename

or with letters:

  • chmod  u=rwx,g+x,o-rx  filename

r (read) = (has value of) 4
w (write)= (has value of) 2
x (execute)= (has value of) 1

For example if you want to give read, write and execute permissions (4+2+1) to owner, read and execute (4+1) to group and world you need to use the following:

  • chmod  755  filename

Setting up the permissions with letters works similar. You have the following abbreviations:

u for user(owner)

g for group

o for others(world)

The following signs are also used: +, - or =

+ will set the specified flag/s and leave other permissions alone
- will unset the specified flag/s and leave all other permissions alone
= will set any specified flags and unset any that are left out of the list.

  • chmod u=rwx,g+rx,o-rx filename

Again the -R key in both cases will do it recursively and using the * will change permissions for all items in current folder. Example: