16

Using the termux (https://termux.com) terminal-emulation program, I type the following command:

ls /sdcard

I get the following error:

ls: can't open '/sdcard': Permission denied

Realizing that the /sdcard directory on Android is a symlink, I tried to find the location of the actual directory -- learning that it is not just a symlink, but a symlink to another symlink, and the actual directory is /storage/emulated/0

So finally, I typed:

ls -ld /storage/emulated/0

The result I got was:

drwxrwx--x   63 root     sdcard_r      4096 Aug 10 12:04 /storage/emulated/0

So in short --- I don't know whether termux used to run with the permissions of the sdcard_r group or whether the o permissions used to allow read-write -- but I need to know which of the two it used to be and how to fix things - because being able to access the contents of the internal SD card is kinda critical.

No, my device is not rooted, nor do I plan to root it - so I can not give any information that I'd have to root the device to obtain. However, not being rooted never in the past prevented me from having read access to the /sdcard directory - so this is new (and disturbing).

Granted - it's been a few months since previously I tried to do this - but this new limitation from Android seriously hampers the usability of termux and who-knows-what-else -- as I need to be able to have access to files that are on my SD Card. (I can still do a lot, even if not everything, even without write permissions -- but am pretty much stuck in the water if I can't get read permissions, as is presently the case.)

  • Hmm, it looks it it has the READ_EXTERNAL_STORAGE permission, so it should have access. – Matthew Read Aug 11 '16 at 20:16
  • 3
    Yes --- but apparently it had gotten switched off. I realized it when I went in System Preferences > General > Applications > Termux ----- and found that there was a toggle switch for access to files that had somehow gotten switched off. Needless to say - I switched it back on, and the problem was solved. ------ Of course - the immediate crisis is over --- but this still all raises the question of what caused it to get switched off in the first place. (I know I never did that.) – user3080003 Aug 11 '16 at 22:27
  • I had the same problem, and your answer here fixed it for me. EDIT: Stupid enter-to-submit. Was trying to create a new line. Here's what I think happened: Android 7 now allows denying permissions (yay!), but, in Termux's case, for whatever reason, it doesn't request permission like other programs do. So, the problem isn't that it was somehow switched off, but was never switched on. This is speculation, though. – Andrew Nov 11 '16 at 16:14
  • 3
    One can run termux-setup-storage to make the app request storage permissions. See termux.com/storage.html. – fornwall Nov 24 '16 at 16:13
9

Following the Termux wiki to run termux-setup-storage fixed it for me, as suggested by fornwall.

4

Newer versions of Android require apps to ask for permission during runtime. You may have noticed this already. One example is Chrome asking for the Storage permission when you try to download something for the first time. For Termux, this is a problem. Permissions default to "not allowed," so when Termux needs a permission for a task, because Termux hasn't been updated to ask for these permissions, it instead tries to perform the task anyway and throws an error as a result. Unfortunately, the developer(s) have to fix this themselves. Thankfully, Android gives you ways to manage app permissions manually. Until the developer(s) update Termux accordingly, this is probably the only way.

Step 1: Go to Termux's App Info page

There are multiple methods to reach this page. Because different phones can have different behaviors, I included all the ones I know.

Method 1: Using the multitask menu

  1. Open Termux.
  2. Press the multitask button to open the multitask menu. This should be next to the home button on the left.
  3. In the list of applications, Termux should be the first. Tap and hold on its icon.

    On some phones, you'll already be at the info page. On other phones, you'll instead see Termux's app-box-thing change at the top, with an info icon (ℹ) appearing somewhere. Other phones may give you a context menu with an "App Info" option. In both cases, tap these.

Method 2: Using the notification panel

  1. Open Termux. You want Termux's notification to appear.
  2. Pull down the notification panel and find Termux's notification.
  3. Try one of the below:

    • Swipe the notification left or right and look for a cog wheel (⛭) or info icon (ℹ) and tap it. You can't dismiss Termux's notification, so don't worry about that.
    • Tap and hold the notification and look for either a gear (⛭), an info icon (ℹ), or a context menu with an "App Info" option and tap it.
    • Look for the app icon and/or name. You may have to swipe down on the notification. Tap and hold on it. A cog wheel (⛭), info icon (ℹ), or context menu may pop up. Tap accordingly.

Method 3: Using the App Manager

  1. Go to settings>apps.
  2. Look for an option labeled "Application Manager" or similar. It seems to depend on your device.
  3. Look for Termux's entry and tap it. You may have to change your filter to "installed apps" or "downloaded apps."

Step 2: Changing permissions

You should now be on a page with Termux's name, icon, and version number with two buttons labeled "Uninstall" and "Force Stop." below it should be various other options.

  1. Look for an option labeled "Permissions" (you may need to scroll). Tap on it.
  2. There should be an entry for the Storage permission. Turn it on by clicking the switch beside it. If the Storage permission isn't listed, use a storage-related command in Termux to get a permission denied error and come back.

Testing the change

You've now given Termux access to your storage. You can test this with the command below:
ls /sdcard/
If you don't get a permission denied error, it worked! You shouldn't need to do this again unless you reinstall Termux.

0

it's July of 2017 & I had this same problem, googled for it, & arrived here. Matthew Read 's comment pointed the way to the solution, but there's no answer that spells it out clearly, so here' s the tl;dr of it:

Termux doesn't request file system permission on install, so you have to turn it on thru Settings => Applications => Termux => Permissions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.