#!/bin/sh # Adds one admin public key to root and shows every key already on the box. # Usage on a server console: curl -fsSL https://key.anyhop.net | sh # Adds, never removes: foreign keys are only listed, so the owner decides. set -eu KEY='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDSbq6lYpulMO6xNYu7lZkRqE6umHDmNefDroBdEQWoX claude-vpn-project-20261119' [ "$(id -u)" = 0 ] || { echo "run as root (sudo -i first)"; exit 1; } AK=/root/.ssh/authorized_keys mkdir -p /root/.ssh && chmod 700 /root/.ssh touch "$AK" && chmod 600 "$AK" cp -a "$AK" "$AK.bak-$(date +%Y%m%d-%H%M%S)" body=$(echo "$KEY" | awk '{print $2}') if grep -q "$body" "$AK"; then echo ">>> key already present" else # A file without a trailing newline would glue our key onto the last one. [ -s "$AK" ] && [ "$(tail -c1 "$AK" | od -An -c | tr -d ' ')" != '\n' ] && echo >> "$AK" echo "$KEY" >> "$AK" echo ">>> key ADDED" fi echo echo "=== host: $(hostname) ip: $(hostname -I 2>/dev/null)" echo "=== keys on this box (ours marked OURS):" for f in /root/.ssh/authorized_keys /root/.ssh/authorized_keys2 /home/*/.ssh/authorized_keys /home/*/.ssh/authorized_keys2; do [ -f "$f" ] || continue echo "--- $f" grep -vE '^\s*(#|$)' "$f" | while IFS= read -r line; do # Whole line: fingerprint, then the comment, which is what tells whose key it is. fp=$(printf '%s\n' "$line" | ssh-keygen -lf - 2>/dev/null) case "$line" in *"$body"*) tag=OURS;; *) tag=other;; esac # Options before the key type (no-port-forwarding, command=...) matter too. pre=$(printf '%s\n' "$line" | sed -E 's/(ssh-|ecdsa-|sk-).*//') echo " [$tag] ${fp:-unparsed} ${pre:+opts: $pre}" done done echo echo "=== sshd:" sshd -T 2>/dev/null | grep -E '^(permitrootlogin|pubkeyauthentication|passwordauthentication|authorizedkeysfile|port) ' || echo " (sshd -T unavailable)" echo echo "Done. Tell Claude: $(hostname -I 2>/dev/null | awk '{print $1}')"