Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to run compiled files - bash: ./a.out: Permission denied. (I've tried chmod)

I've compiled my C source using cc test.c, and it did generate a.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) and chmod 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 check Allow executing file as program,the tick appears and quickly disappears.

like image 815
ShuklaSannidhya Avatar asked Apr 18 '13 15:04

ShuklaSannidhya


Video Answer


2 Answers

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
like image 58
hek2mgl Avatar answered Oct 04 '22 01:10

hek2mgl


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.

like image 41
Anirudh Ramanathan Avatar answered Oct 04 '22 02:10

Anirudh Ramanathan