How to Change Permissions on Mounted Drive in Linux

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

If you have a mounted drive, you might run into some issues such as being unable to read, write, or execute files on your drive properly. Most of the time the problem is associated with permissions and you are required to change the drive permissions. In this article, I will explain how to change permissions on a mounted drive in Linux.

Process flow chart to change permissions on mounted drive in Linux:Flow chart for "change permissions on mounted drive in Linux"

[Distro Used in changing permission on mounted drive in Linux is Ubuntu 22.04.1 LTS]

3 Steps to Change Permissions on A Mounted Drive in Linux

In this section, I will show you all the steps to change the permissions of a mounted drive in Linux. First, I will check all the available drives, then change the permissions of a drive and finally verify whether the process worked. The last step is optional. Go here to know more related to this topic.

Step 01: View Current Permissions of Mounted Drives in Linux

Firstly, list all the mounted drives. Then print permissions of a particular mounted drive. To do that, follow the steps below:

  1. Launch an Ubuntu Terminal.

  2. Paste the following command in the command prompt:

    df
    EXPLANATION
    • df: Shows used and available space on each disk partition.
  3. Hit ENTER.Showing mounted drivesHere “/dev/sda” refers to physical disks as HDD(Hard Disk Drive) or SSD(Solid State Drive). On the other hand, “tmpfs” are virtual file systems used to store temporary files.

  4. Write the following command to view permissions of the mounted drive “/dev/sda3”:
    ls -l /dev/sda3
    EXPLANATION
    • ls: Lists contents of a directory
    • -l: Shows detailed information like permissions, and ownership.
    • /dev/sda3: A mounted drive.
  5. Press ENTER.Showing permissions of a mounted drive for "change permissions on mounted drive in Linux"

    EXPLANATION
    The permission of a mounted drive is a set of 10 characters. The first character (here “b”) denotes file type. The last 9 characters represent permissions for Owner, Group and Others; 3 characters for each. Now let’s see what different character denotes

    • b: Block device, which transfers data in blocks (for instance -Hard Disk).
    • r: Reading
    • w: Writing
    • x: Executing
    • : No permission.

Step 02: Change Permission on Mounted Drive in Ubuntu

Now I will change the permissions of the mounted drive “/dev/sda3”. I will provide reading, writing, and executing permissions to the “owner” and “group”. Now do the following:

  1. Press CTRL+ALT+T to launch an Ubuntu Terminal.
  2. Copy the following command in the command prompt and hit ENTER:
    sudo chmod u=rwx,g=rwx,o= /dev/sda3
    EXPLANATION
    • sudo: Grants root privileges.
    • chmod: Changes permissions.
    • u=rwx,g=rwx,o= : Reading, Writing and executing permissions for Owner and Group. However, no permission for Others.
    • /dev/sda3: A mounted drive.
  3. Type your password.
  4. Press ENTER.
    Change permissions on a mounted drive in Linux

Step 03: Verify Permissions of Mounted Drive

Finally, I will verify whether the permissions have changed or not. You can do that by following the simple steps below:

  1. Firstly, open an Ubuntu Terminal.
  2. Type the following command in the Terminal:
    ls -l /dev/sda3
    EXPLANATION
    • ls: Lists contents of a directory.
    • -l: Shows detailed information like permissions, and ownership.
    • /dev/sda3: A mounted drive.
  3. Hit the ENTER button.Checking permissions for "change permissions on mounted drive in Linux"


How to Change Ownership of Mounted Drive from Root in Ubuntu

To change the ownership of a drive, you need to use the chown command. For example, the owner of the drive “/dev/sda3 ” is “root” and you want to change it to “walid “. Do it by the following:

  1. Open a Ubuntu Terminal by pressing CTRL+ALT+T.
  2. Copy the following command in the Terminal and press ENTER:
    sudo chown walid /dev/sda3
    EXPLANATION
    • sudo: Grants root privileges.
    • chown: Changes ownership.
    • walid: Username of the new Owner.
    • /dev/sda3: A mounted drive.
  3. Provide your password and hit ENTER again.Changing ownership
  4. Finally, to check the new Owner, write the following command and press ENTER:
    ls -l /dev/sda3
    EXPLANATION
    • ls: Lists contents of a directory
    • -l: Shows detailed information like permissions, ownership.
    • /dev/sda3: A mounted drive.
    Showing new ownerAs you can see, the new Owner is “walid” instead of “root”.

How to Mount with Write Permissions in Linux

Every drive has a mount point. Here I will unmount a drive first. Then I will mount it with write permissions to another point. Follow the steps below with me:

  1. At the beginning, launch a Terminal in Ubuntu.
  2. Insert the following command to view mount points and hit ENTER:
    df
    EXPLANATION
    • df: Shows space usage.
    Displaying mount pointsI will choose the drive “/dev/sda2” which is mounted on point “/boot/efi” for demonstration purposes.
  3. Copy the command below to unmount point “/boot/efi” and press ENTER:
    sudo umount /boot/efi
    EXPLANATION
    • sudo: Grants elevated privileges.
    • umount: Detaches a drive from a mounted point.
    • /boot/efi: Mounted point for drive “/dev/sda2”.
    Unmounting a mount point
  4. Now run the following common to mount /dev/sda2” to “/mydirectory” with reading and writing permissions:
    sudo mount -o rw /dev/sda2 /mydirectory
    EXPLANATION
    • sudo: Provides root privileges.
    • mount: Attaches a drive to a particular mount point.
    • -o: This option is used to specify additional mount options.
    • rw: Gives reading and writing permissions.
    • /dev/sda2: A Drive.
    • /mydirectory: The mount point.
  5. Finally to check the permissions of the mount point, use the command below:
    mount -v | grep /mydirectory
    EXPLANATION
    • mount: Attaches a drive to a particular mount point.
    • -v: Enables verbose mode.
    • Pipe(|): Redirects the output of a command to another.
    • grep: Searches for a given pattern.
    • /mydirectory: A mounted point.
    Showing permissions of a mount point
    EXPLANATION

    The mount command with the verbose mode is used to show all the mounted file systems. Then grep command searched for “/myfolder” in the output. On the terminal, it is showing all the information regarding mount point “/myfolder” where the “rw” denotes reading and writing permissions.

