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:
[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:
-
Launch an Ubuntu Terminal.
-
Paste the following command in the command prompt:
df
EXPLANATION- 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 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.
-
Press ENTER.
EXPLANATIONThe 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:
- 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
- Type your password.
- Press ENTER.
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:
- 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, and 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
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:
- 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.
- Finally, to check the new Owner, write the following command and press ENTER:
ls -l /dev/sda3
As you can see, the new Owner is “walid” instead of “root”.EXPLANATION- 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:
- At the beginning, launch a Terminal in Ubuntu.
- Insert the following command to view mount points and hit ENTER:
df
I will choose the drive “/dev/sda2” which is mounted on point “/boot/efi” for demonstration purposes.EXPLANATION- df: Shows space usage.
- 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”.
- 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.
- Finally to check the permissions of the mount point, use the command below:
mount -v | grep /mydirectory
EXPLANATIONEXPLANATIONThe 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:
- 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.
- Now insert the command below to see new permissions:
ls -l myfile.txt
In the image, it is showing “x” in place of “–” for the user permissions. This indicates that the user has execution permission now.EXPLANATION- 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:
- At first, open an Ubuntu Terminal.
- 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.
- Insert the following command to view permissions of drive “/dev/sdb1” and press ENTER:
ls -l /dev/sdb1
No one has any permissions here.EXPLANATION- ls: Lists files and folders in a directory.
- -l: Shows detailed information like permissions and ownership.
- /dev/sdb1: A second drive.
- 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.
- 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?
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
- 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? [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]
FUNDAMENTALS A Complete Guide for Beginners
Hi Walid,
Thank you for your excellent directions.
Welcome!