Skip to content

Instantly share code, notes, and snippets.

@CypherpunkSamurai
Last active April 10, 2025 06:58
Show Gist options
  • Save CypherpunkSamurai/11153be4025dc463e72cd42870d16419 to your computer and use it in GitHub Desktop.
Save CypherpunkSamurai/11153be4025dc463e72cd42870d16419 to your computer and use it in GitHub Desktop.
Termux Easy SSH Server with SFTP
#!/data/data/com.termux/files/usr/bin/bash
# Update package list
pkg update -y
# Install OpenSSH, SFTP server, net-tools, and termux-tools
pkg install -y openssh openssh-sftp-server net-tools termux-tools
# Configure SSH server
cat > $PREFIX/etc/ssh/sshd_config << 'EOL'
Port 8022
ListenAddress 0.0.0.0
ListenAddress ::
AllowTcpForwarding yes
PermitTunnel yes
PrintMotd yes
PasswordAuthentication yes
Subsystem sftp /data/data/com.termux/files/usr/libexec/sftp-server
EOL
# Create the ssh directory if it doesn't exist
mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
# Set password for current user
echo "Setting password for current user..."
{ echo "termux"; echo "termux"; } | passwd
# Create a welcome message
cat > $PREFIX/etc/motd << EOL
Welcome to Termux SSH Server!
This server has been configured for remote access and tunneling.
Current setup date: 2025-04-10 06:56:24
EOL
# Create boot script directory and file
mkdir -p ~/.termux/boot
cat > ~/.termux/boot/start-sshd << 'EOL'
#!/data/data/com.termux/files/usr/bin/bash
termux-wake-lock
sshd
sftp -P 8022 0.0.0.0
EOL
chmod +x ~/.termux/boot/start-sshd
# Setup storage access
termux-setup-storage
# Restart the SSH server
pkill sshd 2>/dev/null || true
sshd
# Display IP addresses using ifconfig
echo "Your device IP addresses:"
ifconfig | grep -E "inet ([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v "127.0.0.1" | awk '{print $2}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment