jacob
jacob

Reputation: 1427

run dropbear ssh server from android as system user

I created a custom rom and I want to run dropbear ssh server from a system ( signed ) service ( in order to have the system user privileges ) , but whatever command I try, after entering the password from the ssh client ( putty ) it just disconnects.

Is it even possible to run ssh server as system ?

Is there an alternative to dropbear that I could try ?

Upvotes: 1

Views: 6313

Answers (1)

luiso1979
luiso1979

Reputation: 918

I did it by installing optware here are the steps:

Optware

We need to install optware to manage packages in the apt-get style inside our android device. Of course, we won’t have all packages apt has, but we will have enough.

To install optware we need to access our device in debug mode this way we can access the console and run the optware install script.

To do so,

  1. install WIFI ADB in your device and run it, it will be accessible via device-id:5555.
  2. go to a linux (Debian, Ubuntu, ...) PC connected to the same network as the device and download the last Google ADT (download the right one for your linux platform)
  3. add the following to the PATH system variable:

     /folder_where_you_untar_adt/sdk/platform-tools
    
  4. now download the optware script for android

    • this script did not work for me out of the box due to unrecognized commands
    • I did some modifications, for instance removing some controls (I did not care about the File Exists errors) and modifying some functions and calls to adb shell specifying the command between quotes (otherwise it would not work).
    • Here you can see my file. You can compare it with the original using any merging tool to see the differences.
  5. run your modified (or not) ./optware-install-via-adb.sh

  6. run adb shell this opens a shell to your device

  7. if you type ls /data/opt you should see a start.sh (this is the bootstrap for optware)

  8. if you don't look at the optware script output there was some errors (mostly related with some command it could not execute via adb or something).

  9. Now make cd /data/opt

  10. Run start.sh

This should show you a Console and here you can type ipkg list to see the packages you have available.

Dropbear

This is a SSH server useful to connect to your TV BOX. Here I assume you just runned start.sh successfully. So inside your BusyBox (Console) do:

  1. type ipkg install dropbear -- to install the dropbear
  2. Then generate a server key: dropbearkey -t rsa -f dropbear_rsa_host_key
  3. Now we will generate a key/pair to connect from a ssh client. This is necessary because the root user in your android does not have a password.
    • dropbearkey -t rsa -f id_rsa
    • dropbearkey -f id_rsa -y > id_rsa.pub
    • mkdir /data/dropbear/.ssh
    • cat id_rsa.pub > /data/dropbear/.ssh/authorized_keys
  4. Also convert the private key to a compatible format for openssh
    • dropbearconvert dropbear openssh id_rsa id_rsa_openssh
  5. Run dropbear -r /data/dropbear/dropbear_rsa_host_key -E -s
  6. Now copy id_rsa and id_rsa_openssh to your client
  7. If you use openssh in your client then type

Now you should have a busybox prompt in your hands

Reboot script

To ensure each time you reboot the bootstrap gets executed you have to:

  1. Modify /data/opt/start.sh by adding before the /bin/sh line:

     dropbear -r /data/dropbear/dropbear_rsa_host_key -E -s
    
  2. Install the app Script Manager

  3. In Script Manager click - Menu - Scripts - Browser and navigate to the file /data/opt/start.sh. Then check the SU, Boot and Net icons.

  4. This way each time your device is rebooted the start.sh gets executed with dropbear on.

I hope this helps you in some way,

Best regards

Upvotes: 2

Related Questions