Permission denied when executing C Program on Linux(from flash drive)

I had this issue when trying my first hello world like C program on Kali linux. I am able to save and compile C program using GCC (GNU compiler collection) but could not set the permissions to it.

The reason??? the file is on a USB drive. I am not sure if mounting it via VM ware is a reason. However, could not execute it from the pen drive.

Will be very happy if someone can explain the reason 🙂

I tried it, and you can notice that I am current on c-programming folder in my pend drive.

root@kali:/media/root/PWK/lab/c-programming# ls
firstprog firstprog.c
root@kali:/media/root/PWK/lab/c-programming#

The permissions before chmod:

root@kali:/media/root/PWK/lab/c-programming# ls -l firstprog
-rw-r--r-- 1 root root 7252 Jan 13 01:05 firstprog
root@kali:/media/root/PWK/lab/c-programming#

And after chmod:

root@kali:/media/root/PWK/lab/c-programming# chmod +x firstprog
root@kali:/media/root/PWK/lab/c-programming# ls -l firstprog
-rw-r--r-- 1 root root 7252 Jan 13 01:05 firstprog
root@kali:/media/root/PWK/lab/c-programming#

Now… moved the folder to Desktop and trying the same:

root@kali:~/Desktop/c-programming# ls
firstprog firstprog.c
root@kali:~/Desktop/c-programming# ls -l firstprog
-rw-r--r-- 1 root root 7252 Jan 13 01:05 firstprog
root@kali:~/Desktop/c-programming# chmod +x firstprog
root@kali:~/Desktop/c-programming# ls -l firstprog
-rwxr-xr-x 1 root root 7252 Jan 13 01:05 firstprog
root@kali:~/Desktop/c-programming#

And now executing the same:

root@kali:~/Desktop/c-programming# ./firstprog
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
Hello World!
root@kali:~/Desktop/c-programming#

Bingoooo!!! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *