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
- Require root/sudo privileges.
- Pendrive for this section.
Process Flow Chart
Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
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
- df: Shows used and available space on each disk partition.
❸ Hit ENTER.Here “/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
- ls: Lists contents of a directory
- -l: Shows detailed information like permissions, ownership.
- /dev/sda3: A mounted drive.
❹ Press ENTER from the keyboard.
- 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
➌ Give your password.
❹ Press the ENTER button on your keyboard.
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
- ls: Lists contents of a directory.
- -l: Shows detailed information like permissions, ownership.
- /dev/sda3: A mounted drive.
❸ Hit the ENTER button.
- How to Give Permission to User in Linux? [4 Methods]
- 2 Ways to Change Folder Permissions from Root to User 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
- 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.❹ Finally, to check the new Owner, write the following command and press ENTER:
ls -l /dev/sda3
- ls: Lists contents of a directory
- -l: Shows detailed information like permissions, ownership.
- /dev/sda3: A mounted drive.
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
- df: Shows space usage.
❸ Copy the command below to unmount point “/boot/efi” and press ENTER:
sudo umount /boot/efi
- sudo: Grants elevated privileges.
- umount: Detaches a drive from a mounted point.
- /boot/efi: Mounted point for drive “/dev/sda2”.
sudo mount -o rw /dev/sda2 /mydirectory
- 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.
mount -v | grep /mydirectory
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
- sudo: Grants root privileges.
- chmod: Changes ownership.
- u+x: Provides executing permission to Owner.
- myfile.txt: Name of a file.
ls -l myfile.txt
- ls: Shows contents of a directory.
- -l: Prints detailed information.
- How to Change File Permissions to 777 in Ubuntu?
- 2 Ways to Change Folder Permissions Recursively in Linux
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
- 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
- ls: Lists files and folders in a directory.
- -l: Shows detailed information like permissions and ownership.
- /dev/sdb1: A second drive.
❹ Write the command below to provide reading, writing and executing permissions to the user and hit ENTER:
sudo chmod u=rwx /dev/sdb1
- 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
- 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?
What does changing drive permissions mean?
What are the 3 types of permissions?
What are Linux file permissions?
What are the default permissions in Linux?
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?
Does chmod work on folders?
What happens to permissions when a file is moved to another drive?
Related Articles
- How to Change Permissions of All Files in a Folder in Linux?
- Manage File Permissions in Ubuntu Using Command?
- How to Change File Permissions in Linux with 6 Examples
- 2 Cases to Give User Permission to Folder and Subfolders in Ubuntu
- How to Change Directories and Files Recursively with “chmod”
- How to Change Folder Permissions in Linux? [2 Methods]