Change File Permissions in Linux

You need to use the chmod command to change the permissions of a regular file as well. The steps are simple, do the following:

  1. Press CTRL+ALT+T to open a Terminal in Ubuntu.
  2. Write the following command to give writing permissions to the user:
    sudo chmod u+x myfile.txt
    EXPLANATION
    • sudo: Grants root privileges.
    • chmod: Changes ownership.
    • u+x: Provides executing permission to Owner.
    • myfile.txt: Name of a file.
    Change permissions on mounted drive of a regular file in Linux
  3. Now insert the command below to see new permissions:
    ls -l myfile.txt
    EXPLANATION
    • ls: Shows contents of a directory.
    • -l: Prints detailed information.
    New permissions of the regular fileIn the image, it is showing “x” in place of “” for the user permissions. This indicates that the user has execution permission now.


How to Change Permission to an External Hard Drive in Ubuntu

The second hard drive in Linux is an additional disk drive that provides extra storage. Its name goes like “/dev/sdb”. Here I have used a pendrive as a second hard drive and I will change its permissions. You can do that by following the steps below:

  1. At first, open an Ubuntu Terminal.
  2. Paste the following command to print all the drives and hit ENTER:
    df
    EXPLANATION
    • df: Prints space usage.

    There are two second hard drives here, sdb1 and sdb2. Let’s change the permissions of sdb1.

  3. Insert the following command to view permissions of drive “/dev/sdb1” and press ENTER:
    ls -l /dev/sdb1
    EXPLANATION
    • ls: Lists files and folders in a directory.
    • -l: Shows detailed information like permissions and ownership.
    • /dev/sdb1: A second drive.
    Printing second hard drivesNo one has any permissions here.
  4. Run the command below to provide reading, writing, and executing permissions to the user:
    sudo chmod u=rwx /dev/sdb1
    EXPLANATION
    • sudo: Grants elevated privileges.
    • chmod: Changes permissions.
    • u=rwx: Proving Owner reading, writing and executing permissions.
    • /dev/sdb1: A second drive.
  5. Give your password and press ENTER again.
  6. Finally, to check new permissions, copy the following command and press ENTER:
    ls -l /dev/sdb1
    EXPLANATION
    • ls: Lists files and folders in a directory.
    • -l: Shows detailed information like permissions and ownership.
    • /dev/sdb1: A second drive.

See, it is showing “rwx” instead of “”. That means the user has r(reading), w(writing), and x(executing) permissions now.

Conclusion

In this article, I have shown you how to change permissions on a mounted drive in Linux. I have also provided some complimentary information for your benefit. I hope everything was useful to you.

People Also Ask

What are drive permissions?

In Linux, drive permissions are a way to control who can read, write, and execute files. Permissions can be granted to individual users, groups of users, or anyone with chmod command. There are several types of permissions that can be granted, including read (by +r), write (by +w), and execute (by +x)

What does changing drive permissions mean?

Changing drive permissions means modifying the access rights of a directory or a file. For instance, only the superuser has access to the files in the root directory. However, he can change permissions to provide other users access to a particular directory or file.

What are the permission types?

The 3 types of permissions are- read, write, and execute. Read permission provides the right to open and read a file. Whereas, write permission grants the ability to modify a file or directory. Furthermore, execute permission gives the capability to execute a program or script.

What are Linux file permissions?

Linux file permissions are a set of rules that determine who can access, modify, and execute a file. The permission set goes like “-rwxr-x—” where the first character denotes file type and the last 9 characters represent permissions for Owner, Group and Others.

What is the default permissions in Linux?

The default permission for a directory is rwxrwxrwx and a file is rw-rw-rw-.

What Linux command is used to change permissions?

The chmod command in Linux is used to change permissions. For example, you can change the permission of “myfile.txt” file to executable for the “user” using chmod u+x myfile.txt.

How do I give all permissions to a file in Linux?

You can give all permissions to a file in two ways below:

chmod a+rwx myfile.txt

Or,

chmod 777 myfile.txt

What is chmod 0700?

It is a numerical argument that provides reading, writing, and executing permissions to the Owner. Moreover, the first digit (0) is used to set special permissions.

Does chmod work on folders?

Yes. chmod works for both folders and files. Using this command, you can limit access to a folder.

What happens to permissions when a file is moved to another drive?

If a file is moved within the same file system, it contains original permissions. However, if the file is moved to a different file system, it will inherit permissions of its destination folder. You can use cp and rsync commands with suitable options to persevere permissions of a file.


Related Articles

3.6/5 - (29 votes)
Walid Al Asad

Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio

2 thoughts on “How to Change Permissions on Mounted Drive in Linux”

Leave a Comment