permission denied in Termux | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

permission denied in Termux

when i compile c++ and try to run a.out ./a.out it prints "permission denied" how can I fix this?

7th Sep 2021, 2:28 AM
Mehran
Mehran - avatar
32 Answers
+ 5
chmod +x a.out ./a.out
7th Sep 2021, 2:52 AM
Slick
Slick - avatar
+ 3
Slick how can i check permissions? i just want to execute a simple c++ program. Note: when i compile using clang command it prints linker error and when i compile using g++ command it generates a.out file.
7th Sep 2021, 3:43 AM
Mehran
Mehran - avatar
+ 3
Mehran then try: sudo su ./a.out First you will be root (you have 100% permission). Then run the binary file.
7th Sep 2021, 5:07 AM
Mani_K_A
+ 3
permission denied again. بی خیالش ignore it....
7th Sep 2021, 7:17 AM
Mehran
Mehran - avatar
+ 3
Mehran the command that Reynard gave just makes the internal/external storage of the phone accessible to termux. And termux's data dir is very well accessible within termux and it allows to set all those basic permissions which you could setup on Linux.
8th Sep 2021, 5:07 AM
P Jain
P Jain - avatar
+ 3
Mehran secondly if you wanna use chmod +x you'll have to place those files under termux data dir
8th Sep 2021, 5:11 AM
P Jain
P Jain - avatar
+ 2
#when you're in the directory: type: ls -l #check permissions # also, what does the code do? You can't mess with certain things unless your phone is rooted
7th Sep 2021, 3:06 AM
Slick
Slick - avatar
+ 2
Try this. sudo ./a.out
7th Sep 2021, 4:55 AM
Mani_K_A
+ 2
Mani_K_A it prints: No superuser binary detected. Are you rooted? my phone isn't rooted.
7th Sep 2021, 5:04 AM
Mehran
Mehran - avatar
+ 2
Mani_K_A trying to run sudo with any arg prints the previous message.
7th Sep 2021, 5:45 AM
Mehran
Mehran - avatar
+ 2
Mehran Try this: chmod 777 a.out Or chown your_username:your_username a.out It might work🤷🏻‍♂️
7th Sep 2021, 6:51 AM
Mani_K_A
+ 2
ای بابا
7th Sep 2021, 7:17 AM
Mani_K_A
+ 2
Mehran you can make files executable by using chmod +x command. But please note on non-rooted Android devices this can be only achieved within the /data/data/com.termux/files/ directory. You can't make files on the Internal/External Storage executable as those mount-points (i.e. /storage & /sdcard ) have only rw permissions to apps & the user (i.e. you)
8th Sep 2021, 4:34 AM
P Jain
P Jain - avatar
+ 2
P Jain. are you sure? as you can see in Reynard's answer he says i have no problem so there's no need to place files in unavailable directories such as internal storage of the app.
8th Sep 2021, 5:04 AM
Mehran
Mehran - avatar
+ 2
Mehran what P Jain said is true,try running pwd in termux and verify if the output is /data/data/com.termux/files/home But technically it wouldnt be anywhere else since your device is not rooted and /data/data/com.termux/files will be the first directory that youre accessing when installing termux,unless there was some kind of corruption in the installation, you might want to reinstall termux and try again.
8th Sep 2021, 5:23 AM
raynard
raynard - avatar
+ 2
So what do you mean my device should be rooted? Mehran no what I mean is that if you want full control over your device (like executing chmod +x in internal Storage, using tsudo/tsu from termux) then root but from what I see that if you only want to make a file executable then no need to root, copy that file to $HOME in termux and then run chmod +x on it
8th Sep 2021, 5:35 AM
P Jain
P Jain - avatar
+ 2
mv a.out ~ cd ~ chmod +x a.out ./a.out run file in root directory
7th Jan 2022, 11:36 AM
Ishaan Kapoor
Ishaan Kapoor - avatar
+ 1
Slick thank you. but the problem could not be solved. it prints again "permission denied"
7th Sep 2021, 3:04 AM
Mehran
Mehran - avatar
+ 1
Mehran what are you compiling it with? Do "g++ filename -o outputname" then run it ./outputname
7th Sep 2021, 8:00 AM
raynard
raynard - avatar
+ 1
raynard I tried it before. prints same result.
7th Sep 2021, 8:19 AM
Mehran
Mehran - avatar