3

Ive got most of the way to getting native sshd working over usb (mainly for shell and winscp), but very murky and not quite there yet. I want to use the built-in sshd, not download an app for it.

Lineageos has a built-in SSHD and ADB allows forwarding from local host:XXXX to the phone on port 22. I've got a sshd_config file ready (password for now, RSA later), and Terminal + su all working. By trial and error I've found the sshd-start or start-sshd files and I'm probably most of the way there. But its hard to reproduce a trial and error approach and I haven't actually got it there yet.

The furthest I've got is that I can run ssh (client) on the phone and it'll at least try to connect to itself (in another terminal window), but doesn't yet fully reach a shell prompt. It gave errors on /var/run/etc and on missing an 'empty' dir which I manually created and seem to help but I don't really know if that's the right or best way to do it.

Assuming I have a valid config file and a clean install with no changes, what are the basic steps from the start, so.I can enable native sshd, start/stop it manually (not started with system), and access it across adb?

I would like to use /sdcard/sshdata for any keys/config, so they are preserved across installing, and for the moment, password over adb via usb only (not WiFi). I'm happy to mod some sshd-related files in /system and probably need to, but I don't know which I need to change.

What is the simplest recipe to get sshd available so that I can fire it up and connect when needed?

1 Answer 1

5

AFAIK with LineageOS 14.1 (I have a rooted FairPhone 2), sshd is enabled by default and ready to use. Its config file is /system/etc/ssh/sshd_config which points to /data/ssh/ for keys storage. I guess you can reconfigure it to use /sdcard/. In theory, /data should be preserved across system updates, though I have not much experience to confirm it. The daemon needs to be started manually (this also generates the server's key pair; note that the start-ssh doesn't launch sshd in the background, hence the &):

$ adb root
phone # /system/bin/start-ssh & 

Alternatively, you might want to configure another sshd instance as explained here.

To have sshd start at each boot (I still haven't tried), one option is to use Termux:Boot. Be aware that having a daemon always running might drain your battery!

As for running ADB and SSH, you say

ADB allows forwarding from local host:XXXX to the phone on port 22

It is my understanding that this is not correct (unless you mean forwarding from a dev machine to another host which the phone is tethered to), as I don't see how adbd can handle encrypted connections. A quick sniff test with ngrep shows that my Wi-Fi connection on port 5555 is clear text.

Otherwise, make sure (I guess you already know it, but repetita iuvant...) that on your phone

  1. Developer options are enabled
  2. Developer options -> Root access is set to "ADB" or "Apps ADB"
  3. Developer options -> ADB over network is enabled

Then, on your computer terminal, the following command should get you on the go:

$ adb connect <your-android-host-name>
$ adb shell

...expect an excruciatingly slow, not encrypted connection :-(

3
  • To have sshd start at each boot (I still haven't tried), one option is to use Termux:Boot so there is no native auto-start for SSHD in Lineage?
    – Suncatcher
    Commented Dec 6, 2020 at 14:00
  • @Suncatcher, AFAIK, nope! This still
    – sphakka
    Commented Dec 7, 2020 at 15:29
  • 1
    (ouch, broken connection) ...still the case with LOS17.1
    – sphakka
    Commented Dec 7, 2020 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .