# Permission Denied with Automounted USB



## Allan (Apr 13, 2017)

I have an interesting issue I can't seem to figure out.  I am trying to set up USB automounting in FreeBSD 10.3 and while I can attach a USB flash or hard drive and have it mount in `/media`, I have no write permissions, only read.

I followed the instructions from Chapter 17 in the Handbook to the letter.  When I plug in the USB disk, I can see that it's automatically mounted (by traversing to that directory) and that the owner is `root`and the group is `wheel`.  When I am logged in with my user account (also a member of wheel).  Here's the output from `ls -la`:


```
# ls -la
total 13
drwxr-xr-x   3 root  wheel   512 Apr 13 16:18 .
drwxr-xr-x  19 root  wheel    26 Apr 13 12:18 ..
drw-r-xr-x  27 root  wheel  2560 Apr 13 17:00 da0s1
```

If I go in and manually change the permissions by issuing the command `chmod 666 /media/da0s1`, it then has all the correct permissions and I can read/write to my hearts content; until I reboot, or unmount/remount the drive.

Per the Handbook, I added these lines to my /etc/devfs.rules


```
[localrules=10]
add path 'da*' mode 0670 group operator
```

/etc/rc.conf

```
# Enable custom rules to allow users to mount devices after boot
devfs_system_ruleset="localrules"
```

Note:  while it does indicate `operator` as the group, my account is a member of the `operator` group.  I also tried changing it to `wheel` with no change in results.

I've got to be missing something in a configuration somewhere, but I am at a loss.  Just to recap, the filesystem mounts, I just have no permissions.  There are several threads here somewhat related, but none fixed my issue.  If anyone can point me in the right direction, I would greatly appreciate it.


----------



## Allan (Apr 14, 2017)

Yes.  I should have mentioned it in my OP,  but I don't think the device would mount without it.  The device mounts and I can read everything with no problem, but I can't write a thing.


----------



## SirDice (Apr 14, 2017)

Are you trying to write files or are you trying to write to the stick itself? There's a difference. Write access to /dev/ad* (through devfs.rules) only deals with accessing the disk or partition directly. It has no influence on the permissions of the filesystem that's on there.


----------



## Allan (Apr 14, 2017)

SirDice said:


> Are you trying to write files or are you trying to write to the stick itself?



Write files.

Just to make sure we're on the same page....  I get access to the device (it gets auto mounted), but when I traverse into the folder (i.e. /media/da0s1) as a non-root user  and issue the command `touch test.txt` I get a `Permission denied` error.  If I run as root (`su` or via `sodu`) I have access.  If there is an existing file there, I can read it with no problem.

I have tried changing the permissions of /media (`chmod 770 /media` as `root`) but I got an error `Operation not permitted`.  If I manually change the permissions of /media/da0s1 (`chmod 770 /media/da0s1)`), I can read/write with no problem until a reboot or I unmount/remove the USB media.

How can I get write permissions for these filesystems?  Is this something that needs to be configured in autofs ()?


----------



## SirDice (Apr 14, 2017)

Allan said:


> Is this something that needs to be configured in autofs(5)?


I've never used automounting but that would be my guess. It's autofs(5) that does the actual mounting, so I'd start looking there and see if you can change the standard permissions when it mounts a filesystem.


----------



## krasnij (May 4, 2017)

Hello, I've had the exact same problem, but managed to fix it. Here's how:

When you're using automount, you should have this kind of config in /usr/local/etc/automount.conf


```
MNTPREFIX="/media"
USERUMOUNT="YES"
USER="username"
ATIME="NO"
REMOVEDIRS="YES"
```

Now, when it comes to /etc/auto_master : you *must* leave the media map commented. Don't enable it. Otherwise you won't have access to this folder as an user.


----------



## nik0tine (Sep 30, 2018)

Krasnij you are a genius! The FreeBSD handbook ain't got sh* on you!
And if FreeBSD were not so security obsessed, this simple function would not have been an issue.
The next 'security' feature should be protection from people wanting to bash their computer with a baseball bat. 
this reminds me of a famous quote:

- He who obsesses about security never gets anything accomplished
-Nelson Mandela

Anyway create /usr/local/etc/automount.conf because the developers can't do it,
Then make it exactly as two posts ago,
Then comment the auto_master, line about media because the whole file is useles,
Then reboot and finally NORMAL people can mount, change and uncounted usb sticks.
This should be a wake-up call to those who made freebsd afraid of its own shadow.


----------



## Deleted member 30996 (Oct 1, 2018)

nik0tine said:


> Then reboot and finally NORMAL people can mount, change and uncounted usb sticks.
> This should be a wake-up call to those who made freebsd afraid of its own shadow.



Just insert your Windows boot media, click your heels 3 times and say "There's no place like home. There's no place like home. There's no place like home." Before you know it you'll wake up back in Kansas and this will all seem like just a bad dream...


----------

