I accidentally ran apt update as root, and now I can't run it as a regular user anymore. Even before, I noticed some odd file permission issues, and they seem to be related. I don't know how to recover.
After running apt update as root, several files were set to root as owner and group, e.g.
$ ls -al ../usr/var/lib/apt/lists/termux.net_dists_stable_InRelease
-rw-r--r-- 1 root root 1684 2016-11-21 05:10 ../usr/var/lib/apt/lists/termux.net_dists_stable_InRelease
Now the weird thing is, even after resetting the permissions back to the regular user, the file remains inaccessible:
$ id
uid=10133(u0_a133) gid=10133(u0_a133) groups=10133(u0_a133)
# chown u0_a133:u0_a133 ../usr/var/lib/apt/lists/termux.net_dists_stable_InRelease
$ ls -al ../usr/var/lib/apt/lists/termux.net_dists_stable_InRelease
-rw-r--r-- 1 u0_a133 u0_a133 1684 2016-11-21 05:10 ../usr/var/lib/apt/lists/termux.net_dists_stable_InRelease
$ cat ../usr/var/lib/apt/lists/termux.net_dists_stable_InRelease
cat: ../usr/var/lib/apt/lists/termux.net_dists_stable_InRelease: Permission denied
What could be the reason?
This is because the folder the list is in is also owned by root now. to revert all termux files back to proper ownership, you can do:
chown -R u0_a133:u0_a133 ../usr
@icebal Thanks for your reply. That sounds like a plausible cause, but unfortunately was not the reason for me. I can access and list the folder just fine as u0_a133.
After testing with running apt as root real quick, I had to remove this list, run apt update again, and it worked. This is after changing the permissions back via the command I posted above
I'm thinking about patching apt so that it always runs as the normal Termux user (u0_a133), so that even if one happens to run it as root nothing bad happens.
@icebal By removing the list you mean removing only the one file? Or the whole lists folder? I'm still wondering why the file is inaccessible even though it has the right permissions.
I got hit by this as well. Something to do with selinux?
[249813.216956] c0 416 type=1400 audit(1481496265.114:13457): avc: denied { unlink } for pid=28207 comm="apt" name="pkgcache.bin" dev="sda35" ino=1025862 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0 tclass=file permissive=0
Update: It is indeed selinux. You can use the following command (as root) to easily fix the permissions:
restorecon -Rv /data/data/com.termux.
@hackel Perfect!! That immediately fixed all my issues. Thanks so much
I didn鈥檛 have restorecon installed, but simple removal (as sudo / using tsu)solved the problem:
rm /data/data/com.termux/files/usr/var/lib/apt/lists/termux.net_dists_stable_*
$ apt update
Reading package lists... Error!
W: Target Packages (x-gui/binary-all/Packages) is configured multiple times in /data/data/com.termux/files/usr/etc/apt/sources.list:2 and /data/data/com.termux/files/usr/etc/apt/sources.list:5
W: Target Packages (x-gui/binary-arm/Packages) is configured multiple times in /data/data/com.termux/files/usr/etc/apt/sources.list:2 and /data/data/com.termux/files/usr/etc/apt/sources.list:5
W: Target Packages (x-gui/binary-all/Packages) is configured multiple times in /data/data/com.termux/files/usr/etc/apt/sources.list:2 and /data/data/com.termux/files/usr/etc/apt/sources.list:6
W: Target Packages (x-gui/binary-arm/Packages) is configured multiple times in /data/data/com.termux/files/usr/etc/apt/sources.list:2 and /data/data/com.termux/files/usr/etc/apt/sources.list:6
W: Target Packages (x-gui/binary-all/Packages) is configured multiple times in /data/data/com.termux/files/usr/etc/apt/sources.list:2 and /data/data/com.termux/files/usr/etc/apt/sources.list:7
W: Target Packages (x-gui/binary-arm/Packages) is configured multiple times in /data/data/com.termux/files/usr/etc/apt/sources.list:2 and /data/data/com.termux/files/usr/etc/apt/sources.list:7
W: Target Packages (x-gui/binary-all/Packages) is configured multiple times in /data/data/com.termux/files/usr/etc/apt/sources.list:2 and /data/data/com.termux/files/usr/etc/apt/sources.list:8
W: Target Packages (x-gui/binary-arm/Packages) is configured multiple times in /data/data/com.termux/files/usr/etc/apt/sources.list:2 and /data/data/com.termux/files/usr/etc/apt/sources.list:8
E: Couldn't create temporary file to work with /data/data/com.termux/files/usr/var/lib/apt/lists/termux.net_dists_stable_InRelease - mkstemp (2: No such file or directory)
E: The package lists or status file could not be parsed or opened.
What to do please help
@Muhaiminkp why you added my repository (with gui packages) multiple times ?
Edit /data/data/com.termux/files/usr/etc/apt/sources.list file by removing all lines containing https://xeffyr.github.io/termux-x-repository/.
@xeffyr yes, I think it come from a script That I run for more times and I edit my source list now but it tells
$ apt update
Err:1 https://termux.net stable InRelease
Couldn't create temporary file /data/data/com.termux/files/usr/tmp/apt.conf.wVMR6V for passing config to apt-key
Reading package lists... Done
W: GPG error: https://termux.net stable InRelease: Couldn't create temporary file /data/data/com.termux/files/usr/tmp/apt.conf.wVMR6V for passing config to apt-key
E: The repository 'https://termux.net stable InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
@Muhaiminkp You have something strange.
Try to replace content in sources.list with
deb [arch=all,arm] https://termux.net stable main
I have the same problem as muhikahdvbddnsb.
Im on an "un rootable" alcatel fierce 4 running 6.0 marsh and have been just under fist fighting this mother f@#$%& to get to root permission. (If they set we can unset it and make it do what we want)
Ive gotten as far as having a "ls" command come back with a "udo su"
Im delving into metasploit and was doing very well untill i guess i flipped a rock in the middle of the phone based grabd canyon and cant undo what either i have done or my bi&%$ a$# phone has un-done.
It fights me every step of the way making nothing easy.
I understand metro has locked its boot process like fort knox.
If i can get any help i will share whatever information i have collected thus far.
I just need a little guidance and maybe someone to back-n-forth with.
I know its possible. If it wasnt than whats the point of having a fu%$&#& phone if i cant do what i want with it.
-LLAP
thank you! i couldn't even use termux because i kept getting
exec("/data/data/com.termux/files/usr/bin/login"): Permission denied
nothing i did seemed to matter. i've been using "adb shell" and root to try to fix things. then i found the following (in dmesg):
[202048.664070] type=1400 audit(1556809111.268:4405): avc: denied { open } for pid=32399 comm="com.termux" path="/data/data/com.termux/files/usr/bin/login" dev="sda35" ino=4983472 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:app_data_file:s0 tclass=file permissive=0
searching for that lead me to this thread. (keep in mind i already changed all ownership of /data/data/com.termux back to the original uid). but then i did this:
restorecon -Rv /data/data/com.termux
that made selinux reset all the permissions, and i can now open Termux.
thanks!
HELP ME
$ apt update
E: Opening /data/data/com.termux/files/usr/etc/apt/sources.list - ifstream::ifstream (13: Permission denied)
E: The list of sources could not be read.
@IFINDYOU1
chown $(stat --format="%U" /data/data/com.termux) /data/data/com.termux/files/usr
/system/bin/restorecon -R /data/data/com.termux/files/usr
$ chown $(stat --format="%U" /data/data/com.termux) /data/data/com.termux/files/usr
$ /system/bin/restorecon -R /data/data/com.termux/files/usrselinux_android_file_context_handle: Error getting file context handle (No such file or directory)
@IFINDYOU1 These commands should be executed as root.
Thanks :)
Most helpful comment
Update: It is indeed selinux. You can use the following command (as root) to easily fix the permissions:
restorecon -Rv /data/data/com.termux.