permission denied

Pages: 12
Hi.
I g++ my program. But when trying to execute ./a.out, I get:
bash: ./a.out: Permission denied
What's the cause for it?

Thanks in advance
You just need to change the permission so you can execute it.
chmod 755 a.out
what is the problem?
I could execute programs before
I chmoded ./a.out, but I still get permission denied when trying to execute ./a.out
It's usually because the user doesn't have the required permissions.

You could try 777'ing if you're not worried about it being wide open.

What permissions does the list command show (ls -l)?
1
2
3
4
5
 ls -l
total 192
-rw-r--r-- 1 soheil soheil 7836 Dec 13 00:24 a.out
-rw-r--r-- 1 soheil soheil 1285 Dec 12 13:01 test1
-rw-r--r-- 1 soheil soheil  879 Dec 13 00:04 test1.cpp
Yeah, that doesn't look like you've chmod'd it right.

You need execute permissions on the file. None of the groups there have those permissions. 755 should give rwx to the owner and rx to everyone else.

Should look like my most_iso application here: http://postimg.org/image/8znc8bu5t/
see:
1
2
3
4
5
 ls -l
total 192
-rw-r--r-- 1 soheil soheil 7836 Dec 13 00:24 a.out
-rw-r--r-- 1 soheil soheil 1285 Dec 12 13:01 test1
-rw-r--r-- 1 soheil soheil  879 Dec 13 00:04 test1.cpp
I'm guessing you're the user 'soheil', right?

You can check by typing 'whoami'. If you are, then you should be able to change the access of the file. If not, you'll have to sudo it or something.

What happens when you chmod?
This is why some basic *nix knowledge is good to have...

Permissions are broken into three groups: Owner Group World, except the first character which denotes what type of file it is. For examples, directories have the first character set to 'd'.

Anyways, with your permissions you have: read-write for Owner, read for Group, and read for World. There is no execute bit set.

To fix this, you need to change the permissions of the file using 'chmod'. For example, 'chmod 777' gives rwx permissions to Owner, Group, and World.

These numbers are created from adding up whatever permissions you want.
r = 4
w = 2
x = 1

So, if you want Owner to have rwx, Group to have rx, and World to have to read, you would do 'chmod 754'

You can see the owner and group per file from an ls -l like you did. The first name is the user, and the second is the group. For you, they are both named the same here.

Hopefully this gave you at least a basic understanding of file permissions. If not, I'm sorry. I was watching Parks and Recreation as I wrote this :)
Last edited on
But I couldn't executed it even when I sudo'ed a.out
Ah sorry screwed up the wording.

You still need to make it executable. A common way is 'chmod u+x a.out'
This just says "give the user who owns this file execute permissions".

like
chmod soheil +x ./a.out?

EDIT:
It didn't work so I tried 'chmod u+x ./a.out'

It executes, but nothing is printed. Please have a look at:
http://www.cplusplus.com/forum/general/119757/
END EDIT
Last edited on
so almost one month has passed and you still can't execute a single file
http://www.cplusplus.com/forum/unices/117723/#msg642319
┬┐how is the partition mounted?
$ mount -l


> it executes, but nothing is printed
test with a hello world

> chmod soheil +x ./a.out
RTFM
Last edited on
When you are doing the chmod, make sure u put a sudo before if your not root. I used to have this problem to. My problem came because I copied the whole code::blocks file from a windows partition and then it gave me but I fixed it with sudo chmod 755... And now I'm on kali linux as root so no more chmod except for running .sh and a few other types
But CaptainBlast, I thought you were 1337 hackers?
What do you mean hackers? I don't remember which chmod one worked but I remember using 755 but now I'm on kali linux and root :)
You should not be running as root.
The file you're trying to compile could be in a folder that is set as read only for a reason

make a new folder on your desktop and open the source file in gedit or what ever editor your using then copy all the code and make a new source file in the folder on your desktop then save and try compile it again

You can use "g++ source.cpp -o program" to name the file rather than having "a.out"
If it was a read-only directory, then the `a.out' file would not be created and the error would read something like `bash: ./a.out: No such file or directory'
Pages: 12