29th June 2022

Using “Chmod +x” Command on Linux and Unix with Examples

In Linux systems, “chmod” command is used to determine the access rights of users to files. It allows us to change the access permissions of the files we specify. The exact equivalent of chmod is change mode.

When we examine the example below; We can sort it as a user, group and other from left to right, which comes in 3 blocks after the first character. Access permissions are always given in the form of rwx. If there is a “-” sign instead of rwx, it means that the permission is not allowed in the place coming to that section. Linux Users There are 3 user types. These;

(Type) | (user) | (group) | (other)

– | – – – | – – – | – – –

User Types
User Types

 

u – user (file or directory owner, creator)
g – group (the group to which the file or directory belongs)
o – other (other than user and group)
a – all (user, group, other) (all, anyone can access files and directories.)

How can I view the chmod permissions?

You can use the “ls -all” command to see the chmod permissions on a directory or file. File operations are divided into reading, write and execute.

r – Read permission: Authorization to read the file. This privilege also has the ability to list all files in that directory when given for a directory.

w – Write permission: Authorization to create, change or delete a file.

x – Execute permission: Many users can read many files on Linux systems. However, it must also have the authorization to run it.

Note: Only the owner or a more authorized user can change the authority of a file.

ls -all
ls -all

 

File types

The first character indicates the type of file. We can list the types of file as follows.

File types
File types

 

– : A normal file
d : Directory
b : Custom block file
c : Special character file
l : Symbolic link file
P : Specially named pipe file

Chmod Permissions with Numbers

Chmod permissions can be either letters or numbers.

000: r (No right to read), w (No write right), x (No right to work):
—: chmod value is 0
001: r (No right to read), w (No write right), x (Right to work)
– -x: chmod value 1
010: r (No right to read), w (Write right), x (No work right)
-w-: chmod value 2
011: r (No right to read), w (Write right), x (Right to work)
-wx: chmod value 3
100: r (Read right), w (No write right), x (No work right)
r- -: chmod value 4
101: r (Right to read), w (No write right), x (Right to work)
r-x: chmod value 5
110: r (Read right), w (Write right), x (No work right)
rw-: chmod value 6
111: r (have the right to read), w (have the right to write), x (have the right to work)
rwx: chmod value 7

Chmod Permissions with Numbers
Chmod Permissions with Numbers

 

Chmod Operators

You can see the Operators for chmod permissions as follows.

: remove chmod permission.
+ : add chmod permission.
= : set chmod permission.

Note: The file owner, parent and root user can change the chmod access permission of a file and directory.

Some examples of chmod

rwx: Read, write and run access permissions are all available.
rw-: Read and write permissions, no permission to run.
r-x: Read and run permissions, no permission to write.
-wx: No permission to reading, write and run permissions.
r–: Only has the right to read.
-w-: It only has the right to write.
–x: Only have the right to run.
—: No access rights.

LEARN MORE  How to Install Persistent Kali Linux on USB?

Example 1: “chmod +r” Command

chmod +r filename: We have given read permission to the file.

chmod +r
chmod +r

 

Example 2: “chmod u=rw,go=” Command

chmod u=rw,go= filename: We gave read and write permission to the file owner. We removed all access permissions for the group and others.

chmod u=rw,go=
chmod u=rw,go=

 

Example 3: “chmod +x” Command

chmod +x filename: We gave the file run permission for all users (user, group, other).

chmod +x
chmod +x

 

Example 4: “chmod +rw” Command

chmod +rw filename: We have given read and write permissions for the user issuing the command, read-only permissions for the group and others.

chmod +rw
chmod +rw

 

Example 5: “chmod 0” Command

chmod 0 filename: We removed all users access permissions for the file.

chmod 0
chmod 0

 

Example 6: “chmod 666” Command

chmod 666 filename: We have given read and write permissions for all users.

chmod 666
chmod 666

 

Example 7: “chmod 0755 or chmod 755” Commands

chmod 0755 or chmod 755 filename: It doesn’t matter if this command is written in two different ways. His task is the same. It gives read, writes and execute rights to the file owner and read and execute rights for the group and others.

chmod 755
chmod 755 or chmod 0755

 

Example 8: “chmod ugo-rwx” Command

chmod ugo-rwx filename: We have removed all access permissions for the file. chmod 0 or chmod 000 do the same.

chmod ugo-rwx
chmod ugo-rwx

 

Example 9: “chmod go-rw” Command

chmod go-rw filename: We removed the read and write rights of the group and other users on the file.

chmod go-rw
chmod go-rw

 

LEARN MORE  What is Searchsploit and Its Use

Example 10: “chmod –R u + r” Command

chmod –R u + r Download: We have given read permission to its user for all files and directories under the directory named Download. With the -R (recursive) parameter, the chmod access permission of all files and directories under the relevant directory is changed in the same way.

chmod -R u+r
chmod -R u+r

 

Example 11: “chmod a + rwx and chmod 777” Commands

chmod a + rwx and chmod 777 filename: Two different commands but the same functions. It ensures that all users have read, write and run rights on the relevant file.

chmod 777
chmod 777

 

Example 12: “chmod go + r” Command

chmod go + r filename *: (*) gives permission to read all files that start with the trial with wildcard parameter by the group and other (other) users.

chmod go+r test*
chmod go+r test*

 

Example 13: “chmod go-rwx * or chmod 700 *” Commands

chmod go-rwx * or chmod 700 *: Used when inside a directory. Read, write and run access permissions for the group and other users are removed from all files and subdirectories in the directory where it is used.

chmod 700 *
chmod 700 *

 

LEARN MORE  Creating a New User Account on Windows 10

Example 14: “chmod u = rw, go =” Command

chmod u = rw, go = filename: This example, we removed the user’s right to run, reserving the read and write rights. We have also removed run, write and read rights in group and others.

chmod u=rw,go=
chmod u=rw,go=

 

Example 14: “chmod –reference=file_x file_y” Command

chmod –reference=file_x file_y: Lastly, it is a useful parameter that we use a lot. It also applies the permissions of file_x to file_y.

chmod --reference=
chmod –reference=

 

Umask

Returns the system default file creation mask value. The default value of umask is 0002. The first character of this value makes no sense. Other characters indicate the file permission according to the base octal.

umask u = rw, go =

This definition indicates that, by default, the files opened in the system are read and write for the user, and group and other users are unauthorized.

Note: Files created using the sudo command are owned by root and access to the file belongs only to root privileges.

 

Leave a Reply

Your email address will not be published. Required fields are marked *