Chmod (change mode) is a command in Linux that allows you to modify the permissions of a file or directory. This command enables you to grant various access levels to users, such as read and write permissions to one user and read-only permissions to another. Additionally, the chmod (change mode) is a command in Linux that allows you to modify the permissions of a file or directory as required.
| User | u | The owner of the file or directory |
| Group | g | Multiple users with the same permissions. |
| Others | o | other users who are neither the owner nor a member of a group |
The owners can have any combination of the following access permissions assigned:
|
Permission |
Symbolic |
Octal |
Description |
|
Read |
r |
4 |
Permission to read, copy from the directory. |
|
Write |
w |
2 |
Permission to write/edit, delete, and add new files to a directory. |
|
Execute |
x |
1 |
Permission to execute file/directory. |
|
No permission |
- |
0 |
no permission set. |
chmod 400
Chmod 400 (chmod a+rwx,u-wx,g-rwx,o-rwx) is a set of permissions where (U)ser / owner can read, can't write and can't execute. (G)roup can't read, can't write and can't execute. (O)thers can't read, can't write and can't execute.
Using the chmod command with the argument "400" grants only the owner or user of the file read permission while restricting everyone else entirely. This method is frequently used to secure an SSH private key. After generating the file, you can safeguard it further by applying chmod 400 to limit access to the owner.

Example: If you wish "nicktest.txt" can only be read by the owner "nick" and not written or executed while also restricting both the group and others from accessing it all together, you can run the following command:
# chmod 400 nicktest.txt

You can see that the owner has read permission for the file, which implies that solely the owner can read its contents. No other user, including the group and others, can't read, write, or execute the file. Additionally, the owner is also unable to modify or run the file.
Conclusion:
Chmod is a powerful command, mainly when used with the sudo command. It's crucial to ensure you instruct the system to execute precisely what you intend; otherwise, modifying incorrect permissions can cause significant harm.
If you're uncertain, hone your skills on a virtual machine before altering permissions on the server or system. This approach can help you avoid making inadvertent errors that may lead to severe consequences.