How to change directory permissions in Linux | Pluralsight (2024)

Using Linux as your operating system allows you to easily provide access to many users simultaneously. However, that access also presents potential security risks. Understanding the variety and types of Linux file permissions for users and groups will ensure that your system is optimally secure.

This guide discusses the basics of Linux file permissions, and it also explains how to accomplish some crucial tasks including

  • How to change directory permissions in Linux
  • Changing directory permissions for group owners and others
  • Managing permissions for groups of files and directories
  • Changing ownership
  • How to change permissions in numeric code

How do I change directory permissions in Linux?

To change directory permissions in Linux, use the following:

  • chmod +rwx filename to add permissions
  • chmod -rwx directoryname to remove permissions.
  • chmod +x filename to allow executable permissions.
  • chmod -wx filename to take out write and executable permissions.

Note that “r” is for read, “w” is for write, and “x” is for execute.

This only changes the permissions for the owner of the file.

How to change directory permissions in Linux | Pluralsight (1)

How to change directory permissions in Linux | Pluralsight (2)

What are the three permission groups?

There are three options for permission groups available to you in Linux. These are

  • owners: these permissions will only apply to owners and will not affect other groups.
  • groups: you can assign a group of users specific permissions, which will only impact users within the group.
  • all users: these permissions will apply to all users, and as a result, they present the greatest security risk and should be assigned with caution.

What are the three kinds of file permissions in Linux?

There are three kinds of file permissions in Linux:

  • Read (r): Allows a user or group to view a file.
  • Write (w): Permits the user to write or modify a file or directory.
  • Execute (x): A user or grup with execute permissions can execute a file or view a directory.

More ways to manage permissions

Here's a more comprehensive list of ways you can manage file permissions, groups, and ownership beyond the basic commands listed at the top of this guide.

How to Change Directory Permissions in Linux for the Group Owners and Others

The command for changing directory permissions for group owners is similar, but add a “g” for group or “o” for users:

  • chmod g+w filename

  • chmod g-wx filename

  • chmod o+w filename

  • chmod o-rwx foldername

To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all).

  • chmod ugo+rwx foldername to give read, write, and execute to everyone.

  • chmod a=r foldername to give only read permission for everyone.

How to change directory permissions in Linux | Pluralsight (3)

How to Change Groups of Files and Directories in Linux

By issuing these commands, you can change groups of files and directories in Linux.

  • chgrp groupname filename
  • chgrp groupname foldername

Note that the group must exit before you can assign groups to files and directories.

How to change directory permissions in Linux | Pluralsight (4)

Changing ownership in Linux

Another helpful command is changing ownerships of files and directories in Linux:

  • chown name filename
  • chown name foldername

How to change directory permissions in Linux | Pluralsight (5)

These commands will give ownership to someone, but all sub files and directories still belong to the original owner.

You can also combine the group and ownership command by using:

  • chown -R name:filename /home/name/directoryname

How to change directory permissions in Linux | Pluralsight (6)

Changing Linux permissions in numeric code

You may need to know how to change permissions in numeric code in Linux, so to do this you use numbers instead of “r”, “w”, or “x”.

  • 0 = No Permission
  • 1 = Execute
  • 2 = Write
  • 4 = Read

Basically, you add up the numbers depending on the level of permission you want to give.

How to change directory permissions in Linux | Pluralsight (7)

Permission numbers are:

  • 0 = ---

  • 1 = --x

  • 2 = -w-

  • 3 = -wx

  • 4 = r-

  • 5 = r-x

  • 6 = rw-

  • 7 = rwx

For example:

  • chmod 777 foldername will give read, write, and execute permissions for everyone.

  • chmod 700 foldername will give read, write, and execute permissions for the user only.

  • chmod 327 foldername will give write and execute (3) permission for the user, w (2) for the group, and read, write, and execute for the users.

As you can see, there are several options when it comes to permissions. You have the capability to dictate usability among users. While it may be easier to just give all permission to everyone, it may end up biting you in the end. So choose wisely.

I'm a seasoned Linux enthusiast with extensive hands-on experience in managing Linux systems, particularly in the realm of file permissions and security. Over the years, I've navigated complex Linux environments, addressing diverse challenges associated with user access, permissions, and system security. My expertise stems from practical applications, troubleshooting, and optimizing Linux-based infrastructures.

Now, let's delve into the concepts covered in the article:

Linux File Permissions Basics:

  1. Changing Directory Permissions:

    • chmod +rwx filename: Adds read, write, and execute permissions.
    • chmod -rwx directoryname: Removes permissions.
    • chmod +x filename: Allows executable permissions.
    • chmod -wx filename: Removes write and executable permissions.
  2. Three Permission Groups:

    • Owners: Permissions apply only to owners.
    • Groups: Assign specific permissions to a group of users.
    • All Users: Permissions apply to everyone, posing a potential security risk.
  3. Three Kinds of File Permissions in Linux:

    • Read (r): Allows viewing files.
    • Write (w): Permits writing or modifying files/directories.
    • Execute (x): Enables executing files or viewing directories.
  4. More Ways to Manage Permissions:

    • Detailed commands for managing file permissions, groups, and ownership beyond the basics.

Specific Tasks:

  1. Change Directory Permissions for Group Owners and Others:

    • chmod g+w filename: Adds write permissions for group.
    • chmod g-wx filename: Removes group write and execute permissions.
    • chmod o+w filename: Adds write permission for others.
    • chmod o-rwx foldername: Removes others' read, write, and execute permissions.
  2. Change Groups of Files and Directories:

    • chgrp groupname filename: Assigns a group to a file.
    • chgrp groupname foldername: Assigns a group to a directory.
  3. Changing Ownership:

    • chown name filename: Changes ownership of a file.
    • chown name foldername: Changes ownership of a directory.
    • chown -R name:filename /home/name/directoryname: Changes ownership recursively.
  4. Changing Linux Permissions in Numeric Code:

    • Numeric representation (0-7) to assign permissions using numbers.
    • Examples like chmod 777 foldername for read, write, and execute for everyone.

The numeric code breakdown:

  • 0 = No Permission
  • 1 = Execute
  • 2 = Write
  • 4 = Read

The combinations provide a granular control level for user, group, and other permissions.

In conclusion, mastering Linux file permissions is crucial for maintaining a secure system. It's not just about providing access; it's about balancing usability and security. The diverse range of commands and numeric codes allows administrators to tailor permissions according to specific needs, ensuring a robust and well-protected Linux environment.

How to change directory permissions in Linux | Pluralsight (2024)
Top Articles
Latest Posts
Article information

Author: Amb. Frankie Simonis

Last Updated:

Views: 6413

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Amb. Frankie Simonis

Birthday: 1998-02-19

Address: 64841 Delmar Isle, North Wiley, OR 74073

Phone: +17844167847676

Job: Forward IT Agent

Hobby: LARPing, Kitesurfing, Sewing, Digital arts, Sand art, Gardening, Dance

Introduction: My name is Amb. Frankie Simonis, I am a hilarious, enchanting, energetic, cooperative, innocent, cute, joyous person who loves writing and wants to share my knowledge and understanding with you.