0

I have mounted my flash drive to a new mount point inside my home folder. However, when I still try to compile my .cpp file, it tells me permission denied. How can I fix this?

1) In GParted, my flash drive is referred to as /dev/sdc1 . And here, under the Mounte Pointe label, it says the path is /home/myName/newMount

2) So when I open my home folder, I see the newMount folder, and inside are all the contents of my flash drive. However, when I try to compile a program, it won't let me. Here are the steps I take:

  • $ cd newMount
  • $ cd test (test is the C++ folder containing my program)
  • $ g++ -std=c++11 test.cpp -o test
  • $ ./test

And by running the mount command, I am getting this line of text from my flash drive: /dev/sdc1 on /home/myName/newMount type vfat (rw,noexec,nosuid,nodev,fmask=0022,dmask=0000)

  • Possible duplicate of [Mounting external hard disk for all users at start up in ubuntu 14.04](http://askubuntu.com/questions/547965/mounting-external-hard-disk-for-all-users-at-start-up-in-ubuntu-14-04) – sinclair May 19 '16 at 18:39
  • 2
    Possible duplicate of [How do i change permissions on a FAT32 formatted drive?](http://askubuntu.com/questions/96923/how-do-i-change-permissions-on-a-fat32-formatted-drive) – wjandrea May 19 '16 at 19:29
  • You don't have execute permissions on the flash drive because FAT doesn't support execute permissions. You will just need to remount the drive. See the link I just put as duplicate. – wjandrea May 19 '16 at 19:31
  • Do not [double post](http://askubuntu.com/q/774885/108204). Try [edit]ing this question instead of trying to ask a new one. – Matt Clark May 19 '16 at 20:47
  • @MattClark Sorry about that, I'm just very desperate to resolve this issue. I have been working on this all day. I edited the question. –  May 19 '16 at 20:54
  • Please [edit] you post again to include the relevant output of `mount`, and then the full output of `ls -alF /home/myName/newMount`, or whatever you mount path is. – Matt Clark May 19 '16 at 20:56
  • @MattClark ok, I fixed the original post. –  May 19 '16 at 21:03
  • what happen when you compile on your disk instead of flash? – Mohamed Slama May 19 '16 at 21:14

2 Answers2

3

After some private chat and debugging with the author - It would seem that you have your USB drive mounted with the noexec flag - this is preventing you from executing anything off of the drive, even if you have the permission explicitly set.

To fix this, simply remount the usb drive with the exec flag.

sudo mount -o remount,exec /home/myName/newMount

Using remount, all other flags will remain the same.

Matt Clark
  • 182
  • 13
  • I'm sorry about that, I've been in a frantic mode trying to resolve this issue. But when I try to do `chmod u+x test` I get a response back saying `chmod: changing permissions of ‘test’: Operation not permitted` –  May 19 '16 at 21:10
  • `sudo chmod ...` like stated in my previous comment, please post the output of `ls -alF /path/to/mountPoint`, you may just not be the owner of the USB drive, it may be owned by root. – Matt Clark May 19 '16 at 21:15
  • I apologize if I sound ignorant, but what is the `ls -alF/path/to/mountPoint` ? And also, when I ran the `sudo chmod...` it still tells me "permission denied". I sincerely apologize if I am causing anger, I am in desperate need to gain access to my flash drive. –  May 19 '16 at 21:17
  • [ls](http://man7.org/linux/man-pages/man1/ls.1.html) -alF (all, list, format) then your mount point, this will show all files in that directory with their owner, and full permission set. It will help us debug. – Matt Clark May 19 '16 at 21:19
  • `$ ls -alF/home/myName/newMount` And I get this output: "ls: invalid option -- '/' " "Try 'ls --help' for more information. " –  May 19 '16 at 21:26
  • Space between flags and path. Space before the first / – Matt Clark May 19 '16 at 21:27
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/40027/discussion-between-dhaneku-b-and-matt-clark). –  May 19 '16 at 21:32
0

It is not very clear what you are trying. I am guessing that your drive is getting mounted automatically but when you are trying to compile a file on your flash drive you get permission denied. Seems like you may have copied files with root privileges. You might want to try sudo chmod -R a+r /path/to/folder/, if you also want to store files on the device, also run sudo chmod -R a+w /path/to/folder/.

wjandrea
  • 14,109
  • 4
  • 48
  • 98
Atriv
  • 1
  • 2