Can I change devices permissions with chmod?

Can I change devices permissions with chmod?

  • Before read: I don't want to use any udev rule. I need to change (programmatically) the permissions of some device. But first in order to underestand what I have to do (in code) I want to make the job using just chmod command. So far, I've tried this: root# ls -l /dev/sdb root# brw-rw-rw- 1 root disk 8, 16 Apr 7 05:27 /dev/sdb root# chmod 0600 /dev/sdb root# ls -l /dev/sdb root# brw------- 1 root disk 8, 16 Apr 7 05:27 /dev/sdb as you can see, /dev/sdb has read and write permissions only for the owner (wich is root). But I'm still able to create new files and read files from my connected flash drive. What I'm missing. How can I use chmod to prevent users to write to some device? Can be done what I'm asking for? Thank in advance.

  • Answer:

    If I understand you right then there is some file system on /dev/sdb that you have mounted. What matters here are the permissions in the file system that resides on /dev/sdb, the permissions of /dev/sdb are completely irrelevant for your question. Except that with permissions 0666 anyone can bypass the access control mechanisms for that file system and access the content on the device arbitrarily, but this is a different issue. If you want to restrict access to the files within the file system, then you have to assign appropriate ownership and permissions to the files (beginning with the root of that file system). For file systems like FAT mount(8) lets you set the ownership and access permissions for all files within the file system. If you want to expose the entire tree to certain users only and hide it from all others, then mount it somewhere where only those users have access to. But note that any user can see that something is being mounted (mount(8) or df(1) will show them). chroot(1) is not going to help you at all.

Raydel Miranda at Unix and Linux Visit the source

Was this solution helpful to you?

Other answers

/dev/sdb is the block device name. Changing the permission of /dev/sdb will not affect the filesystem on /dev/sdb. Use mount to get the list of mounted mediums and mountpoints. Use chmod to change permissions in mountpoint. e.g. mount will show lines which looks something like /dev/sdb1 on /run/mount/pioneeraxon/disk1 type ext4 (...) In such case /run/mount/pioneeraxon/disk1 is the mountpoint for /dev/sdb1. You need to change the permissions in /run/mount/pioneeraxon/disk1.

PioneerAxon

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.