How to mount another hard disk for sharing with other users in Linux

Sometimes, a drive needs to be shared by more than that primary user logged in on a Linux computer. This is to facilitate sharing of files and folders by other users on that computer. To enable all authorized users to work with files and folders on the shared drive, read on. Any commands need to be entered in a terminal window.

Create a new user group named datagroup
$ sudo groupadd datagroup <enter>
where datagroup is the new group to be created.

Add users to the datagroup
$ sudo usermod -a -G datagroup johndoe <enter>
where johndoe is the user to add and the group to which johndoe is to be added is datagroup.

Find out the device of the hard disk device that is to be mounted
$ sudo blkid <enter>
It returns below line. Remember the UUID from the below line.
/dev/sda2: LABEL=”MyDataDrive” UUID=”21930adc-e951-46f1-8040-e755d783d93c” TYPE=”ext4″ PARTUUID=”89047dd3-6819-41ab-8eeb-a2266d4b9ffb”

Use the UUID to create an entry in /etc/fstab
$ sudo vi /etc/fstab <enter>
Add the line
UUID=21930adc-e951-46f1-8040-e755d783d93c /media/datadrive ext4 auto,user,rw,exec 0 0
:wq to save the file
Note any changes will only take effect after restarting the computer.

Create the datadrive mount point directory

You will notice there is a /media/datadrive listed in the /etc/fstab entry. This is the mount point i.e. where the file system will be mounted.
Create it with:
$ cd /media <enter>
$ sudo mkdir datadrive <enter>

Change ownership of mount point folder it’s owning user and the datagroup to read and write in the mount point folder

The /media/datadrive folder is of no use until the permissions to allow the group datagroup to access it are given. So, do the following to change the folder’s ownership first:
$ cd /media <enter>
$ sudo chown -R johndoe.datagroup datadrive <enter>
where johndoe is the user, datagroup is the group and datadrive is the folder /media/datadrive.

Enable the group to read and write to the mount point folder

Only the user can write to the mounted disk and not the other users within the datagroup. To enable the users in the datagroup to write to the disk, do:
$ cd /media <enter>
$ sudo chmod -R ug+rwx datagroup <enter>

Once done, restart the computer and you can now use the MyDataDrive device and share data between users of the datagroup group.