Termux-app: Termux could gain write access to the entire external SD card on Android 5.1 by asking the user to select the root directory of the card

Created on 3 Dec 2016  路  21Comments  路  Source: termux/termux-app

ES File Explorer does it.
Steps to reproduce in ES File Explorer:

  • Install ES File Explorer
  • Insert external storage
  • Attempt to perform some sort of write operation on the external storage
  • This will come up. Follow the directions:
    img_20161203_113617_405
    img_20161203_113647_041
    img_20161203_113710_035
    img_20161203_113802_828

  • After you do that, ES File Explorer will perform that operation.

It would be nice if termux had this feature as well, because then users could write to their external storage using linux programs.

enhancement wontfix

Most helpful comment

That feature already exists, run $ termux-setup-storage.

All 21 comments

That feature already exists, run $ termux-setup-storage.

@karolba I have already tried that:

$ termux-
termux-battery-status        termux-contact-list          termux-infrared-transmit     termux-setup-storage         termux-telephony-deviceinfo
termux-camera-info           termux-dialog                termux-location              termux-share                 termux-toast
termux-camera-photo          termux-download              termux-notification          termux-sms-inbox             termux-tts-engines
termux-clipboard-get         termux-fix-shebang           termux-open-url              termux-sms-send              termux-tts-speak
termux-clipboard-set         termux-infrared-frequencies  termux-reload-settings       termux-telephony-cellinfo    termux-vibrate
$ termux-setup-storage
$ cd /storage/sdcard1
$ pwd
/storage/sdcard1
$ touch myfile
touch: cannot touch 'myfile': Permission denied
$ cd /mnt
$ ll
total 2
drwxr-xr-x 2 root   system     40 Dec  4 07:39 asec
dr-xr-xr-x 1 root   root     2048 Mar 12  2012 cd-rom
drwxr-xr-x 4 system system     80 Dec  4 07:39 media_rw
drwxr-xr-x 2 root   system     40 Dec  4 07:39 obb
lrwxrwxrwx 1 root   root       24 Dec  4 07:39 sdcard -> /storage/emulated/legacy
lrwxrwxrwx 1 root   root       16 Dec  4 07:39 sdcard2 -> /storage/sdcard1
drwx------ 4 root   root       80 Dec  4 07:39 secure
drwxr-x--- 3 shell  sdcard_r    0 Dec  4 07:39 shell
$ cd sdcard2
$ touch myfile
touch: cannot touch 'myfile': Permission denied

I haven't installed an sdcard (internal or external) in my Android 5.1 device, so I don't have experience with this problem, yet, but
$ termux-setup-storage help
says it sets up "$HOME/.storage". I don't know if it affects "/storage". I have "$HOME/storage" without running it manually, but maybe it or something similar was run automatically on install?

Only $SDCARD/Android/data/com.termux/files directory is writable.

@Quasic There as a typo in an earlier version of termux-setup-storage (run apt update && apt upgrade to install updated packages!) - the real directory is $HOME/storage without the dot.

Thanks. I have an internal sdcard, now, but termux-setup-storage didn't make the folder or symlink. When I made them manually, it worked. I created a test file inside. Termux can read most of the rest of the card, just not change it.

One catch: I had to use File Manager to make the folder. Termux didn't have permission to create the folder in /storage/external_SD/Android/data

@Quasic How did you do that? Here's what happens to me:

u0_a159@localhost:~$ cd /storage/sdcard1/Android/data/com.temux/
u0_a159@localhost:/storage/sdcard1/Android/data/com.temux$ mkdir mydir
mkdir: cannot create directory 'mydir': Permission denied
u0_a159@localhost:/storage/sdcard1/Android/data/com.temux$

@nonnymoose Please note that the app internal name is com.termux.

@alive4ever Wow, that fixed things. Stupid Android keyboard. Thanks!
Anyway, the issue remains: if termux did what I detailed in my original post, it could allow the user tomwrite to the entire sdcard.

Anyway, the issue remains: if termux did what I detailed in my original post, it could allow the user tomwrite to the entire sdcard.

This is the real issue.

If only termux could gain access to entire external sdcard without root access, there is no need for dedicated file manager app to manage files on external sdcard, since busybox applets and coreutils can do file management task so well. Not to mention libarchive, p7zip, and unzip addition for compressed files.

I remembered that an archive manager, namely ZArchiver asked for external sdcard root directory on first launch and gained write access to the entire sdcard directory when granted the right location.

@nonnymoose The Termux app can gain access to the SD card, but (as I understand it) only when using the appropriate java api (Storage Access Framework). Terminal programs such as vim, cat, cp etc. would not gain direct file system level access.

@nonnymoose The Termux app can gain access to the SD card, but (as I understand it) only when using the appropriate java api (Storage Access Framework). Terminal programs such as vim, cat, cp etc. would not gain direct file system level access.

Major bummer! I have been setting up rsync to sync the content of my internal SD card with my computers, it does a very good job too. But syncyng back, sigh...

@fornwall Would it be possible to create a FUSE based FS which does exactly this?

@fornwall As a workaround: it's possible to gain access to all files using sshfs together with my patched version of "tsu":
https://github.com/kiney/tsu
you have to use this option with sshfs:
-o sftp_server="/data/data/com.termux/files/home/tsu -c /data/data/com.termux/files/usr/libexec/sftp-server"

unfortunately it does not work with upstream tsu and my pull request gets no response...

I gain write access on extSdCard by doing this, but you need root

@kurokirasama - I tried the editing of /data/system/packages.xml that you suggested on my LineageOS 14.1 rooted Samsung Galaxy Tab Pro 8.4 so as to use the extSdCard for installing Fedora under termux in a place that has adequate storage. Unfortunately, it bricked my tablet; it no longer boots. (Guess I'll be reinstalling LineageOS.) Question: Does the certification signing key (?) get invalidated when I edit the file? Could this be why the tablet bricked? If so, how does one go about getting a new/correct key?

@srdegraaf Hi, I also did it on lineageos 14.1, but for a huawei phone, so I don't know why you got bricked. I don't know what a certification signing key is either. Nevertheless, as I understand, we cannot install termux, nor any other Linux distro, on external sdcard because that storage doesn't have execution permissions...

nor any other Linux distro, on external sdcard because that storage doesn't have execution permissions...

Certain directories with read write permission files CAN be placed on the external SDCard and symlinked back into internal storage. This only works with read write permission files, and is an experimental concept that appears to work to some extent with minimal effort. It might not be worth the effort in the long run. However, this method CAN save a lot of space on devices with small internal storage if it works properly.

I have a potentially elegant solution. I don't code java or whatever android speaks so I may be missing some ugly implementation problems. Create an app, an idiot file manager, that just does rm or mv or mkdir.
Get the app external access. run termux-uglyhack-rm.

Potential catch, I tried to use quickpic in a similar fashion via termux-send, the delete option was hidden. It may mean termux can't call the rm app directly and would have to do somethng nonstandard.

If this works I reccomend packaging it seperate for pay. Maybe even entirely seperate from termux as a general purpose set of utilities for everyone.

my current work around is a local copy of primitive ftpd and termux sftp with some scripting. disadvantages, mv and cp from sd to sd unavailable.

Was this page helpful?
0 / 5 - 0 ratings