This is a quick reference guide on to use the chmod command on Linux Based Operating Systems.
- chmod General
chmod options permissions file name
chmod u=rwx,g=rx,o=r file1
u = user
g = group
o = other
r = read
w = write
x = execute
So in the example above – the user has read, write, and execute permissions, group has read and execute and other have read only.
2. chmod Octal
chmod 751 file1
4 = read
2 = write
1 = execute
0 = no permission
So in the example above – the user has read, write, and execute permissions, group has read and execute and other have execute only. (user) 4+2+1= 7, (group), 4+1=5, (other) 1 = 1
3. Check file permission using ls -l
root@vps:~# chmod 751 file1 root@vps:~# ls -l file1 -rwxr-x--x 1 root root 0 Jun 3 08:17 file1
A dash (-) indicates that the file is a regular file.
The letter (d) indicates that the file is a directory as per below:
A letter (l) preceding indicates a special file type called a symlink. A symlink is a pointer to another location in the file system.
drwxr-xr-x 3 root root 4096 Oct 18 2018 ufw
The first three letters above refer to the permission of the user so in this case rwx, so read, write, and execute.
The next three letters is for group r-x, so read and execute, but not write as indicated by the dash.
The next three letters is for other r-x, so read and execute, but not write as indicated by the dash. (so the same as group in this example)
The number 3 in this example after the permissions indicates the number of files or sub-directories contained within this particular directory.
The first name after the number (directory and file number) in the example below is the user or file owner. “vpsuser”
The second name refers to the files group. “group1”
-rwxr-x--x 1 vpsuser group1 0 Jun 3 08:17 file1 root@vps:~#
The remainder of the file details are the size of the file, the date and time that the file was created or last modified, and the file name.
Thank you for reading and please feel free to leave any feedback.