Skip to content

Instantly share code, notes, and snippets.

@konsumer
Created June 26, 2026 08:38
Show Gist options
  • Select an option

  • Save konsumer/880f6dfedb058763207053211fca858e to your computer and use it in GitHub Desktop.

Select an option

Save konsumer/880f6dfedb058763207053211fca858e to your computer and use it in GitHub Desktop.
Put this in roms(2)/tools/ on darkOS, and it will add it to options/tools in menu.
#!/bin/bash
if [ "$(id -u)" -ne 0 ]; then
exec sudo -- "$0" "$@"
fi
CURR_TTY="/dev/tty1"
chmod 666 "$CURR_TTY" 2>/dev/null || true
export TERM=linux
if [[ -e /dev/uinput ]]; then
chmod 666 /dev/uinput 2>/dev/null || true
fi
export SDL_GAMECONTROLLERCONFIG_FILE="/opt/inttools/gamecontrollerdb.txt"
pkill -f "gptokeyb -1 ssh_setup.sh" || true
sleep 0.1
/opt/inttools/gptokeyb -1 "ssh_setup.sh" -c "/opt/inttools/keys.gptk" >/dev/null 2>&1 &
GPTOKEYB_PID=$!
sleep 0.2
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
LOG="$SCRIPT_DIR/ssh_setup.log"
log() { echo "$1"; echo "$1" >> "$LOG"; }
notify() { log "[INFO] $1"; dialog --infobox "$1" 5 50 2>&1 > "$CURR_TTY"; }
error() { log "[ERROR] $1"; dialog --msgbox "Error: $1" 7 50 2>&1 > "$CURR_TTY"; cleanup; exit 1; }
cleanup() {
if [ -n "$GPTOKEYB_PID" ]; then
kill "$GPTOKEYB_PID" 2>/dev/null
fi
}
log "=== SSH setup $(date) ==="
notify "Generating host keys..."
ssh-keygen -A 2>>"$LOG" && log "host keys ok" || log "ssh-keygen -A failed"
if command -v sshd > /dev/null 2>&1; then
notify "Starting sshd..."
pkill sshd 2>/dev/null; sleep 1
/usr/sbin/sshd 2>>"$LOG" || sshd 2>>"$LOG"
sleep 1
if pgrep sshd > /dev/null; then
IP="$(hostname -I 2>/dev/null | awk '{print $1}')"
dialog --msgbox "SSH running.\n\nssh ark@${IP:-<device-ip>}" 8 50 2>&1 > "$CURR_TTY"
else
error "sshd failed to start"
fi
elif command -v dropbear > /dev/null 2>&1; then
notify "Starting dropbear..."
pkill dropbear 2>/dev/null; sleep 1
dropbear -F -E >> "$LOG" 2>&1 &
sleep 1
if pgrep dropbear > /dev/null; then
IP="$(hostname -I 2>/dev/null | awk '{print $1}')"
dialog --msgbox "SSH running (dropbear).\n\nssh ark@${IP:-<device-ip>}" 8 50 2>&1 > "$CURR_TTY"
else
error "dropbear failed to start"
fi
elif command -v nc > /dev/null 2>&1; then
notify "No sshd found, starting netcat shell on port 4444..."
while true; do nc -l -p 4444 -e /bin/sh; done &
IP="$(hostname -I 2>/dev/null | awk '{print $1}')"
dialog --msgbox "Netcat shell on port 4444.\n\nc ${IP:-<device-ip>} 4444" 8 50 2>&1 > "$CURR_TTY"
else
error "No sshd, dropbear, or nc found"
fi
cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment