LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-09-2008, 04:06 PM   #1
jxrod2000
Member
 
Registered: Apr 2006
Location: MA, USA
Distribution: Ubuntu 18.04
Posts: 35

Rep: Reputation: 15
Directory permissions on a usb stick


Hello,

I don't know how to do this and I'm hopping someone can help.

As root
mount the usb stick on /mnt.
create a directory, lets say tmp, the permissions are rwx r-x r-x
At this point I want to change the permissions to rwx rwx rwx
I then run chmod a+w tmp
(it says it changed it to 0777)
After running ls -l the permissions are still rwx r-x r-x

How can I change the permissions of tmp.

Do I have to mount it with special options in order to accomplish this

Thanks,
JR.
 
Old 08-09-2008, 05:11 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
If the USB stick is formatted with NTFS then it is probably mounted read-only. You have to mount it with ntfs-3g to get full read-write support.
 
Old 08-09-2008, 05:56 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You can't use chmod on fat32 or ntfs filesystems. NTFS has a foreign acl and fat32 doesn't store any user permissions with files and directories.

Instead you need to change the way it is mounted. The permissions on files are determined in-mass when the filesystem is mounted. The same is for file permissions.

For vfat, use the mount options "uid=<your-username>,gid=<your_default_group>,fmask=0111,dmask=000". This will change the owner to you and the group ownership to your default group. You can use either your UID number or your username. The fmask and dmask commands determine the permissions of the files and directories.

I just reformatted a pendrive and used these mount options:
Code:
sudo mount -t vfat /dev/sdd1 /mnt/craig/ -o rw,uid=jschiwal,gid=jschiwal,noatime,nodev,noexec,utf8,fmask=0111,dmask=0000,flush
jschiwal@qosmio:/media> ls -ld /mnt/craig/
drwxrwxrwx 2 jschiwal jschiwal 4096 1969-12-31 17:00 /mnt/craig/
I created a group who's name matches my username and made it my default group. I could have used the mount options "fmask=0177,dmask=0077" instead. That would have given me private access to the pen drive while mounted on this machine.

If I wanted to create an fstab entry, I would first determine the filesystem UUID of the filesystem (vfat). This way, even if after pluggin in the pendrive, it is assigned a different device node, such as /dev/sde1, I would still be able to mount it with the permissions I have in the /etc/fstab entry:
[code]
udevinfo -q env -n /dev/sdd1
ID_VENDOR=USB
ID_MODEL=DISK_2.0
ID_REVISION=1219
ID_SERIAL=USB_DISK_2.0_G3X7CRTIRASZ4RCH-0:0
ID_SERIAL_SHORT=G3X7CRTIRASZ4RCH
ID_TYPE=disk
ID_INSTANCE=0:0
ID_BUS=usb
ID_PATH=pci-0000:00:1d.7-usb-0:1.4:1.0-scsi-0:0:0:0
ID_FS_USAGE=filesystem
ID_FS_TYPE=vfat
ID_FS_VERSION=FAT32
ID_FS_UUID=489E-19FC
ID_FS_UUID_ENC=489E-19FC
ID_FS_LABEL=podcasts
ID_FS_LABEL_ENC=podcasts
ID_FS_LABEL_SAFE=podcasts
[code]

Code:
/etc/fstab entry:
UUID=489E-19FC /mnt/craig vfat rw,noauto,uid=jschiwal,gid=jschiwal,noatime,nodev,noexec,utf8,fmask=0111,dmask=0000,flush 0 0
I might also use the "user" or "users" option to allow mounting this pendrive as a normal user. Notice the "noauto" option. This will prevent the system from trying to mount the pendrive when rebooting. Imagine that the pendrive isn't plugged in. That would cause a failure, dropping into the root shell instead of continuing. The "user" or "users" option combined with the UUID number of the filesystem would even allow you to include a mount command in your ~/.profile command and have the pendrive mount when you log in. You don't need to use sudo, because the mount command is suid, and allows a regular user to mount the device if the "user" or "users" option is used.

---

If you are using KDE or Gnome and your distro uses hal/udev for automounting removable drives, including an /etc/fstab entry may interfere with automounting or signal that you prefer to mount it manually. Instead of mounting it yourself, when the dialog box comes up asking if you want to examine the files (e.g. open the filemanager), press the "Mounting" tab. From there you can change how the pendrive is mounted. Be sure the mount as user is selected.

I haven't tried changing permissions in the permissions tab to see whether that would change the mount options on a vfat drive, or if that dialog is useful if you use a different filesystem.

In the least, you can gain full access to the device.

---

Using my previous example with an fstab entry, when running on your system, an external device with that UUID will only be mounted that way. A different regular user can mount it if you use the "users" option, but can't enter the device if you mask out the group and user permissions. This can give you a small amount of protection if the user doesn't have root access or access to a different computer or a live distro and if you don't duel boot to windows. I should emphasize the word "small".

Last edited by jschiwal; 08-09-2008 at 05:59 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getting permissions to stick? lleb Linux - Newbie 1 01-15-2008 01:06 PM
mount/umount usb stick - PQI Intelligent Stick 2.0 sandbag Linux - Software 5 05-06-2005 11:12 AM
SuSE 9.1 Permissions, how to make 'em stick hoopyfrood Linux - Distributions 10 08-14-2004 11:21 PM
USB problems: Memorex USB stick 256MB and PSX to USB adapter by Radio Shack Knuckles T15 Linux - Hardware 1 05-19-2004 06:58 PM
Why do my directory permissions not stick permanently? h00chman Linux - Newbie 3 03-20-2004 05:49 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration