0

(use this trick, and didn't work's)

After reinstall my ubuntu from 16.04 to 14.04. My C program can't be executed. My username is the same.

I have used:

chmod +x ./hello 
chmod -R 775 hello

I am still getting:

bash: ./hello: Permission denied

I use GUI, to tick execute or change permission group or kind, it suddenly back after few second. But I can read and write every file inside it, when I compile it again, then execute, it's always didn't works.

GUI

How can I solve it?

(read many other question, but still didn't works for me..)

$ ls -l
total 160
-rw------- 1 reigin reigin  1323 Agu 31 07:14 bentuk.class
-rw------- 1 reigin reigin  2438 Agu 31 07:14 bentuk.java
-rw------- 1 reigin reigin  1290 Sep  1 04:16 bentukq.class
-rw------- 1 reigin reigin  2183 Sep  1 04:16 bentukq.java
-rw------- 1 reigin reigin   644 Agu 29 05:09 deret.class
-rw------- 1 reigin reigin   841 Agu 29 05:09 deret.java
-rw------- 1 reigin reigin  1471 Agu 27 04:30 Fkonversi.class
-rw------- 1 reigin reigin  8519 Sep 20 14:44 hello
-rw------- 1 reigin reigin   264 Sep 20 09:06 hello.c
-rw------- 1 reigin reigin   262 Agu 25 23:52 hello.c~
-rw------- 1 reigin reigin   417 Agu 26 00:00 hello.class
-rw------- 1 reigin reigin   281 Agu 26 00:00 hello.java
-rw------- 1 reigin reigin   182 Sep  1 18:13 HelloWorld.java
-rw------- 1 reigin reigin  8612 Agu 26 01:20 jumlah
-rw------- 1 reigin reigin   484 Agu 26 01:20 jumlah.c
-rw------- 1 reigin reigin   557 Agu 27 05:43 jumlah.class
-rw------- 1 reigin reigin   645 Agu 26 00:22 jumlah.java
drwx------ 1 reigin reigin  4096 Sep 17 12:46 lat2
drwx------ 1 reigin reigin  4096 Sep 17 12:46 lat3
-rw------- 1 reigin reigin  8517 Sep 20 09:23 new
-rw------- 1 reigin reigin   250 Sep 20 09:23 new.c
-rw------- 1 reigin reigin 25424 Agu 31 07:18 noted.txt
drwx------ 1 reigin reigin  4096 Sep 20 11:42 ong
-rw------- 1 reigin reigin  1006 Agu 31 06:16 suhu.class
-rw------- 1 reigin reigin  1354 Agu 31 06:15 suhu.java
drwx------ 1 reigin reigin     0 Sep 17 12:46 suhuu
-rw------- 1 reigin reigin   645 Agu 26 10:17 terbesar.class
-rw------- 1 reigin reigin   865 Agu 26 01:29 terbesar.java
-rw------- 1 reigin reigin  8664 Sep  1 11:24 test
-rw------- 1 reigin reigin   266 Sep  1 11:24 test.c
-rw------- 1 reigin reigin  8758 Agu 29 03:36 tigainteger
-rw------- 1 reigin reigin  2343 Agu 29 03:30 tigainteger_.c
-rw------- 1 reigin reigin  2345 Agu 29 03:34 tigainteger.c
-rw------- 1 reigin reigin  1184 Agu 27 13:46 tigainteger.class
-rw------- 1 reigin reigin  2776 Agu 27 13:09 tigainteger.java

grep result :

# mount | grep 'on /media
/dev/sda7 on /media/reigin/data type fuseblk (rw,nosuid,nodev,allow_other,default_permissions,blksize=4096)
  • 1
    Where is the file located - is it on an external filesystem, or one that might have been mounted with the noexec flag? – steeldriver Sep 20 '16 at 07:10
  • it's on same hard drive.. before i reinstall everything is alright, what i suspicius is ownership or permission.. – Budi Mulyo Sep 20 '16 at 08:04
  • The /media/reigin path suggests it's an external drive - is it NTFS or FAT formatted? – steeldriver Sep 20 '16 at 08:07
  • Please edit your question with the output of mount | grep 'on /media'. – insert_name_here Sep 20 '16 at 08:08
  • @steeldriver it's not external drive it's one hardisk, but in different filetype.. it's ntfs.. XD – Budi Mulyo Sep 20 '16 at 08:17
  • @insert_name_here done.. – Budi Mulyo Sep 20 '16 at 08:20
  • Well... there's your answer - NTFS doesn't support the chmod operation. Either move the executable to somewhere such as your home directory - or figure out how to mount the media drive with the appropriate mask(s) to allow execution - see .exe file permission fail – steeldriver Sep 20 '16 at 08:21
  • @steeldriver but why when i first time install in 16.04, i can execute them without using chmod or kind.. ? – Budi Mulyo Sep 20 '16 at 08:22
  • @muru can u help me explain /dev/whatever /mnt/whatever ? what i must write in my condition? – Budi Mulyo Sep 20 '16 at 08:27
  • /dev/sda7 and /media/reigin/data, looking at your output. – muru Sep 20 '16 at 08:30
  • Try running mount -o remount,fmask=0022 /dev/sda7 /media/reigin/data and then executing the file again. – insert_name_here Sep 20 '16 at 08:31
  • still permission denied.. even i give chmod 755 hello, hello can't running.. – Budi Mulyo Sep 20 '16 at 08:34
  • Did you run the command as root? Did it produce any output? – insert_name_here Sep 20 '16 at 08:37
  • @insert_name_here root@reigin-K43SA:/# mount -o remount,fmask=0022 /dev/sda7 /media/reigin/data root@reigin-K43SA:/# no, no nothing result from it.. – Budi Mulyo Sep 20 '16 at 08:40
  • Odd. The only other thing I could think of would be to run umount /dev/sda7; mount -o fmask=0022 /dev/sda7 /media/reigin/data, though I'm not sure why remount wouldn't work. – insert_name_here Sep 20 '16 at 08:42
  • root@reigin-K43SA:/# umount /dev/sda7; mount -o fmask=0022 /dev/sda7 /media/reigin/data umount: /dev/sda7: not mounted fuse: failed to access mountpoint /media/reigin/data: No such file or directory root@reigin-K43SA:/# mount -o fmask=0022 /dev/sda7 /media/reigin/data fuse: failed to access mountpoint /media/reigin/data: No such file or directory root@reigin-K43SA:/# mount -o remount,fmask=0022 /dev/sda7 /media/reigin/data mount: you must specify the filesystem type root@reigin-K43SA:/#

    still confuse..

    – Budi Mulyo Sep 20 '16 at 08:49
  • after i mount manually from nemo, root@reigin-K43SA:/# mount -o remount,fmask=0022 /dev/sda7 /media/reigin/data root@reigin-K43SA:/# but still permission denied.. – Budi Mulyo Sep 20 '16 at 08:53
  • Try umount /dev/sda7; mkdir -p /media/reigin/data; mount -o fmask=0022 /dev/sda7 /media/reigin/data? (then try executing hello again) – insert_name_here Sep 20 '16 at 09:31
  • Answer has been posted. – insert_name_here Sep 20 '16 at 10:32

1 Answers1

0

The problem here is that the filesystem is NTFS, which doesn't support Unix permissions. You need to use the fmask option of mount, which sets the permissions of all files on the mounted drive while it is mounted.

Note that you need to have root permissions for these commands to work.

First, unmount the drive if needed:

umount /dev/sda7

If it gives an error like:

umount: /dev/sda7: not mounted

just ignore it.

Next, create a directory to be your mountpoint:

mkdir -p /media/reigin/data

Finally, mount the drive:

 mount -o fmask=0022 /dev/sda7 /media/reigin/data

This will assign 755 permissions to every file on the drive (but directories will still have default permissions). Note that this is not permanent; you'll have to do this every time you mount the drive.