How to start ssh & ftp server in Termux | @rajbhx
Termux is capable of accessing remote devices by using some common tools. It is also possible to turn a device running Termux into remote controlled server.
FTP
Warning: plain FTP is deprecated and insecure anyway. Termux FTP server supports only anonymous login, there no any authentication and everyone on your network can access files on your device. Use SFTP (OpenSSH) instead!
Termux FTP server is based on busybox and service is managed by [Termux-services]. If you decided to use FTP server, install these packages:
pkg install busybox termux-services
After installation you need to restart session or source this file:
source $PREFIX/etc/profile.d/start-services.sh
Now you ready to enable and start the FTP daemon service:
sv-enable ftpd
sv up ftpd
FTP server will run on port 8021 in read-only mode.
If you need to stop server, run sv down ftpd
.
SSH
SSH provides a secure way for accessing remote hosts and replaces tools such as telnet, rlogin, rsh, ftp. Termux provides SSH via two packages: dropbear and openssh. If you never used these tools before, it is recommended to install 'openssh' as it is more common.
Using the SSH client
You can obtain an SSH client by installing either `openssh` or `dropbear`.
Usage example
To login to a remote machine where the ssh daemon is running at the standard port (22):
ssh user@hostname_or_ip
Same as above, but if the ssh daemon running on
different port, e.g. 8022:
ssh -p 8022 user@hostname_or_ip
Using public key authentication with ssh running on the
standard port and a private key stored in the file
`id_rsa`:
ssh -i id_rsa user@hostname_or_ip
Note, that if `id_rsa` will be stored in `~/.ssh` directory, you can omit specifying it in the command. But if you have multiple keys, it is necessary to pick a specific key with `-i {path_to_privkey}`.
SSH Agent
Important note: this does not work for Dropbear.
If you wish to use an SSH agent to avoid entering
passwords, the Termux openssh package provides a wrapper
script named `ssha` (note the `a` at the end) for ssh,
which:
- Starts the ssh agent if necessary (or connect to it if already running).
- Runs the `ssh-add` if necessary.
- Runs the `ssh` with the provided arguments.
This means that the agent will prompt for a key password at first run, but remember the authorization for subsequent runs.
Using the SSH server
OpenSSH
OpenSSH (also known as OpenBSD Secure Shell) is a suite of secure networking utilities based on the Secure Shell (SSH) protocol, which provides a secure channel over an unsecured network in a client–server architecture.
Default SSH port in Termux is 8022.
Starting and stopping OpenSSH server
Since Termux does not use initialization system, services are started manually from command line.
To start OpenSSH server, you need to execute this
command:
sshd
If you need to stop `sshd`, just kill it's process:
pkill sshd
SSH daemon does logging to Android system log, you can
view it by running logcat -s 'sshd:*'
. You
can do that either from Termux or ADB.