Search code examples
linuxbashzshoh-my-zshfstab

Can't execute a .sh script from mounted disk (Ubuntu 18.04): zsh: permission denied


Ubuntu 18.04 - Installed Zsh and Oh-My-Zsh from here.

Given the following

echo '#!/bin/bash\n\nls ~;' >> myscript.sh
chmod 755 ./myscript.sh
./myscript.sh

Executed in my home folder, all goes as expected and it lists files in my home folder

output omitted for brevity -- it worked and listed files as the script intended

Executed in a secondary drive I get the output listed below (my fstab config is listed lower in this question).

╭─user@host /media/user/raw/scripts
╰─$ echo '#!/bin/bash\n\nls ~;' >> myscript.sh
╭─user@host /media/user/raw/scripts  
╰─$ chmod 755 ./myscript.sh
╭─user@host /media/user/raw/scripts  
╰─$ ./myscript.sh 
zsh: permission denied: ./myscript.sh

My /etc/fstab

╭─user@host /media/user/raw/scripts  
╰─$ cat /etc/fstab                                                                130 ↵
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sdb2 during installation
UUID=<<some_uuid>> /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sdb1 during installation
UUID=<<some_uuid>>  /boot/efi       vfat    umask=0077      0       1
/swapfile                                 none            swap    sw              0       0
/dev/disk/by-uuid/<<some_uuid>> /media/user/raw auto user,rw,nofail,x-gvfs-show 0 0

Since this executes fine in my home folder and not on this mounted drive, I'm thinking the issue is somewhere within the fstab configuration. Any ideas?


Solution

  • You are implicitly specifying noexec, which means that no files on the device will be executable.

    Here's man mount:

    user

    Allow an ordinary user to mount the filesystem. The name of the mounting user is written to the mtab file (or to the private libmount file in /run/mount on systems without a regular mtab) so that this same user can unmount the filesystem again. This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid).

    The same paragraph also suggests the fix: use the user,exec to re-enable execution in a user mountable fs.