In the process of using Linux, not everyone has used the chmod command. Especially for users who perform operations with folders and files or encounter errors without permission. However, those who are new to Linux will not know chmod. The following article BKNS will send to you What is Chmod?? Instructions for using Chmod Linux.
>> Learn more: Basic Commands in Linux
1. What is Chmod?
Chmod (full name is Change Mod) in Linux operating system is the command used to change the permissions of the object file system (files and directories).
1.1 Syntax of chmod command in linux
chmod [options] mode [mode] file1 file2 file3 ....
1.2 List of options
- -v: verbose, display processed object
- -f: force, set permissions in case of an error
- -R: Recursive, applies to all files and folders inside
If it is a symbolic link, the target object will be affected.
# | Permission | rwx | Binary |
7 | read, write and execute | rwx | 111 |
6 | read and write | rw- | 110 |
5 | read and execute | r-x | 101 |
4 | read only | r– | 100 |
3 | write and execute | -wx | 011 |
2 | write only | -w- | 010 |
1 | execute only | –x | 001 |
0 | none | — | 000 |
CEO: In case mode = 777 (Alphanumeric type)
- With folder => drwxrwxrwx
- With file => -rwxrwxrwx
– The first character is the letter [d] then folder, if it's a dash [–] then it's file
– The next 3 characters are the owner's read, write, and execute permission (File/folder creator)
– The next 3 characters are read, write and execute permissions of Owner Group (Group of file/folder creator)
– The last 3 sequences are the read, write, and execute permissions of EveryOne (All remaining users)
2. Install chmod in cpanel
Step 1: Login to cPanel site admin account
Step 2: choose "File Manager”.
Then the interface of “File Manager”
Step 3: Set chmod
- Set chmod command for each file or folder: click on column "Perms" or select "Change Permissions” by right clicking, then change the parameters.
- Set the chmod command for the entire folder or file: choose "Select all, then right click and select “Change Permissions, proceed to customize
2. Instructions for using chmod on Linux
2.1 View and understand file permissions
You can use option -l (long format) to get a list ls file permissions for files and folders.
ls -l
On each line, the first character identifies the type of entry being enumerated. If it is a dash (–) then it's 1 file. But if it's a word d then it is a directory.
The next 9 characters represent the settings for the 3 sets of permissions.
- First 3 characters: shows the permissions for the user who owns the file. (user rights)
- 3 characters in between: visible to the members of the file group.
- Last 3 characters: shows for permissions for anything that isn't in the first 2 items (the others).
There are 2 characters in a permission set. The characters are indicators for the presence or absence of 1 of the permissions. They are dashes (-) or letters. If it is a dash then the permission is not granted. If the character is r,w there are x then the right is granted.
The letters represent:
- r : read permission. The file can be opened, and its contents viewed.
- w : write permission. Files can be edited, modified and deleted.
- x : execute permission. If the file is a script or a program, it can be run (executed).
Eg:
- — means no permissions are granted at all.
- rwx means full permission has been granted. Read, write and execute metrics are all present.
In our screenshot, the first line starts with a d . This line refers to a folder named “archive". The owner of the folder is “dave, the name and name of the group to which the folder belongs is also called “dave”.
- The next three characters are the user permissions for this folder. These show that the owner has full rights. The characters r , w and x are all present. This means that the user has read, write, and execute permissions for that directory.
- The second set of three characters are group permissions, these are rx . They show that members of the dave group have read and execute permissions for this directory. That means they can list files and their contents in the directory and they can cd (executable) into that directory. They don't have write permissions, so they can't create, edit, or delete files.
- The last three characters are also rx . These rights apply to people who are not covered by the first two sets of rights. These people (called other people) have read and execute permissions on this directory.
So to summarize, group members and others have read and execute permissions. The owner, a user called dave, also has write permissions.
For all other files (apart from the mh.sh script file), dave and members of the dave group have read and write attributes on the files, and the other files have read-only permissions.
For the special case of the mh.sh script file, owner dave and team members have read, write and execute permissions and others only read and execute permissions.
2.2 Setting and modifying permissions
Let's say you have a file that everyone has full permissions on.
ls -l new_ file.txt
If you want users to have read and write permissions, other groups of objects or users to have read only, you can do so by using the following command:
chmod u = rw, og = r new_file.txt
Using the “=” operator means you have the power to wipe any existing permissions and then set the specified ones.
Check for new permissions on the following file:
As shown in the image above, the existing permissions have been deleted and the new permissions have been reset.
To perform the addition of permissions without removing the existing permission settings, you can do the following:
Let's say you have a script file that you've finished editing. You need to make it for all users. Its current permissions will be as follows:
ls -l new_script.sh
You can add execute permission for everyone with the following command:
chmod a + x new_script.sh
If you look at the permissions, you'll see that execute permissions are now available to everyone, and the existing permissions are still in effect.
ls -l new_script.sh
The following commands can also do this:
chmod + x new_script.sh
2.3 Check file/folder permissions
ls -l /duong-dan-file-hoac-folder
So the article on BKNS has provided you What is chmod? Instructions for using Chmod Linux. If you have any questions about this article, please leave a comment below for support. Don't forget to visit the website https://www.bkns.vn/ for more useful information.
My name is Thinh Hanh, currently the CEO of BKNS. I will provide you with information technology services and network solutions in the fastest and most effective way.
Post a Comment
Post a Comment