Created
April 23, 2026 01:16
-
-
Save dakdevs/5ff4b91474629a7b241faab115cd32ab to your computer and use it in GitHub Desktop.
Setup Ubuntu for SSH access from dakdevs' Mac
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 | |
| # Setup an Ubuntu machine to be SSH-able from dakdevs' Mac. | |
| # Idempotent: safe to re-run. | |
| # | |
| # Usage (on the Ubuntu machine): | |
| # curl -fsSL <gist-raw-url> | bash | |
| set -euo pipefail | |
| PUBKEY="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEqJZkbO069wsfHTuRDMPLNe8SWozP5Gf/cpTgxT3XI1 dakdevs-mac" | |
| echo "==> Installing openssh-server" | |
| sudo apt-get update -qq | |
| sudo DEBIAN_FRONTEND=noninteractive apt-get install -y openssh-server | |
| echo "==> Enabling and starting ssh service" | |
| sudo systemctl enable --now ssh | |
| echo "==> Authorizing Mac public key for user: $USER" | |
| mkdir -p "$HOME/.ssh" | |
| chmod 700 "$HOME/.ssh" | |
| touch "$HOME/.ssh/authorized_keys" | |
| chmod 600 "$HOME/.ssh/authorized_keys" | |
| if ! grep -qxF "$PUBKEY" "$HOME/.ssh/authorized_keys"; then | |
| echo "$PUBKEY" >> "$HOME/.ssh/authorized_keys" | |
| echo " added key" | |
| else | |
| echo " key already present" | |
| fi | |
| echo "==> Opening firewall (if ufw is active)" | |
| if command -v ufw >/dev/null 2>&1 && sudo ufw status | grep -q "Status: active"; then | |
| sudo ufw allow OpenSSH | |
| else | |
| echo " ufw not active — skipping" | |
| fi | |
| IP="$(hostname -I 2>/dev/null | awk '{print $1}')" | |
| HOSTNAME="$(hostname)" | |
| echo "" | |
| echo "Done. Connect from Mac with:" | |
| echo " ssh ${USER}@${IP}" | |
| echo "or:" | |
| echo " ssh ${USER}@${HOSTNAME}.local" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment