How to change file/directory permission in Linux

How to change file/directory permission in Linux

chmod

chmod (change file mode bits) command allows you to change file access and directory. File permissions are given to users, groups, and other users.

SYNOPSIS

chmod [OPTION]… MODE[,MODE]… FILE…
chmod [OPTION]… OCTAL-MODE FILE…
chmod [OPTION]… –reference=RFILE FILE…

File permission
Number Permission Type Symbol
0 No Permission
1 Execute –x
2 Write -w-
3 Execute + Write -wx
4 Read r–
5 Read + Execute r-x
6 Read +Write rw-
7 Read + Write +Execute rwx

Example

View your files, regardless of the access rights

ls -alt

Regardless of the file’s access rights, you can use this command to view your files.
Enable groups and other users to have read and write access to files

chmod 066 SMTPTester.py

Allow all users to have read, write, and execute permissions on the file
chmod 777 SMTPTester.py

chgrp

chgrp (change group ownership) command is used to change the group to which a file or directory belongs. This is an administrator command. Only administrator users can change the group to which the file or directory belongs.

SYNOPSIS

chgrp [OPTION]… GROUP FILE…
chgrp [OPTION]… –reference=RFILE FILE…