file ownerships and file permisions on Linux and unix like systems

It indicatesFile name: linux_script.shLast modified: July 21 at 9:30PMFile size: 1801 bytesThe group of the file: staffThe owner of the file: rootroot access level: read, write and executestaff access level: read and executeothers access level: read onlyThe first symbol – means this is a file, D means it is a directory. The rest are 9 symbols divided into 3 groups:
Firt three symbols for the owner of the file
Second three symbols for the group of the file
Last three symbols for other users who have access to the computer

Create a new user “ben” and set a password’

adduser ben
passwd ben

Delete the user “ben”.

userdel ben

Create a new group developers and check if it was created successfully.

groupadd developers
grep developers /etc/group

Delete the group developers.

groupdel developers

Add the user “ben” to the group staff and check if the staff was added successfully.

usermod -a -G staff ben
groups ben

Remove the user “ben” from the group staff and check if it was removed successfully.

gpasswd -d ben staff
groups ben

Change the group of /u to “staff”.

chgrp staff /u

Change the group of /u and subfiles to “staff”

chgrp -hR staff /u

Change the owner of /u to “root”.

chown root /u

Change the owner of /u to “root” and also change its group to “staff”.

chown root:staff /u

Change the owner of /u and subfiles to “root”.

chown -hR root /u

Give read permission for all users

chmod +r linux_script.sh

Give write permission for all users

chmod +w linux_script.sh

Give execute permission for all users

chmod +x linux_script.sh

Give read, write and execute permission for all users

chmod +rwx linux_script.sh

Give read, write and execute permissions to the file owner; give read and write permissions to the users who are members of the file’s group; give read permisson to other users

chmod u+rwx,g+rw,o+r linux_script.sh

To remove the write permission for all users

chmod -w linux_script.sh

Give read permission to everyone for the directory /share and it’s subfiles

chmod -R +r /share

We can also use numbers to grant permissions for files and directories.