Use chown
command for the ownership, and add -hR
flag for all its sub-files/folders.
For example, make animals
and all files/folders under that folder owned by user
and group user
via command:
sudo chown user:user -hR animals
TIP: remove -hR
so it applies to that folder only.
Use chmod
command for file/folder permission, with following flags:
u
means user(owner), g
means group, o
means others, a
for all.
r
for read permission, w
for write, and x
for execute.
For example, grant read and write permission for user and group, but only read permission for others, use (add sudo
if you're not owner):
chmod u=rw,g=rw,o=r FILE
Grant read and write permission for all:
chmod a=rw FILE
or add read&read permission for all:
chmod +rw FILE
Remove write permission for others (for that folder only):
chmod o-w FOLDER
Add read/write/executable for user and group, but no permission for others, for specified folder and all sub-files/folders:
chmod -R ug+rwx,o-rwx FOLDER
You can also use numbers along with chmod
command to change permissions.
1
= executable
2
= write permission.
4
= read permission.
5
= 1+4 = write & execute
6
= 2+4 = read & write
7
= 1+2+4 = read & write & execute
First number applies for owner(user), second for group, and the last for others. So, the command below means full permission for user, write & execute permission for group and others.
chmod 755 FILE
Also add -R
for folder and all sub-files/folder. For example, grant read & write for user(owner) but no permission for all others.
chmod 600 -R FOLDER
There are lots of tutorials about this stuff in the web, and I got one here:
https://fostips.com/tell-change-file-permission-owner-linux/