Skip to content

Instantly share code, notes, and snippets.

@rubenhorn
Last active November 22, 2023 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubenhorn/48efb299166bd73efdbc0826e2ccc92b to your computer and use it in GitHub Desktop.
Save rubenhorn/48efb299166bd73efdbc0826e2ccc92b to your computer and use it in GitHub Desktop.
Termux Server

Initial setup

(See also the Termux Wiki)

# Install AutoSSH, OpenSSH and FTP server and tmux
pkg upgrade
pkg install autossh openssh openssh-sftp-server tmux
# Set password for initial connection
passwd
# Find local IP address of device
ifconfig | grep -o 192[0-9\.]*
# (Re-)start SSH server
pkill sshd; sshd

Set up public key authentication

# Set IP address of device as environment variable
# SERVER=...
# Create public key (optional)
# ssh-keygen -t rsa -b 2048
# Copy public key to device
ssh-copy-id -p8022 -i ~/.ssh/id_rsa user@$SERVER
# Switch to public key authentication
ssh user@$SERVER -p8022 'c=$PREFIX/etc/ssh/sshd_config;sed -rie "s/^(PasswordAuthentication)\s.*/\1 no/g" $c;pkill sshd;sshd'
# Connect to the device using public key
ssh user@$SERVER -p8022

Set up web server

# Create/attach to tmux session
tmux new-session -A -s webserver
# Create a simple website
mkdir -p www && nano www/index.html
# Install python
pkg install python3
# Start local webserver (preview with xdg-open http://$SERVER:8080; to foreground using fg)
$(cd www && python3 -m http.server 8080) &
# Create public key for the server (optional)
# ssh-keygen -t rsa -b 2048
# Set requested subdomain (optional)
# SUBDOMAIN=...
# Create public tunnel to website (alternatively use localhost.run)
autossh -M 0 -R $SUBDOMAIN:80:localhost:8080 serveo.net
# Detach from tmux session using Ctrl+b d

TODO: Nextcloud

Optional:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment