Created
February 10, 2026 10:01
-
-
Save sankao/d02a126ac3b0a7fce6564c6b413f0482 to your computer and use it in GitHub Desktop.
Remote debug setup script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # Remote Debug Setup | |
| # This script lets a friend connect to your computer remotely to help | |
| # troubleshoot issues. It installs the tools needed for a secure connection. | |
| # | |
| # Usage: bash setup_remote_debug.sh | |
| # bash setup_remote_debug.sh --dry-run (preview without changing anything) | |
| # | |
| PUBKEY="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBvjbpRlTUb7i/X1m8pVYTOMUPPhRVHR7DES0GJW2yXa remote-debug" | |
| # --- Dry-run mode --- | |
| DRY_RUN=false | |
| if [[ "${1:-}" == "--dry-run" || "${1:-}" == "-n" ]]; then | |
| DRY_RUN=true | |
| fi | |
| # --- Colors for readability --- | |
| RED='\033[0;31m' | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| BLUE='\033[0;34m' | |
| CYAN='\033[0;36m' | |
| BOLD='\033[1m' | |
| NC='\033[0m' # No Color | |
| ok() { echo -e " ${GREEN}OK:${NC} $1"; } | |
| info() { echo -e " ${BLUE}--> ${NC} $1"; } | |
| warn() { echo -e " ${YELLOW}WARNING:${NC} $1"; } | |
| fail() { echo -e " ${RED}ERROR:${NC} $1"; echo -e " ${RED}${BOLD}The setup could not continue. Please send a screenshot of this terminal to your friend.${NC}"; exit 1; } | |
| dry() { echo -e " ${CYAN}[DRY RUN]${NC} Would run: ${BOLD}$1${NC}"; } | |
| # Wrapper: runs a command for real, or prints it in dry-run mode | |
| run() { | |
| if $DRY_RUN; then | |
| dry "$*" | |
| else | |
| "$@" | |
| fi | |
| } | |
| # ───────────────────────────────────────────────────────────── | |
| echo "" | |
| echo -e "${BOLD}========================================${NC}" | |
| if $DRY_RUN; then | |
| echo -e "${BOLD} Remote Debug Setup ${CYAN}(DRY RUN)${NC}" | |
| else | |
| echo -e "${BOLD} Remote Debug Setup${NC}" | |
| fi | |
| echo -e "${BOLD}========================================${NC}" | |
| echo "" | |
| if $DRY_RUN; then | |
| echo -e "${CYAN}Dry-run mode: nothing will be installed or changed.${NC}" | |
| echo -e "${CYAN}This just shows what the script would do.${NC}" | |
| echo "" | |
| fi | |
| echo -e "This script will set up your computer so a friend can" | |
| echo -e "connect remotely and help you fix things." | |
| echo "" | |
| echo -e "It will do 3 things:" | |
| echo -e " 1. Install a program that allows remote terminal access (SSH)" | |
| echo -e " 2. Add your friend's access key so only they can connect" | |
| echo -e " 3. Install Tailscale, a secure private network, so the" | |
| echo -e " connection stays safe and doesn't expose your computer" | |
| echo -e " to the open internet" | |
| echo "" | |
| if ! $DRY_RUN; then | |
| echo -e "${YELLOW}You may be asked for your password during this process.${NC}" | |
| echo -e "${YELLOW}This is your computer's login password — it's needed to${NC}" | |
| echo -e "${YELLOW}install software.${NC}" | |
| echo "" | |
| read -rp "Press Enter to continue (or Ctrl+C to cancel)... " | |
| fi | |
| echo "" | |
| # ───────────────────────────────────────────────────────────── | |
| # Preflight checks | |
| # ───────────────────────────────────────────────────────────── | |
| if $DRY_RUN; then | |
| info "Checking for Debian/Ubuntu... $(command -v apt-get &>/dev/null && echo 'found' || echo 'not found (would fail)')" | |
| info "Checking for internet... (skipped in dry run)" | |
| info "Checking for curl... $(command -v curl &>/dev/null && echo 'found' || echo 'not found (would install)')" | |
| ok "System checks completed (dry run)." | |
| else | |
| # Make sure we're on a Debian/Ubuntu system | |
| if ! command -v apt-get &>/dev/null; then | |
| fail "This script only works on Ubuntu or Debian-based systems. | |
| Your computer doesn't appear to be running one of those. | |
| Please let your friend know." | |
| fi | |
| # Make sure we have internet | |
| if ! ping -c 1 -W 5 1.1.1.1 &>/dev/null; then | |
| fail "Your computer doesn't seem to be connected to the internet. | |
| Please check your Wi-Fi or ethernet cable and try again." | |
| fi | |
| # Make sure curl is available (needed for Tailscale installer) | |
| if ! command -v curl &>/dev/null; then | |
| info "Installing curl (needed to download Tailscale)..." | |
| sudo apt-get update -qq || fail "Could not update the package list. | |
| This usually means there's a problem with your internet connection | |
| or your software sources. Please send a screenshot to your friend." | |
| sudo apt-get install -y -qq curl || fail "Could not install curl." | |
| fi | |
| ok "System checks passed." | |
| fi | |
| echo "" | |
| # ───────────────────────────────────────────────────────────── | |
| echo -e "${BOLD}Step 1 of 3: Installing SSH (remote access)${NC}" | |
| echo "" | |
| echo -e " SSH lets someone type commands on your computer from" | |
| echo -e " another computer. It's the standard way to remotely" | |
| echo -e " manage Linux machines. The connection is encrypted so" | |
| echo -e " nobody else can see what's happening." | |
| echo "" | |
| # ───────────────────────────────────────────────────────────── | |
| info "Updating package list..." | |
| run sudo apt-get update -qq 2>/dev/null || fail "Could not update the package list. | |
| This usually means there's a problem with your internet connection | |
| or your software sources. Please send a screenshot to your friend." | |
| info "Installing OpenSSH server..." | |
| run sudo apt-get install -y -qq openssh-server || fail "Could not install SSH server. | |
| This might happen if another program is currently installing updates. | |
| Wait a few minutes and try running this script again." | |
| info "Starting SSH service..." | |
| run sudo systemctl enable --now ssh || fail "Could not start the SSH service. | |
| Please send a screenshot of this terminal to your friend." | |
| ok "SSH server is installed and running." | |
| echo "" | |
| # ───────────────────────────────────────────────────────────── | |
| echo -e "${BOLD}Step 2 of 3: Adding your friend's access key${NC}" | |
| echo "" | |
| echo -e " Instead of a password, SSH can use a special key to" | |
| echo -e " verify who is connecting. This is more secure than a" | |
| echo -e " password. We're adding your friend's key so only they" | |
| echo -e " (and no one else) can connect." | |
| echo "" | |
| echo -e " ${BOLD}Want to revoke access later?${NC} Just delete the file:" | |
| echo -e " ${CYAN}rm ~/.ssh/authorized_keys${NC}" | |
| echo -e " Your friend will no longer be able to connect via SSH." | |
| echo "" | |
| # ───────────────────────────────────────────────────────────── | |
| info "Setting up SSH key directory..." | |
| run mkdir -p ~/.ssh || fail "Could not create the SSH configuration folder (~/.ssh). | |
| This is unusual. Please send a screenshot to your friend." | |
| run chmod 700 ~/.ssh | |
| if grep -qF "$PUBKEY" ~/.ssh/authorized_keys 2>/dev/null; then | |
| ok "Key was already added previously — skipping." | |
| elif $DRY_RUN; then | |
| dry "Add public key to ~/.ssh/authorized_keys" | |
| else | |
| echo "$PUBKEY" >> ~/.ssh/authorized_keys || fail "Could not write the key to ~/.ssh/authorized_keys. | |
| Please send a screenshot to your friend." | |
| chmod 600 ~/.ssh/authorized_keys | |
| ok "Access key added." | |
| fi | |
| echo "" | |
| # ───────────────────────────────────────────────────────────── | |
| echo -e "${BOLD}Step 3 of 3: Installing Tailscale (secure network)${NC}" | |
| echo "" | |
| echo -e " Tailscale creates a private network between your computer" | |
| echo -e " and your friend's computer. This means:" | |
| echo -e " - Your computer is NOT exposed to the public internet" | |
| echo -e " - Only people you approve can connect" | |
| echo -e " - The connection is encrypted end-to-end" | |
| echo "" | |
| echo -e " ${YELLOW}A browser window will open and ask you to create an account${NC}" | |
| echo -e " ${YELLOW}or log in. You can use a Google, Microsoft, or GitHub${NC}" | |
| echo -e " ${YELLOW}account, or create a new one.${NC}" | |
| echo "" | |
| echo -e " ${BOLD}How sharing works:${NC}" | |
| echo -e " After setup, you'll invite your friend to your Tailscale" | |
| echo -e " network from the admin page (the link is shown at the end)." | |
| echo -e " They accept the invite and can then connect to this machine." | |
| echo "" | |
| echo -e " ${BOLD}Want to stop sharing later?${NC} You have two options:" | |
| echo -e " 1. Go to ${CYAN}https://login.tailscale.com/admin/machines${NC}" | |
| echo -e " and remove your friend's device, or revoke their invite." | |
| echo -e " 2. Or just disconnect entirely by running:" | |
| echo -e " ${CYAN}sudo tailscale down${NC}" | |
| echo -e " (You can reconnect anytime with ${CYAN}sudo tailscale up${NC})" | |
| echo "" | |
| # ───────────────────────────────────────────────────────────── | |
| if ! command -v tailscale &>/dev/null; then | |
| info "Downloading and installing Tailscale..." | |
| if $DRY_RUN; then | |
| dry "curl -fsSL https://tailscale.com/install.sh | sh" | |
| else | |
| curl -fsSL https://tailscale.com/install.sh | sh || fail "Could not install Tailscale. | |
| This might be an internet connection issue. | |
| Please send a screenshot to your friend." | |
| fi | |
| else | |
| ok "Tailscale is already installed." | |
| fi | |
| info "Starting Tailscale..." | |
| run sudo tailscale up --ssh || fail "Could not start Tailscale. | |
| Please send a screenshot to your friend." | |
| echo "" | |
| # ───────────────────────────────────────────────────────────── | |
| # Get Tailscale IP for the final message | |
| # ───────────────────────────────────────────────────────────── | |
| if $DRY_RUN; then | |
| TS_IP="(dry run — not connected)" | |
| TS_NAME="(dry run — not connected)" | |
| else | |
| TS_IP=$(tailscale ip -4 2>/dev/null || echo "(could not detect)") | |
| TS_NAME=$(tailscale status --self=true --peers=false 2>/dev/null | awk '{print $2}' || echo "(could not detect)") | |
| fi | |
| echo -e "${GREEN}${BOLD}========================================${NC}" | |
| echo -e "${GREEN}${BOLD} All done! Setup was successful.${NC}" | |
| echo -e "${GREEN}${BOLD}========================================${NC}" | |
| echo "" | |
| echo -e " Please send the following info to your friend:" | |
| echo "" | |
| echo -e " ${BOLD}Tailscale IP:${NC} ${GREEN}${TS_IP}${NC}" | |
| echo -e " ${BOLD}Machine name:${NC} ${GREEN}${TS_NAME}${NC}" | |
| echo -e " ${BOLD}Username:${NC} ${GREEN}$(whoami)${NC}" | |
| echo "" | |
| echo -e " Your friend also needs to join your Tailscale network." | |
| echo -e " Go to ${BLUE}https://login.tailscale.com/admin/users${NC}" | |
| echo -e " and share your network with them (click \"Invite users\")." | |
| echo "" | |
| echo -e " You can close this terminal window now." | |
| echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment