Native SSH server on LinageOS
I finally trashed my shitty Shift5.2 and got a spare OnePlus One from a good colleague.
tldr: scroll down to Setup of SSH on LineageOS.
I strongly discourage everyone from buying a ShiftPhone. The Phone was/is on Android patch level from 2017-03-05 – which is one and a half year ago! Not to mention that it was running an Android 5.1.1 in 2018… With soo many bugs and security issues, in my opinion this phone is a danger to the community! And nobody at Shift seemed to really care…
However, I now have a OnePlus One, which is supported by LineageOS - the successor of CyanogenMod. So, first action was installing LineageOS. Immediately followed by installing SU to get root access.
Next, I’d like to have SSH access to the phone. I did love the native SSH server on my Galaxy S2, which used to run CyanogenMod for 5+ years. Using the SSH access I was able to integrate it in my backup infrastructure and it was much easier to quickly copy stuff from the phone w/o a cable :)
The original webpage including a how-to for installing SSH on CyanogenMod has unfortunately vanished. There is a copy available from the WayBackMachine (thanks a lot guys!!). I still thought dumping an up-to-date step-wise instruction here may be a good idea :)
Setup of SSH on LineageOS
The setup of the native SSH server on LineageOS seems to be pretty similiar to the CyanogenMod version. First you need a shell on the phone, e.g. through adb, and become root (su). Then just follow the following three steps:
Create SSH daemon configuration
You do not need to create a configuration file from scratch, you can use
/system/etc/ssh/sshd_config as a template.
Just copy the configuration file to
Just make sure you set the following things:
Subsystem sftp internal-sftp
Update: Ed Huott reported:
There was one additional step I needed to make it work. It was necessary to set
/data/ssh/sshd_configin order to keep sshd from failing to start due to bad file ownership/permissions on the
/data/.sshdirectory and files as well as the parent
This is because the owner:group of
/datais system:system which doesn’t match either
shellowner:group used for
/data/.sshand its contents. I felt that setting
StrictModes nowas a better solution than messing with the owner:group of the
Setup SSH keys
We’ll be using SSH-keys to authenticate to the phone. If you don’t know what SSH keys are, or how to create them, you may go to an article that I wrote in 2009 (!!) or use an online search engine.
First, we need to create
/data/.ssh on the phone (note the
.!) and give it to the
Second, we need to store our public SSH key (probably stored in
~/.ssh/id_rsa.pub on your local machine) in
/data/.ssh/authorized_keys on the phone.
If that file exists, just append your public key into a new line.
Afterwards, handover the
authorized_keys file to the shell user:
Create a start script
Last but not least, we need a script to start the SSH service.
There is again a template available in
Just copy the script to
Finally, we just need to update the location of the
/data/ssh/sshd_config in our newly created
/data/local/userinit.d/99sshd script (in the template it points to
/system/etc/ssh/sshd_config, there are 2 occurences: for running the daemon w/ and w/o debugging).
You can now run
/data/local/userinit.d/99sshd and the SSH server should be up and running :)
Earlier versions of Android/CyanogenMod auto-started the scripts stored in
/data/local/userinit.d/ right after the boot, but this feature was removed with CM12..
Thus, at the moment it is not that easy to automatically start the SSH server with a reboot of your phone.
But having the SSH daemon running all the time may also be a bad idea, in terms of security and battery…
- network (67) ,
- software (155) ,
- security (29) ,
- administration (41) ,
- private (33) ,
- operatingsystem (14) ,
- howto (25) ,
- phone (5) ,
- cyanogen (4) ,
- lineageos (4)
- android (5) ,
- backup (5) ,
- config (21) ,
- cyanogen (4) ,
- lineageos (5) ,
- network (78) ,
- phone (5) ,
- private (30) ,
- remote (22) ,
- ssh (12) ,
- trick (60)
Leave a comment
There are multiple options to leave a comment:
- send me an email
- submit a comment through the feedback page (anonymously via TOR)
- Fork this repo at GitHub, add your comment to the _data/comments directory and send me a pull request
- Fill the following form and Staticman will automagically create a pull request for you:
On my lineage 18.1 I can not find /system/bin/start-ssh . is there another way?
Cheers and what a fine post, fellow mate. Meanwhile there isn’t any /system/bin/start-ssh on my phone, so it might be helpful to post the content of the templates you’re refering in case they’re absent.
I’m not sure if it’s the vanilla file or a version that I already messed around with, but here is one that found on my system: https://gist.github.com/binfalse/87755e1e6608647add36fa30ae6bd5ed