Gaming industry under DDoS attack. Get DDoS protection now. Start onboarding
  1. Home
  2. Developers
  3. How to Manage File Permissions on Linux Using chmod

How to Manage File Permissions on Linux Using chmod

  • By Gcore
  • October 11, 2023
  • 2 min read
How to Manage File Permissions on Linux Using chmod

In the world of Linux, ensuring the right people have access to the right files is paramount to system security and functionality. The chmod command stands as a pivotal tool in this arena, allowing users to modify file permissions with precision. This article provides a comprehensive guide on using chmod to manage file permissions, ensuring both the security and accessibility of your Linux system’s data.

What is File Permission

File permissions determine who can read, write, and execute files and directories in a filesystem. They are essential for maintaining the security and proper functioning of file systems, especially in multi-user environments like Unix and Linux.

In Unix-like operating systems, there are three basic types of permissions:

  1. Read (r): Grants the capability to read the contents of a file or list the contents of a directory.
  2. Write (w): Grants the capability to modify a file or add, remove, and rename files in a directory.
  3. Execute (x): Grants the capability to run a file as a program or enter and search a directory.

File permissions are defined for three types of users:

OwnerThe individual user who owns the file or directory
GroupUsers belonging to the file’s group can have different permissions from those of the owner and others. A file or directory belongs to a single group.
OthersAll other users who are not the owner or part of the group.

Understanding and managing file permissions is essential for ensuring system security, preventing unauthorized access, and enabling collaboration in multi-user environments. In the next section, let’s take a look at how to manage file permissions using the chmod command.

Process on Managing File Permissions on Linux

Here’s a step-by-step guide on managing file permissions on Linux using the chmod command, complete with descriptions and sample outputs.

#1 View Current Permissions

Before modifying permissions, it’s helpful to view the current permissions on a file or directory.

ls -l filename

Sample Output:

-rwxr-xr-x 1 user group 1234 Oct 10 10:00 filename

#2 Grant Execute Permission to the Owner

Add execute permission for the file’s owner.

chmod u+x filename

#3 Remove Write Permission for the Group

Remove write permission for the file’s group.

chmod g-w filename

#4 Set Specific Permissions Using Numeric Values

Set permissions using numeric values (octal notation). The numbers represent permissions as: 4 for read (r), 2 for write (w), and 1 for execute (x). The value is the sum of those numbers.

For example, to give the owner read/write/execute, the group read/execute, and others only read permissions:

chmod 755 filename

#5 Grant All Permissions to Everyone

Give read, write, and execute permissions to everyone.

chmod 777 filename

#6 Recursive Change for Directories

If you want to change permissions for a directory and all its contents, you can use the -R option for recursion.

chmod -R 755 directoryname

#7 Set Permissions for Files and Directories Differently in a Single Command

Useful when you want files and directories to have different permissions within a directory structure. The find command can be utilized in conjunction with chmod.

To set all directories to 755 (drwxr-xr-x):

find /path/to/base/dir -type d -exec chmod 755 {} 

To set all files to 644 (-rw-r–r–):

find /path/to/base/dir -type f -exec chmod 644 {} +

That’s it! Now you’re equipped to manage file permissions on Linux. By understanding and applying the chmod command as detailed above, you’ll gain granular control over the file and directory permissions on your Linux system.

Conclusion

Looking to deploy Linux in the cloud? With Gcore Cloud, you can choose from Basic VM, Virtual Instances, or VPS/VDS suitable for Linux:

Choose an instance

Related articles

What's the difference between multi-cloud and hybrid cloud?

Multi-cloud and hybrid cloud represent two distinct approaches to distributed computing architecture that build upon the foundation of cloud computing to help organizations improve their IT infrastructure.Multi-cloud environments involve us

What is multi-cloud? Strategy, benefits, and best practices

Multi-cloud is a cloud usage model where an organization utilizes public cloud services from two or more cloud service providers, often combining public, private, and hybrid clouds, as well as different service models, such as Infrastructur

What is cloud migration? Benefits, strategy, and best practices

Cloud migration is the process of transferring digital assets, such as data, applications, and IT resources, from on-premises data centers to cloud platforms, including public, private, hybrid, or multi-cloud environments. Organizations can

What is a private cloud? Benefits, use cases, and implementation

A private cloud is a cloud computing environment dedicated exclusively to a single organization, providing a single-tenant infrastructure that improves security, control, and customization compared to public clouds.Private cloud environment

What is a cloud GPU? Definition, types, and benefits

A cloud GPU is a remotely rented graphics processing unit hosted in a cloud provider's data center, accessible over the internet via APIs or virtual machines. These virtualized resources allow users to access powerful computing capabilities

What is cloud networking: benefits, components, and implementation strategies

Cloud networking is the use and management of network resources, including hardware and software, hosted on public or private cloud infrastructures rather than on-premises equipment. Over 90% of enterprises are expected to adopt cloud netwo

Subscribe to our newsletter

Get the latest industry trends, exclusive insights, and Gcore updates delivered straight to your inbox.