Android ssh client github
sftp (secure file transfer program) client that uses FUSE to mount files and directories served by any SSH server to an android client, secure enough to mount over the internet
The code is mostly from the FUSE project’s sshfs implementation, found here. It’s been adapted to compile into the cyanogenmod android rom.
This project will allow you to securely mount a folder served up by an ssh server to your android device from anywhere with a network connection.
A typical use case for this would be that you have a phone with 8GB of non-expandable storage and you want access to your 100GB music collection while you’re on the go (either via cell or Wi-Fi data access). This project allows all the apps on your phone to see your entire music/movie/book/document/whatever collection as if your files were on your device (if your data connection permits it).
This project provides (for free) the functionality promised by the currently broken and
$2.75 app in the play store called SSHFSAndroid.
How to build and install
This module will build a single binary executable file: ‘sshfs’ that will be installed into /system/xbin on your device, if you follow the instructions provided.
During the installation, some glib-2.0 libraries will also be built and installed on your phone.
This was only tested under cyanogenmod cm-10.2. It’ll probably work fine in other roms so long as they have FUSE support.
However, it should be noted that there have been reports with this not working properly in CM12+ (Lollipop). If, after you build this, the sshfs directory structure disappears after opening a file, rest assured that the developer is working to find the source of the problem.
It should also be noted that this has only been tested with SuperSu. You may come across unknown issues when using a different SU app.
These steps assume:
- You have a working cyanogenmod or cm-based rom’s build environment with the rom’s source tree located in
/android/system (see here for instructions on how to get this, and consult your rom’s forum thread or auther regarding its source if you have a cm-based rom)
Note: These instructions will differ if you are building in a system other than a Linux distro. Mac and Windows users will need to either run a Virtual Machine for the build environment (recommended) or consult a CyanogenMod build guide that is specific to their operating system (and their operating system’s release version, most likely).
To build and install onto your device, issue the following commands in your build environment:
Running the lunch command will prompt you to choose a device. Choose the device that your source tree supports (presumably the one you are building for).
. Your phone should be plugged in at this point .
After a successful compile, you should see something like this at the end of your terminal’s output:
If you see that, you know the binary was built and pushed successfully to your device. If you don’t see that, make sure you have a proper build environment. Usually these commands will show errors pointing to missing files. If it fails to find a file in «
/android/system/vendor/. » and you have already successfully built your rom with your source tree, you most likely chose the wrong device when you ran «lunch» or you never ran it at all.
In a shell on your android device type sshfs -h , you’ll see:
The following example assumes:
- You already have an ssh server running somewhere on a machine with hostname (or IP) SERVER that you can log into as USER
- You have created an empty directory on your device to mount to at the following location: /data/media/0/sshfsmount
- You have turned off namespace separation in your SU app, if the option exists. If you are running certain android versions and you have SuperSu (which is recommended for 4.0+), you can turn this off in SuperSu’s settings. Be aware that if namespace separation is on, you will not be able to access the files outside of the app you use to initiate the connection, because namespace separation forces fuse-mounted directories to be on a per-app basis. If you change this setting, it is recommended to reboot your device before testing sshfs.
Make sure /data/media/0/sshfsmount exists and is an empty directory.
In a shell on your android device type:
Replace USER with your ssh login name and SERVER with the server hostname or IP address (note the colon after SERVER is intentional). You will be asked for your ssh password for USER.
- -o ro means you’ll mount the files as read only (recommended to prevent file damage because this project is experimental)
- -o allow_other sets the permissions of the mounted files so that you can access them
- -o follow_symlinks enables symlinks in your ssh share to work properly
- -o StrictHostKeyChecking=no bypasses a prompt for a security measure used to prevent MITM attacks
- -o reconnect allows for reconnection after interruption in network service
- -o TCPKeepAlive=no prevents interruptions in network connectivity from bringing down the connection
When the sshfs command completes successfully you’ll be dumped back to the command line with no indication that it worked. You can verify that the mount completed properly by issuing ls /data/media/0/sshfsmount you should see the directory structure of your ssh home directory.
To mount a directory on the ssh server other than your home directory, add it after the colon USER@SERVER:/some/path/to/mount
Any failed attempts at mounting will likely leave the mount point directory «dirty». This prevents the success of any future mount attempts. The «dirty» mountpoint can be «cleaned» by unmounting it with the following command. It’s good practice to execute this command any time something goes wrong to ensure that future attempts at mounting are not foiled by a «dirty» mount point directory.
It’s a real drag to have to enter your password every time you want to connect to your server. Especially if you’re trying to automate the process. Follow these steps to setup public key authentication to log into your server without typing in a password on your device.
In a shell on your android device type:
Press enter at the prompts here to generate a key with no passphrase. Your public key should now be in /data/.ssh/id_rsa.pub Now copy this key to your ssh server like this:
Replace USER with your ssh login name and SERVER with the server hostname or IP address
You’ll have to enter your password here one last time.
To actually use paswordless login, you must add -o IdentityFile=/data/.ssh/id_rsa from now on so that your sshfs command becomes something like:
You’ll no longer be prompted for a password when using sshfs. Perfect for automated mounting and unmounting. Note that you must do this for each server you with to set up passwordless login to.
Other usage ideas
After you setup passwordless login (as described above) you can:
- Use the GScript Lite app to add a buttons to your homescreen that mount and unmount your files
- The Tasker (paid) app becomes almost essential to maintain connectivity during network state changes. Setup Tasker tasks that execute the mount command when wifi and cellular connections go up and the unmount command when they go down. My testing shows this makes the mount bulletproof.
- Media files mounted this way will NOT be picked up automatically by an automated media scanner (media scanning over a network connection is a bad idea anyway).
- Mounting to any arbitrary directory on your device has not been fully tested and may not always work. Mounting to /data/media/0/sshfsmount as in the example above works reliably for me, as does mounting to /data/local/sshfsmount. YMMV for mounting to other directories.
- Error message reporting doesn’t work. If the sshfs command encounters any errors it will return 1 and exit silently so you’re flying blind if things aren’t working. sshfs prints its error messages to stderr which apparently android sends to /dev/null. I’ve found that -o sshfs_debug -o debug can cause crashes themselves (especially with paswordless login) so you best not use those either. Just don’t make any mistakes and everything will be fine :^)
- Connections are not maintained when the device’s IP address changes (the underlying SSH connection breaks in this case). For example when the user switches from cellular to Wi-Fi the mountpoint will become disconnected. This could potentially be solved by something like mosh: http://mosh.mit.edu/ A readily available workaround is to use the paid Tasker app to manage tne mount point as the network state changes (see above).
About
Fuse based ssh file system client for android devices
Источник
Android ssh client github
Android SSH Client to connect to an SSH Server with mpc (Linux) to play music. IDE is Android Studio. Screenshots can be found on my website..
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Name: Pi Audio Player
This is a Mini Open-Source Project and is basically intended for the rasperry-pi-developing community
You can find the repository to the code here: https://github.com/Hyper-Node/SSHMediaPlayer
Description: App which connects from Android to Raspberry Pi (or any another Linux device) to play music. Music is played with mpc (which is a command line media player for linux) on Raspberry. The connection to the Raspberry is made with SSH (Secure Shell). The Smartphone works as a controller which sends weblinks to the RaspBerry Pi, the weblinks are added to a playlist and played from the internet on the pi.
At the first start the settings pop up. It’s mandatory to give the correct ip and ssh-Port of your Raspberry Pi in the network then. Be sure to add username and password if you configured your SSH to use this.
- Adding music streams and mp3 by pasting a weblink to playlist
- SSH connection to Raspberry Pi
- Volume control with Smartphone audio buttons
- Skip to a percentage of the song with a seekbar
- Saving/reloading preferences
Requirements (on Android) Wifi Connection to Raspberry Pi (Pi is in same LAN)
Requirements (on Raspberry Pi) Raspbian or other Linux-System, (I tested against Raspbian) SSH Server active, Audio-Speakers, Internet Connection,
mpc, mpd and mp3-Codecs (Install like this): $ sudo apt-get install mpd mpc $ sudo apt-get install mpg321 lame
The App uses the jsch SSH library by JCraft(link): http://www.jcraft.com/jsch/
IDE is Android Studio
About
Android SSH Client to connect to an SSH Server with mpc (Linux) to play music. IDE is Android Studio. Screenshots can be found on my website..
Источник
Android ssh client github
How to access your android phone from anywhere using ssh
Android is linux. So theoretically you can just run everything you can on a linux box. It’s not exactly convenient to type code or commands on a phone, so being able to write it on a computer is quite useful. It’s also useful to be able to transfer files easily between a computer and the phone.
So I decided to try and install a ssh server on my phone. It had to :
- run all the time
- be always available regardless of the network
- be performant
- run as root
I tried the various available ssh application and they all have some problems : slow, full of ads, old encryption methods, .
performant ssh server that can be run as root : openssh with termux
I then found https://github.com/termux/termux-app which is really useful to run gpu tools, including sshd.
Initially sshd runs as a basic user. In order to make it run as root, https://github.com/st42/termux-sudo is useful. Using sshd -d can also provide useful debugging informations, as well as ssh -V.
That provides a good sshd server that supports ssh keys.
run all the time : init.d
The next step was to make it run all the time. To do that, I tried various methods to setup init.d but it turned out it’s different on every phone and it didn’t work on mine (nexus 6). So to bypass this issue, I used the init.d scripts support app which simulates the init.d functionnalities by running some scripts (which can be run as root) some time after boot (which is convenient : at that time the phone probably connected to the network).
So I added a script to run sshd at boot time:
The environment variables are similar to the one present in termux-sudo.
be available regardless of the network
Phones usually change of network often, which can have firewalls that block the ssh ports, and it also means the public ip of the phone changes often. That is not convenient to access the phone.
To bypass that problem, I decided to connect my phone to my server using a reverse ssh tunnel.
To do that I created a simple script tun :
- -R 19995:localhost:8022 : that means the ssh server of the phone will be available on port 19995 of your server
- -o «ExitOnForwardFailure yes» -o «ServerAliveInterval 30» -o «ServerAliveCountMax 1» : options to improve the connection robustness
- autossh -M 0 -f : autossh will keep the ssh connection open by reconnecting whenever needed
That script can then be added in your init folder.
I advise to also set ClientAliveInterval 30 and ClientAliveCountMax 1 in your server /etc/ssh/sshd_config file to close lingering connections as soon as possible.
The result is you can then connect to your server from anywhere, and then just run ssh -p 19995 localhost to connect to your phone.
Источник
raveenb / ssh_into_android.md
Connecting to an Android device over SSH
Install Android App Termux from APKPure or AppStore. If the app exists, just delete and re-install it to get the latest version, The APK can be downloaded from https://apkpure.com/termux/com.termux/ Install the APK using by running
Then locate the app and run it
Install and run SSH Server
Next, run the following commands inside the Termux using the on device keyboard to type. When the setup asks for permission, always choose default option, you can just hit/tap enter on the keyboard, dont let it modify any configs
Now, set a password for the current user by running passwd , remember this password you will need it later
Then, Start the SSH server inside by running sshd , do not close/exit the app after running the command
Connect to SSH Server
On the pc terminal run the following, dont use root@ as prefix to the ip address
When asked for password, enter the password you used in the steps above
This will drop you into a shell where you can do further installs using pkg install or run any other command you would like wget, curl you get a proper linux shell, sweet, enjoy!
Stop SSH Server
Once you are done working with the shell, stop the ssh server by running pkill sshd on the device
Host key verification error
If for some odd reason you are getting Host key verification failed error, run the following first
If it still gives you trouble edit
/.ssh/known_hosts , locate the line(s) with the ip address and delete it and then connect again
Waiting forever to connect
There are instances when the pc to android ip connection will wait a long time. If so, first check if you can ping the android’s ip address, and if its not pingable, perhaps reboot the android device. Stating the obvious here, unless the android cant be pinged you cant ssh into it.
Источник