HOW TO: Native SSHd on Android

Search This thread

Dimath

Senior Member
Nov 5, 2008
77
1
Los Angeles
BTW, sshd returns "Segmentation fault", which is also could be related to getpwnam("username") returning NULL (if you try to use the returned structure which is NULL you'll get this error).

So, any ideas so far?
 
Last edited:

Stericson

Retired Senior Mod / Retired Senior RD
Nov 10, 2008
1,203
417
This keeps failing on me:

busybox cp -s busybox cp

Even when I am in /system/bin why is this?

I gave busybox 4755 permissions.

[Edit]

I got it to work...I had to go into the adb shell....strange
 
Last edited:

mzet

Senior Member
Mar 23, 2008
67
12
broken links

Hi,
links are broken. Can someone please post dropbear as attachment?

Thanks
 

jblomer

New member
May 12, 2009
1
0
If you don't want to setup a user database (/etc/passwd), you can also patch the dropbear code a little. I have it done here.
 

threaded

New member
Aug 3, 2009
1
0
Please, somebody, share 'dropbear' and 'dropbearkey' binaries

I also confirm that the author's links are broken. I ask somebody to share the binaries or to send them to my email: dark.diver (at) mail.ru

Thnx
 

oma

Member
Sep 22, 2005
38
43
I don't have the original binaries posted in this thread, but I have ones I compiled myself. It's dropbear-0.52 with patches from:

http://jblomer.web.cern.ch/jblomer/android.htm
http://www.mail-archive.com/android-freerunner@android.koolu.org/msg01076.html

Mostly the former with just the openpty function from the latter (because it couldn't open a pty otherwise on my Samsung Galaxy).

Just put dropbear, dropbearkey and scp in /system/bin and then start dropbear as described in the first link.
 

Attachments

  • dropbear.zip
    154.7 KB · Views: 487

oma

Member
Sep 22, 2005
38
43
does the file that says patch need to be on the phone?

No, this is only needed if you want to build it yourself. The files you really need on your phone are dropbear, dropbearkey, and scp.

(scp isn't strictly necessary, but it's quite convenient for copying files to/from your phone over wifi. Also, after you've generated your host key, dropbearkey isn't needed any longer.)
 

professordes

Member
Aug 8, 2009
46
5
dropbear on HTC Hero anyone?

I don't have the original binaries posted in this thread, but I have ones I compiled myself. It's dropbear-0.52 with patches from:

http://jblomer.web.cern.ch/jblomer/android.htm
http://www.mail-archive.com/android-freerunner@android.koolu.org/msg01076.html

Mostly the former with just the openpty function from the latter (because it couldn't open a pty otherwise on my Samsung Galaxy).

Just put dropbear, dropbearkey and scp in /system/bin and then start dropbear as described in the first link.

I had a go at running dropbear on a rooted HTC Hero and was a bit puzzled by the behaviour. When I booted the phone using the boot.img.insecure originally used to carry out the rooting as described in:

http://phandroid.com/2009/08/04/how-to-gain-root-access-on-your-htc-hero/

and started dropbear with:

dropbear -A -N justme -U 0 -G 0 -C <passwd> -r /system/etc/my_rsa_key -p 2222

(where justme was a cloned root user I had set up) I found I could happily ssh into the phone with ssh justme@ipaddress -p 2222. However, when I executed the same command after booting the phone from the native ROM it would hang after asking for the password. Would anyone have an idea what is going on?
 

oma

Member
Sep 22, 2005
38
43
I had a go at running dropbear on a rooted HTC Hero and was a bit puzzled by the behaviour. When I booted the phone using the boot.img.insecure originally used to carry out the rooting as described in:

http://phandroid.com/2009/08/04/how-to-gain-root-access-on-your-htc-hero/

and started dropbear with:

dropbear -A -N justme -U 0 -G 0 -C <passwd> -r /system/etc/my_rsa_key -p 2222

(where justme was a cloned root user I had set up) I found I could happily ssh into the phone with ssh justme@ipaddress -p 2222. However, when I executed the same command after booting the phone from the native ROM it would hang after asking for the password. Would anyone have an idea what is going on?

I don't know what's wrong, but you can see what's going on if you add "-F -E" to the dropbear command.
 

Bieh

New member
Aug 4, 2009
2
1
So, I've managed to get this running properly ('dropbear -A paul -C <passwd> -R /sdcard/authorized_keys -U0 -G0'). I had an issue where upon logging in $PATH would be set incorrectly, but I added a .profile file to fix this. I also use 'ash && exit' at the bottom of .profile, which makes it start ash on login, then logout when ash exits. All seems to work great now.

However I still have to start dropbear manually - I tried adding the launch line to /system/init.rc, but no luck. Anyone have any tips on how to make the dropbear service start on boot?
 
Last edited:

Bieh

New member
Aug 4, 2009
2
1
For anyone who's still struggling with it, I got it working. All I did was add:

service sshd /system/bin/sh /system/bin/rundropbear
oneshot

to the end of /system/init.rc. This calls my rundropbear script which is simply:

#!/system/bin/sh
dropbear -A paul -C <password> -R /system/etc/dropbear/authorized_keys -U0 -G0

And now I can log in with paul@phone, with password and sshkey auth :)
 
  • Like
Reactions: osiixy

professordes

Member
Aug 8, 2009
46
5
I don't know what's wrong, but you can see what's going on if you add "-F -E" to the dropbear command.

Good idea :) - what I see on the phone after starting dropbear from
an adb shell over usb is:

password auth succeeded for 'justme' from 192.168.2.10:5624

and what I see on the machine trying to login is now:

exit after auth (justme): couldn't change user as non-root
Connection to 192.168.2.31 closed.

I get a similar message if I set dropbear running for root

exit after auth (root): couldn't change user as non-root
Connection to 192.168.2.31 closed.

do I need to do some tinkering with passwd and group?
 

seaweeduk

Senior Member
Aug 19, 2009
316
4
Hi all, I have recently had some problems trying to configure the dropbear ssh server under cyanogen 4.0.2

I had previously managed to setup a working version of this program by using some files attached earlier in this thread and starting dropbear with a specific username and password defined.

I was excited to see dropbear added in cyanogen 4.0.2 because this had been confusing to setup as the links in this thread no longer worked and I hadn't yet found a way to make the server run at startup. However since upgrading I have been unable to get the version of dropbear included with cyanogen 4.0.2 to allow me to login.

I understand that this version of the server does not contain the ability to define a username and password and am unsure as to how I need to login. I have managed to get the server running on my phone (after generating rsa and dss keys using dropbearkey and putting them in /data/dropbear/) however I cannot find a way to define the username and password so have been unable to login to my phone via ssh.

I was hoping someone could point me in the right direction as a working ssh server on my phone would be a major advantage to myself and no doubt many others.
 
Last edited:

seaweeduk

Senior Member
Aug 19, 2009
316
4
After some reading it seems I may not need a password to login to ssh but instead can use keys

I have generated rsa and dsa keys as mentioned earlier however everything I have managed to read with regards to linux and using keys involves generating a "private" and "public" key??. I do not have the ability to do this on my g1 as far as I know.

Do I just need to use the rsa key I have already generated on my phone to login, if so how?
 

seaweeduk

Senior Member
Aug 19, 2009
316
4
Has anyone gotten scp to work? I receive the following error

TRACE: enter sign_key_free
TRACE: enter dsa_key_free
TRACE: leave dsa_key_free
TRACE: enter rsa_key_free
TRACE: leave rsa_key_free
TRACE: leave sign_key_free
scp: not found
lost connection
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    After many hours of yelling and screaming at my linux dev box, I finally got everything working so I can cross compile and port in theory any application to Android. Obviously the first step was to get SSHd working on the phone, specifically dropbear since it is much simpler than openssh.

    Follow these exactly and you should have a running dropbear daemon.

    If you have already rooted your phone and have busybox on your phone, I HIGHLY recommend walking through this to make sure you have done everything that is listed. There are a few things you must do for dropbear to work correctly

    NOTE: I have not been able to login yet! I have been unable to find the password data for the phone. It is asking for a password when you login with root. And yes, I have tried no password and also common ones along with "android". All result in me still being locked out.

    With that out of the way, lets begin. I am assuming you have a virgin G1. I will walk you through the entire procedure.

    PART 1 - ROOTING YOUR PHONE

    1. Download pTerminal from the marketplace or from http://android-dls.com/files/src.com.poidio.terminal.apk. If you choose to download the file from the link provided, download it on the phone by going to this forum post and long holding the link.

    2. Run pTerminal and type

    Code:
    cd /system/bin

    and then

    Code:
    telnetd

    3. Connect the phone to your wifi and go back to pTerminal and run:

    Code:
    netstat

    This will show you the local ip of the G1.

    4. Using your favorite telnet client, connect to your phone on the default telnet port 23.

    PART 2 - BUSYBOX

    5. Welcome to root access :) We now need to get busybox on the phone. Again, pull up this thread on your phone and long hold the following link: http://staulkor.com/android/busybox.xxx. Dont mind the .xxx extension. Browser wont let you download certain extension types. The xxx will be renamed to asc automatically.

    6. We now need to remount /system because it is currently read only. After that we will copy busybox off the sdcard and put it in the bin directory and then make it executable. Go to your telnet app and type:

    Code:
    mount -o remount,rw /dev/block/mtdblock3 /system
    dd if=/sdcard/download/busybox.asc of=/system/bin/busybox
    chmod 4755 /system/bin/busybox
    cd /system/bin
    busybox cp -s busybox cp

    You now have access to the cp command. You can use that syntax to make a symlink to any of the busybox commands. MAKE SURE you do NOT overwrite the default symlinks. They have special syntaxes and you will most likely break things.

    PART 3 - DROPBEAR

    7. Now that you have busybox and the cp command (you MUST have the cp command), we need to create a directory.

    Code:
    mkdir /system/etc/dropbear

    This is where the encryption keys will be kept.

    8. Now you have the required directory, you can download dropbear and dropbearkey.

    Dropbear - http://www.staulkor.com/android/android-dropbear-0.51.rev1.xxx
    Dropbearkey - http://www.staulkor.com/android/android-dropbearkey-0.51.rev1.xxx

    Again, download them on the phone by long pressing each link and saving it.

    I am using version 0.51 of dropbear. The rev1 is so you know what revision of the android port it is. Changes may have to be made and recompiled and I want to make sure you guys can tell the versions apart short of an md5 hash :)

    9. Now that they are downloaded, they again change the .xxx extension to .asc automatically. We need to move them to /system/bin and make them executable.

    Code:
    cp /sdcard/download/android-dropbear-0.51.rev1.asc /system/bin/dropbear
    cp /sdcard/download/android-dropbearkey-0.51.rev1.asc /system/bin/dropbearkey
    chmod 4755 /system/bin/dropbear
    chmod 4755 /system/bin/dropbearkey

    10. Now we have to create the encryption keys. If you do not create them, dropbear will not run at all.

    Code:
    dropbearkey -t rsa -f /system/etc/dropbear/dropbear_rsa_host_key
    dropbearkey -t dss -f /system/etc/dropbear/dropbear_dss_host_key

    11. Now dropbear is totally installed. You can run it by typing:

    Code:
    dropbear

    To check if it is running, type:

    Code:
    ps

    and to make sure it is listening, type:

    Code:
    netstat

    and look for the 0.0.0.0:22 LISTENING

    At any point if you have to kill dropbear, you will need to run ps, find the PID and then do "kill <pid>" without the brackets of course.

    12. Now we can try to login to the phone. I run Vista on my main box, so I use putty for my ssh/telnet client. If you use linux/osx and type:

    Code:
    ssh root@<ip address of G1>

    You should be able to connect to the phone and it will ask for a password.

    13. ?????????? -- We need to be able to login. I cant find any password data on the phone. I am looking for that data to see if there is even a password, or if it would be possible to create a password, or a new user, or something.

    Enjoy! :D

    Credits:
    Rooting the phone - http://android-dls.com/forum/index.php?f=15&t=151&rb_v=viewtopic
    Busybox - http://android-dls.com/forum/index.php?f=15&t=153&rb_v=viewtopic
    And big thanks to DarkriftX for making those tutorials and helping the cause :)
    1
    Looks like somebody beat you to it!

    http://www.upche.org/doku.php?id=wiki:android4

    This is only confirmed on the emulator. I guess install dropbear on the emulator (watch out, when you close the emulator, you will have to reinstall everything again the next time it boots up) and then try this out and see if you can login.
    1
    For anyone who's still struggling with it, I got it working. All I did was add:

    service sshd /system/bin/sh /system/bin/rundropbear
    oneshot

    to the end of /system/init.rc. This calls my rundropbear script which is simply:

    #!/system/bin/sh
    dropbear -A paul -C <password> -R /system/etc/dropbear/authorized_keys -U0 -G0

    And now I can log in with paul@phone, with password and sshkey auth :)
    1
    Binaries

    Hey guys,

    This thread hasn't had any activity since last month, but since no one else posted them, I thought I should put some dropbear binaries up for people to use.

    I did not compile these, instead I shamelessly extracted them from someone else's rom. They look to be compiled without any changes, so it's probably cool, but if he contacts me, i'll pull them.

    I don't know how to put them into an update.zip for flashing, so you'll have to copy them to your phone manually. I REPEAT, YOU CANNOT FLASH THE ATTACHED ZIP, AND HAVE TO EXTRACT IT AND COPY THE FILES OVER MANUALLY. I've included instructions below.

    If you push the 95dropbear file, it will start on boot. I have not noticed any battery loss associated with leaving dropbear running, waiting for connections.

    Login as root, pw is password. you can change the password by editing the 95dropbear file (replace -Y with -C if you want to use a cleartext password)

    Terminal Emulator:
    Code:
    mount -o remount,rw /system
    cp /sdcard/dropbear /system/bin/dropbear
    cp /sdcard/dropbearkey /system/bin/dropbearkey
    cp /sdcard/95dropbear /system/etc/init.d/95dropbear
    chmod 755 /system/bin/dropbear /system/bin/dropbearkey /system/etc/init.d/95dropbear

    ADB:
    Code:
    adb remount
    adb push dropbear /system/bin/dropbear
    adb push dropbearkey /system/bin/dropbearkey
    adb push 95dropbear /system/etc/init.d/95dropbear
    adb shell chmod 755 /system/bin/dropbear /system/bin/dropbearkey /system/etc/init.d/95dropbear