Hello,

I have a USB key on which I do all of my programming. It is formatted as an NTFS drive with 32 gigabytes of space.

On this drive I have large C::B projects which contain both windows and linux executables.

When I try to run the linux executables it gives me a permission denied error.

I tried right-clicking on the USB name on the left of the default Ubuntu file viewer and setting 'Allow executing file as program' but it wouldn't hold. Then I tried running sudo chmod -R a+x media/USBKeyName, it took a few seconds to run, but when I checked the file permissions they had been reset. When I look at the checkbox for 'Allow executing file as program' it is highlighted with a minus sign in it.

How can I set the executable bit on my USB key?

Recommended Answers

All 2 Replies

NTFS usually sets (to Linux's view) the execute bit. Which NTFS driver are you using? You probably want to install and use the ntfs-3g driver which has much better capabilities than the fuse-ntfs driver. Here is a link to the manpage for Ubuntu: http://manpages.ubuntu.com/manpages/precise/man8/ntfs-3g.8.html

The problem is that you are looking in the wrong places. The reason why you cannot execute files on a USB is because the automatic mounting of USB drives in Ubuntu is somehow set to read-write permissions, but no execute permissions. Basically, the mount permissions are a mask that apply recursively to everything on the mount folder. So, you need to mount the USB drive with executable permission (rwx) if you want executable files in it to be executable when the USB drive is mounted.

This is a classic problem and it has been around for years, and it baffles me why the Ubuntu team (or anyone related to the automount feature) has not yet gotten around to adding a GUI setting somewhere for the user to change the default mounting permissions for external / USB drives. And I think rubberman is right that the automount uses the antiquated fuse-ntfs driver, which mounts ntfs without executable permission by default (or maybe not at all).

Here are some solutions:

1) Edit your fstab file for that USB drive entry. I use this for ntfs drives:

UUID=<UUID of USB drive> /media/<mount-folder>                      ntfs-3g    permissions,uid=1000,gid=1000,dmask=022,fmask=022        0       0

and you can get the UUID of your USB drive with the command $ sudo blkid.

2) Mount the USB drive manually with the ntfs-3g option. You can just do this:

$ sudo mkdir /media/<mount-folder>
$ sudo mount -t ntfs-3g /dev/sdb1 /media/<mount-folder>

where /dev/sdb1 should be replaced by whatever your device name is, you can list them with $ sudo fdisk -l. When finished, unmount with $ sudo umount /media/<mount-folder>. By default, ntfs-3g will mount with all permissions. If you want to restrict that, you can do:

$ sudo mount -t ntfs-3g -o permissions,uid=1000,gid=1000,dmask=022,fmask=022 /dev/sdb1 /media/<mount-folder>

3) Change the udev rules. Follow the instructions here or here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.