Setting appropriate directory and file permissions
We are almost done!
Since the mkfs.ext4 ran under superuser privileges, the permissions in the filesystem needs to be modified if you wish to write to it with any user other than root.
Mount the ext4 filesystem using any of the means mentioned above.
Code:
Navigate to the mount point using cd:
Code:
We will try making a file using the current user (rock64). Use the touch command to try to make a file with that user:
Code:
You will see that you will be unable to make a file. However if you try again using the root user, it should work, showing you need to address the permissions.
![[Image: Rciuk5h.png]](https://i.imgur.com/Rciuk5h.png)
Navigate up a directory
Code:
To give permission to the current user (rock64 in this case), you will need to use the chown command:
Code:
"-R" stands for recursive, it means the mountpoint and all directories/files within it. We need root privileges to change permissions so in our case, the command would be:
Code:
![[Image: 6VXZVae.png]](https://i.imgur.com/6VXZVae.png)
After changing the permissions, you should be able to navigate back into the mounted filesystem and write to files.
Code:
If you want to give full permissions to ANY user to that directory, you need to use the chmod command to do that:
Code:
We need to invoke superuser for that command, and after navigating out of the directory, in our case it would look like:
Code:
Its absolutely not required at this level, but if you'd like to learn more about linux file permissions, I've found the following writeups quite handy:
https://www.digitalocean.com/community/t...ermissions
https://www.linux.com/learn/understandin...ermissions
We are almost done!
Since the mkfs.ext4 ran under superuser privileges, the permissions in the filesystem needs to be modified if you wish to write to it with any user other than root.
Mount the ext4 filesystem using any of the means mentioned above.
Code:
Code:
rock64@rock64:~$ pmount /dev/sda1 /media/USB-test3
rock64@rock64:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 14.9G 0 disk
└─sda1 8:1 1 14.9G 0 part /media/USB-test3
mmcblk1 179:0 0 29.8G 0 disk
├─mmcblk1p1 179:1 0 3.9M 0 part
├─mmcblk1p2 179:2 0 64K 0 part
├─mmcblk1p3 179:3 0 4M 0 part
├─mmcblk1p4 179:4 0 4M 0 part
├─mmcblk1p5 179:5 0 4M 0 part
├─mmcblk1p6 179:6 0 112M 0 part /boot/efi
└─mmcblk1p7 179:7 0 29.7G 0 part /
Navigate to the mount point using cd:
Code:
Code:
rock64@rock64:~$ cd /media/USB-test3/
We will try making a file using the current user (rock64). Use the touch command to try to make a file with that user:
Code:
Code:
touch test
You will see that you will be unable to make a file. However if you try again using the root user, it should work, showing you need to address the permissions.
![[Image: Rciuk5h.png]](https://i.imgur.com/Rciuk5h.png)
Navigate up a directory
Code:
Code:
cd ..
To give permission to the current user (rock64 in this case), you will need to use the chown command:
Code:
Code:
chown -R user:user directory/
"-R" stands for recursive, it means the mountpoint and all directories/files within it. We need root privileges to change permissions so in our case, the command would be:
Code:
Code:
sudo chown -R rock64:rock64 USB-test3/
![[Image: 6VXZVae.png]](https://i.imgur.com/6VXZVae.png)
After changing the permissions, you should be able to navigate back into the mounted filesystem and write to files.
Code:
Code:
rock64@rock64:/media$ cd USB-test3/
rock64@rock64:/media/USB-test3$ touch test
rock64@rock64:/media/USB-test3$ ls
lost+found test
rock64@rock64:/media/USB-test3$ touch test2
rock64@rock64:/media/USB-test3$ ls
lost+found test test2
If you want to give full permissions to ANY user to that directory, you need to use the chmod command to do that:
Code:
Code:
chmod -R a+rwX directory/
We need to invoke superuser for that command, and after navigating out of the directory, in our case it would look like:
Code:
Code:
rock64@rock64:/media$ sudo chmod -R a+rwX USB-test3/
Its absolutely not required at this level, but if you'd like to learn more about linux file permissions, I've found the following writeups quite handy:
https://www.digitalocean.com/community/t...ermissions
https://www.linux.com/learn/understandin...ermissions