0

I would like to make USB drive to become read only for users (user with no root access) .Am using ubuntu 14.04.

2
  • What file system is there in the USB drive (ext4, FAT32 or NTFS or some other file system)? – sudodus Dec 6 '16 at 5:31
  • FAT32 File system only – Anil Kumar Dec 6 '16 at 5:34
1

[Please be aware, that an advanced user will be able to override this method. It is enough to boot the computer into a live system with a USB/DVD boot drive or to move the USB drive to another computer.]

Mount a FAT32 partition in a pendrive with write permissions only for root

FAT32 and NTFS file systems get their permissions in linux when mounted, and they cannot be changed for individual directories and files. The crucial part of the example is the command line to mount the FAT32 partition on the USB drive.

This example assumes that the pendrive is seen as /dev/sdx. Replace x with the actual drive letter, for example b: /dev/sdx1 ---> /dev/sdb1

sudo mkdir -p /mnt/sd1  # only if you want a new mountpoint
sudo umount /dev/sdx1   # only if already mounted (but with bad permissions)

sudo mount -o rw,users,umask=022 /dev/sdx1 /mnt/sd1  # mount

ls -ld /mnt/sd1                          # check permissions

sudo bash -c "echo 'Hello World' > /mnt/sd1/hello.txt"  # test writing with sudo
cat /mnt/sd1/hello.txt                   # test reading (as user)
ls -l /mnt/sd1                           # check permissions of the content
rm /mnt/sd1/hello.txt                    # test removing (as user)
echo 'I am a user' > /mnt/sd1/user.txt   # test writing (as user)
0

Number of solutions are already, Might be helfull for you

USB devices showing a read only

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.