[LineageOS Questions & Answers] botsarehots:
Introduction:

Hello smarter people. I've been trying to run an ssh server on my phone. My phone is encrypted with the standard tools provided by Lineage OS. I believe the phone's encryption is causing the ssh daemon to loose access to the file found in /data/data/com.termux/files/home/.ssh/authorized_keys (reasoning in My Possible Solution and Question section). If I could make this file unencrypted somehow, it would likely solve the issue and allow me to ssh into my phone's server from my Ubuntu machine (or at least let me start troubleshooting further arising issues. :)).

I know the version of Lineage OS that I am using is unofficial, but if this is possible, it should be the same process.

Specific Technologies:

Unofficial Lineage OS Android 8.0.0 on Moto G5 Plus..

This phone is encrypted using the encryption tool found at Settings --> Security & Location --> Encryption & credentials --> Encrypt phone

Using the latest version of the Termux application installed through the Google Play store.

Using the latest version of the openssh package installed through through Termux's apt package manager.

Specific Problem

I am familiar with setting up ssh servers, so I believe I did the configuration correctly. Since this was on my phone and I wanted manual control, I installed openssh through Termux's apt package manager, appended my public key to the ~.ssh/authorized_hosts file (the only thing in the file), started the daemon with sshd, and finally ssh'ed in from my Ubuntu computer. Here is a link on how to do this from Termux.

On my Ubuntu computer I get this:

myusername@ubuntu:~$ ssh 192.168.0.101 -p 8022
Permission denied (publickey,keyboard-interactive).

When viewing the logs with logcat -s 'syslog:*' I get the following output:

12-24 16:29:01.209 13972 13972 I syslog : sshd - Server listening on :: port 8022.
12-24 16:29:01.210 13972 13972 I syslog : sshd - Server listening on 0.0.0.0 port 8022.
12-24 16:29:52.029 14131 14131 I syslog : /data/data/com.termux/files/usr/bin/sshd - Connection closed by authenticating user myusername 192.168.0.123 port 59614

My Possible Solution and Question

Based on a few hours of troubleshooting I believe that since my phone is encrypted, the ssh daemon cannot read the authorized_keys file correctly, or some other issue origination from the phone's encryption to the authorized_keys file. I found someone having a similar issue at this link, which is why I believe the encryption is the source of the problem. Unfortunately the encrypted environment that was causing them issues was on a CentOS server with an encrypted home folder and mine is on a Lineage OS phone with pretty much total encryption(?).

If you were wondering if the solution posted to the link above works, here is the log output:

[12-24 17:00:00.768 17585 17585 I syslog : /data/data/com.termux/files/usr/bin/sshd - Authentication refused: bad ownership or modes for directory /data/data
12-24 17:00:02.146 17585 17585 I syslog : /data/data/com.termux/files/usr/bin/sshd - Connection closed by authenticating user myusername 192.168.0.123 port 59760

I do not believe a change in that /data/data directory's permissions would stop the root error as the full path to each authorized_keys file is /data/data/com.termux/files/home/.ssh/authorized_keys and /data/data/com.termux/files/usr/etc/ssh/mytermuxusername/authorized_keys which are both contained in the /data/data directory.

Does anyone know how to make my authorized_key file unencrypted on Lineage OS (just for Termux) by either moving it to a non encrypted directory or through some other, fancier means? I would love to hear how to do this. Or if you have identified a different source of the issue, that would be equally appreciated!