cirosantilli / cirosantilli.github.io

Source for: https://cirosantilli.com and https://ourbigbook.com/cirosantilli Build HTML with https://github.com/ourbigbook/ourbigbook with "npm install && npx ourbigbook ." You can use this issue tracker for anything you want to tell me, even if it is not related to the repo. I also use this repo as generic issue tracker for myself.
https://cirosantilli.com
Creative Commons Attribution Share Alike 4.0 International
42 stars 9 forks source link

How can I communicate with an Android device via SSH? #54

Open cirosantilli opened 4 years ago

cirosantilli commented 4 years ago

https://stackoverflow.com/questions/11468053/how-can-i-communicate-with-an-android-device-via-ssh/34040560#34040560

SSH server apps

SSHDroid App is a possibility, and there are many others available from Google Play (search for SSHD).

  1. Get your Android and PC on the same LAN.

  2. Open SSHDroid

  3. Note the "Address" field shown on the app. It should look something like root@192.168.0.3:2222.

    You could also use netcfg + adb to get the device IP from the CLI.

  4. Install an SSH client on your PC, e.g.:

    sudo apt-get install openssh-client

    on Ubuntu 15.10

  5. Run on your PC:

    ssh root@192.168.0.3 -p 2222
  6. It says:

    Default password is 'admin'
    root@192.168.0.3's password:

    So type admin and enter.

  7. We're in. Try ls. But note that:

    • many folders are not accessible without rooting your device. In particular, each app has it's own Linux user, and you are logged in as the SSHDroid user.

    • an Android device is not a POSIX system, and in particular POSIX CLI utilities may be missing, e.g. cal (how could you live without that?)

  8. The SSH server continues running on Android as a daemon even if the SSHDroid window is closed. To stop it you must go on the app and click STOP.

I have also tried SSH Server from Ice Cold Apps. It is definitely more powerful, allowing multiple connections and other protocols, but it required a bit more setup.

Tested on Ubuntu 15.10, Android 5.1.1. SSHDroid 2.1.2.

adb shell USB

If you just want to quickly get a shell on your USB connected device to help development, install the SDK, enable debugging and do:

adb shell

it's the simpler way.

I only came here because I had never done Android development before and thought: need a shell on another computer... SSH! But sometimes mobile is different.

For file transfers, you want adb pull and adb push.

adb shell TCP

If you don't have USB access to the device, you can also connect adb shell over TCP, which provides a solution very similar to ssh.

More details: https://stackoverflow.com/questions/2604727/how-can-i-connect-to-android-with-adb-over-tcp