GithubHelp home page GithubHelp logo

tianmulake / openssh-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dmikushin/openssh-android

0.0 0.0 0.0 18.78 MB

Minimal OpenSSH client/server with patches for Android cell phones

License: Other

Shell 6.92% C++ 0.13% C 82.47% Awk 0.18% KRL 0.11% Makefile 1.14% M4 3.07% Dockerfile 0.02% Roff 5.96%

openssh-android's Introduction

Minimal OpenSSH client/server with patches for Android cell phones

OpenSSH is a complete implementation of the SSH protocol (version 2) for secure remote login, command execution and file transfer. It includes a client ssh and server sshd, file transfer utilities scp and sftp as well as tools for key generation (ssh-keygen), run-time key storage (ssh-agent) and a number of supporting programs.

This is a port of OpenBSD's OpenSSH to most Unix-like operating systems, including Linux, OS X and Cygwin done by https://github.com/openssh/openssh-portable, and further tailored to limited Android environment (adb shell). Android shell does not provide user names and account information, such as /etc/passwd. Furthermore, this version limits encryption protocols to internal implementations. As a result, a complex dependency on libcrypto is lifted off, and ed25519 becomes the only supported (and still - the best one!) encryption protocol (that is, no DSA or RSA support). The low-level installation process involves access to the base system and therefore requires a bootloader with permissive recovery mode, such as TWRP. Android-specific domain name resolution is delegated to an external nslookup executable.

Documentation

The official documentation for OpenSSH are the man pages for each tool:

Building Portable OpenSSH for Android

The instructions below assume armv7. You may need to adjust the compiler to target armv8 (arm64) variant.

  • Obtain GCC ARM cross toolchain:
sudo apt install gcc-arm-linux-gnueabi
  • Build Musl:
git clone git://git.musl-libc.org/musl
cd musl
mkdir build
cd build
../configure --prefix=$(pwd)/../install

Make a small change into the system(char*) implementation:

--- a/src/process/system.c
+++ b/src/process/system.c
@@ -32,7 +32,7 @@ int system(const char *cmd)
        posix_spawnattr_setsigmask(&attr, &old);
        posix_spawnattr_setsigdefault(&attr, &reset);
        posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK);
-       ret = posix_spawn(&pid, "/bin/sh", 0, &attr,
+       ret = posix_spawn(&pid, "/system/bin/sh", 0, &attr,
                (char *[]){"sh", "-c", (char *)cmd, 0}, __environ);
        posix_spawnattr_destroy(&attr);

Then proceed to building and installation:

make -j12 && make install
git clone https://github.com/dmikushin/openssh-android
cd openssh-android
autoconf
mkdir build
cd build
LDFLAGS=-static CFLAGS="-D__ANDROID__ -O3 -fomit-frame-pointer -ffast-math" CC=$(pwd)/../../musl/install/bin/musl-gcc ../configure --prefix=$(pwd)/../install --host=arm-linux-gnueabi --without-zlib --without-openssl

Installation

Reboot your phone into accessible recovery mode, such as TWRP. Mount /system partition as writable and use adb to roll the compiled OpenSSH binaries:

adb push ./ssh /system/bin/
adb push ./sshd /system/bin/
adb push ./ssh-keygen /system/bin/
adb push ./sshd_config /system/etc/ssh/

Furthermore, we would want to generate the host SSH keys by manually calling ssh-keygen:

adb shell
ssh-keygen -f /system/etc/ssh/ssh_host_ed25519_key -N '' -t ed25519

Generate another key pair to be used for remote authentication:

adb shell
ssh-keygen -f /system/etc/ssh/ssh_user_key -N '' -t ed25519
mv /system/etc/ssh/ssh_user_key.pub /system/etc/ssh/authorized_keys
exit
adb pull /system/etc/ssh/ssh_user_key ./
adb shell rm /system/etc/ssh/ssh_user_key

Deployment

Reboot the phone into Android and launch the SSH server:

adb shell
/system/bin/sshd
exit

Given that the phone has a reachable IP address (e.g. the phone is connected to your home wireless router), connect to it directly:

$ ssh 192.168.12.202 -p 2222 -i ./ssh_user_key
shell@alto5_premium:/ $ uname -a
Linux localhost [email protected]_rb1.29-MIUI-Kernel #1 SMP PREEMPT Tue Jan 9 15:35:54 MSK 2018 armv7l GNU/Linux

openssh-android's People

Contributors

djmdjm avatar daztucker avatar mouring avatar mfriedl avatar dmikushin avatar jonathangray avatar djm-google avatar ischwarze avatar botovq avatar github-cygwin avatar rubenk avatar bluhm avatar 4a6f656c avatar nkadel avatar hogand avatar hallexander avatar bob-beck avatar sebastianbenoit avatar fobser avatar jcourreges avatar klemensn avatar natano avatar omoerbeek avatar semarie avatar stspdotname avatar inferno-chromium avatar alanyee avatar dag-erling avatar dodys avatar enh-google avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.