Unable to run compiled files - bash: ./a.out: Permission denied. (I've tried chmod)
Solution 1
Seems that you've mounted the partition with with no-exec flag set. You'll have to remount the partition:
sudo mount -o remount -o exec /dev/sda7
Solution 2
I'd guess you are doing all of this on an NTFS/FAT partition that you probably share with windows. chmod permissions do not work on them.
You should move it to an ext4
(or equivalent linux) partition, and then perform permission changes.
Else, for an NTFS/FAT partition, you set permissions for the entire partition, at the time of mounting. For example,
sudo umount /mnt/my_partition
sudo mount -t vfat -o rw,auto,user,fmask=0000,dmask=0000 /dev/sda7 /mnt/my_partition
This would give you 777
on all directories and files (eeeek!), but once set, you can't modify them till you remount.
ShuklaSannidhya
Updated on June 11, 2022Comments
-
ShuklaSannidhya almost 2 years
I've compiled my C source using
cc test.c
, and it did generatea.out
file.However when I run it I get this error -
bash: ./a.out: Permission denied
My source is not in the home directory, it is on different FAT-32 partition, so I've mounted the drive in which the code is using the following command -
$ udisks --mount /dev/sda7 --mount-options umask=022 Mounted /org/freedesktop/UDisks/devices/sda7 at /media/48E9-FD53 $ cd /media/48E9-FD53/C
Then I compile my code using
cc
I've also tried
gcc
. But still I get the same error.Then I did -
chmod +x a.out
, still the same problem. Also with(chmod 755 a.out
) andchmod u+x a.out
.I've also tried compiling and executing the program using
sudo
.I've also tried -
sudo chown sannidhya:sannidhya a.out
.I've tried every thing that I found after googling, still couldn't get it to work.
How can I run
.out
file (without moving it to home directory)?Note - I am using Ubuntu 12.04 LTS.
But a weird thing here is, even after running
chmod +x a.out
, on running -ls -l a.out
, I get--rw-r--r-- 1
also when I check the properties of
a.out
, under Permissions tab, when I checkAllow executing file as program
,the tick appears and quickly disappears. -
hek2mgl about 11 yearscan you add the output of
mount | grep sda7
? -
Anirudh Ramanathan about 11 years@Sann Same logic. You can only apply permissions to the entire partition when you mount, if it isn't a linux native partition. Move it to a linux partition for
chmod
to work. -
ShuklaSannidhya about 11 yearsWhat do I pass in for
mount point
parameter? I am getting this error -mount: mount point /media/48E9-FD53 does not exist
-
ShuklaSannidhya about 11 years
/dev/sda7 on /media/48E9-FD53 type vfat (rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks)
-
hek2mgl about 11 yearsI'm having the same mount options, and the same filesystem (vfat). And it works... Hmm
-
ShuklaSannidhya about 11 yearsDo I need chmod even after that?
-
Anirudh Ramanathan about 11 yearsDid you manage to mount it successfully?
mount | grep sda7
should now reflect the newdmask
andfmask
set. Can you check? -
hek2mgl about 11 yearsI would for testing do anything as root. And then check if
ls
if the executable bit is set. Then try to run ./a.out -
hek2mgl about 11 yearsHehe! :) fine!.. Although in this case it seems to be an usb stick, you should have this in mind any time you mount a cdrom.
-
ShuklaSannidhya about 11 yearsAll right, so this command will unmount if the drive was already mounted and the mount it again, right? How do mount it if it wasn't mounted before? Is this alright -
sudo mount -o exec /dev/sda7
. BTW: what is the purpose of the-o
parameter? -
hek2mgl about 11 yearsyes, then just drop the
-o remount
and use your regular mount command and add-o exec
. Btw, for usb sticks this should work out of the box with ubuntu 12.04 as I'm using it too. It looks like that you have enabled this no-exec monting to prevent form malware etc on usb sticks.. -
ShuklaSannidhya about 11 yearsWhen I mount it freshly using
sudo mount -o exec /dev/sda7
, I get this error -mount: can't find /dev/sda7 in /etc/fstab or /etc/mtab
. -
hek2mgl about 11 yearsyou missed the path where it should be mounted. Call it like:
mount OPTIONS DEVICE TARGET_PATH
-
ShuklaSannidhya about 11 yearsWhen I compile, I get this -
/usr/bin/ld: cannot open output file a.out: Permission denied collect2: ld returned 1 exit status
. However, there is no problem while running the file. Strange...