How to Change Permissions on Mounted Drive in Linux

If you have a mounted drive, you might run into some issues. You may not be able to read, write or execute files on your drive properly. And most of the time the problem is associated with permissions and you require to change the drive permissions. In this article, I will explain how to change permissions on a mounted drive in Linux.

Key Takeaways

  • Changing permissions of a mounted drive.
  • Getting familiar with chmod, chown
  • In-depth knowledge of permissions and ownership.

Requirements

Process Flow Chart

Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTSFlow chart for "change permissions on mounted drive in Linux"

Watch to Change Permissions on  Mounted Drive in Linux

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, I will list all the mounted drives. Then I will print permissions of a particular mounted drive. To do that, follow the steps below:

Steps to Follow >

➊ At first, launch an Ubuntu Terminal.

➋ Insert the following command in the command prompt:

df
EXPLANATION
  • df: Shows used and available space on each disk partition.

❸ 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.

➌ Write the following command to view permissions of mounted drive “/dev/sda3”:

ls -l /dev/sda3
EXPLANATION
  • ls: Lists contents of a directory
  • -l: Shows detailed information like permissions, ownership.
  • /dev/sda3: A mounted drive.

❹ Press ENTER from the keyboard.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:

Steps to Follow >

➊ Press CTRL+ALT+T to launch an Ubuntu Terminal.

➋ 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.

➌ Give your password.

❹ Press the ENTER button on your keyboard.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:

Steps to Follow >

❶ Firstly, open an Ubuntu Terminal.

❷ Type the following command in the Terminal:

ls -l /dev/sda3
EXPLANATION
  • ls: Lists contents of a directory.
  • -l: Shows detailed information like permissions, ownership.
  • /dev/sda3: A mounted drive.

❸ Hit the ENTER button.Checking permissions for "change permissions on mounted drive in Linux"



Complementary Information

Here I have added some extra information on how to change permissions on a 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 instance, the Owner of the drive “/dev/sda3 ” is “root” and I want to change it to “walid “. I can do it by doing the following:

Steps to Follow >

❶ Open a Ubuntu Terminal by pressing CTRL+ALT+T.

❷ 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.

❸ Provide your password and hit ENTER again.Changing ownership❹ 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:

Steps to Follow >

❶ At the beginning, launch a Terminal in Ubuntu.

❷ 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.

❸ 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❹ Now write the following common to mount /dev/sda2” to “/mydirectory” with reading and writing permissions and press ENTER:
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.
Mounting a mount point❺ Finally to check the permissions of the mount point, type the command below and hit ENTER:
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:

Steps to Follow >

❶ Press CTRL+ALT+T to open a Terminal in Ubuntu.

❷ 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❸ 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:

Steps to Follow >

❶ At first, open an Ubuntu Terminal.

❷ Copy the following common to print all the drives and hit ENTER:

df
EXPLANATION
  • df: Prints space usage.

There are two second hard drives here, sdb1 and sdb2. I will change the permissions of sdb1.

❸ 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.

❹ Write the command below to provide reading, writing and executing permissions to the user and hit ENTER:

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.

❺ Give your password and press ENTER again.

❻ 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?
It controls who can access and modify files and directories on a Linux system. Additionally, it provides an administrator to control the resources of a system.
What does changing drive permissions mean?
Changing drive permissions mean 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 3 types of permissions?
There are 3 types of permissions- 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 are 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. Here is an example of changing permission using chmod command-

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 only 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 chmod command, anyone can limit access to a folder.
What happens to permissions when a file is moved to another drive?
It depends on the file system and the method. 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

5/5 - (1 vote)
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