My USB flash drive gets automatically mounted at /media/ME
without requiring root
intervention.
Now, I can read and write sectors on the drive mounted at /dev/sdX
device using open
, lseek
, read
, and write
. But I can do this only as root
.
Question: Just as the device can get mounted without root
intervention, is it also possible to read and write from/to this device without being root
?
If it's not possible, I'm willing to show a GUI password dialog for
root
.
But how do I do this from my console program?
Yes
The block device /dev/sdX has standard UNIX permissions - so if it is owned by your user or a group your user is in and the permissions are set correctly then you will be able to write to it.
$ ls -l /dev/sda
brw-rw---T 1 root disk 8, 0 Dec 3 18:27 /dev/sda
So only root and members of the group disk can read or write to my /dev/sda. If I put myself in the disk group I would be able to write to the block device.
You can set-up udev to set the permission of the block devices automagically when they are plugged in.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.