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:
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
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
- 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
- Provide your password and hit ENTER again.
- Finally, to check the new Owner, write the following command and press ENTER:
As you can see, the new Owner is “walid” instead of “root”.
ls -l /dev/sda3
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:
I 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
- Now run the following common to mount “/dev/sda2” to “/mydirectory” with reading and writing permissions:
sudo mount -o rw /dev/sda2 /mydirectory
- Finally to check the permissions of the mount point, use the command below:
mount -v | grep /mydirectory
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
- Now insert the command below to see new permissions:
In the image, it is showing “x” in place of “–” for the user permissions. This indicates that the user has execution permission now.
ls -l myfile.txt
- How to Change File Permissions to 777 in Ubuntu?
- 2 Ways to Change Folder Permissions Recursively in Linux
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:
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:
No one has any permissions here.
ls -l /dev/sdb1
- Run the command below to provide reading, writing, and executing permissions to the user:
sudo chmod u=rwx /dev/sdb1
- Give your password and press ENTER again.
- Finally, to check new permissions, copy the following command and press ENTER:
ls -l /dev/sdb1
See, it is showing “rwx” instead of “—”. That means the user has r(reading), w(writing), and x(executing) permissions now.
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?
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
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?
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.
- 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]