How to Change Permissions and Ownership in Linux: A Comprehensive Guide

How to Change Permissions and Ownership in Linux: A Comprehensive Guide

How to Change Permissions and Ownership in Linux: A Comprehensive Guide

Properly managing Linux file permissions and ownership is essential for safety, especially when multiple administrators manage one server. Moreover, using the correct settings ensures your server can run properly.

Overview of Changing Linux Permissions

The commands for changing file and directory permissions are the same. Here are some of the most popular ones:

  • chmod +rwx item – adds read, write, and execute permissions.
  • chmod -rwx item – removes all permissions from an item.
  • chmod +r item – grants the read permission over an item.
  • chmod -x item – prevents all users from executing the item.

You can further fine-tune the permission settings for different users. We’ll explain it more in the following sections.

Understanding the Linux Permissions Model

Linux operating systems have three classes to which you can grant permissions and ownership:

  • owner – a user that possesses the file or folder.
  • group – multiple users that belong to the same category.
  • others – all users who are neither the owner nor the group member.

Files and folders in Linux have three types of permissions:

  • read (r) – allows users to view the content of a file or directory.
  • write (w) – lets users edit a file’s content. For directories, they can create, delete, and move files within the folder.
  • execute (x) – enables users to run a file. Executable permissions over a folder mean users can open it and gain access to all its data.

Viewing Current Permissions

To view files and folders permission in your current working directory, run the following command:

ls -l

If you want to check only a specific item, enter this command:

ls -l itemname

The output will show the permissions and ownership information of the item.

Changing Permissions with chmod

To change item permissions, use the chmod Linux command. The syntax looks like the following:

chmod [option] [mode] [file_folder_name]

Option is an additional flag that modifies your chmod command behavior. Mode is the new permissions for the file or folder, which you can write in symbolic or numeric notation.

Symbolic Mode

The symbolic method in chmod uses a single character representing the user class, permissions, and operations. For example, to add write and execute permissions to the item’s owner, you can use chmod u+wx item. Symbolic mode is more flexible and descriptive.

Numeric (Octal) Mode

The numeric mode uses three-digit numbers to determine the new permissions. For example, to set read, write, and execute permissions for the owner, write chmod 764 item. Numeric notation is more straightforward than symbolic.

Recursive Permission Changes

The chmod -R option enables the recursive mode, which lets you set new permissions to a folder and all its content using a single command.

Changing Ownership with chown and chgrp

In Linux, you can change the ownership of an item using the chown or chgrp command. Chown is the more common command, which lets you change the ownership to both users and groups. Chgrp only lets you change the ownership to another group.

Special Permission Bits

In addition to read, write, and execute permissions, Linux has additional permissions that give you more control over items on your system. These include setuid, setgid, and sticky bit.

Conclusion

Setting the proper permissions and ownership of items is crucial for server security and functionality. In Linux, you can grant read, write, and execute permissions to three user classes: owner, group, and others. To change permissions in Linux, use chmod followed by the settings and items you want to modify. Use chown to change an item’s ownership to another user or group, and chgrp to change the ownership to another group.

Change Permissions Linux FAQ

What command is used to change permissions in Linux?

To change a file or folder’s permissions in Linux, use the chmod command. The syntax is chmod [option] [mode] [item]. Option modifies your command behavior, mode specifies the new permissions, while item refers to the file or folder you want to modify.

How do I view the current permissions of a file?

To view the current permissions of a file, run ls -l filename, with filename being the actual name of the file you want to check. You can also run ls -l to see permissions of all files and folders in the current directory.

What does chmod stand for in Linux?

In Linux, the chmod command stands for change mode. It lets you modify a file or folder’s permission, allowing different users to read, write, or execute it.

👉
Start your website with Hostinger – get fast, secure hosting here
👈


🔗 Read more from MinimaDesk:


🎁 Download free premium WordPress tools from our Starter Tools page.

How to Change the Author in WordPress: A Step-by-Step Guide
Understanding Mobile Commerce: A Guide for Online Business Owners
My Cart
Wishlist
Recently Viewed
Categories