Last active
March 7, 2026 00:29
-
-
Save Macmee/2bf2b7586c6b8c771a84b75b9679d79a to your computer and use it in GitHub Desktop.
Onboard non-dev teammates to git + GitHub SSH so they can use Claude Code
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
| #!/bin/bash | |
| # ╔═══════════════════════════════════════════════════════════════════════════╗ | |
| # | |
| # ██████╗ ██╗████████╗ ███████╗███████╗████████╗██╗ ██╗██████╗ | |
| # ██╔════╝ ██║╚══██╔══╝ ██╔════╝██╔════╝╚══██╔══╝██║ ██║██╔══██╗ | |
| # ██║ ███╗██║ ██║ ███████╗█████╗ ██║ ██║ ██║██████╔╝ | |
| # ██║ ██║██║ ██║ ╚════██║██╔══╝ ██║ ██║ ██║██╔═══╝ | |
| # ╚██████╔╝██║ ██║ ███████║███████╗ ██║ ╚██████╔╝██║ | |
| # ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝ | |
| # | |
| # WHY DOES THIS EXIST? | |
| # I wanted to get some non-engineering teammates (designers, etc.) set | |
| # up with Claude Code, which requires git + GitHub SSH access. Rather | |
| # than walking each person through it manually, I made this script to | |
| # automate the whole onboarding process. Just curl | bash and go. | |
| # | |
| # WHAT IT DOES: | |
| # 1. Installs developer tools (Xcode CLT on Mac, git on Linux) | |
| # 2. Configures git identity (name + email) | |
| # 3. Generates an SSH key | |
| # 4. Installs the GitHub CLI | |
| # 5. Logs in to GitHub and adds the SSH key automatically | |
| # 6. Verifies the connection works | |
| # | |
| # ╚═══════════════════════════════════════════════════════════════════════════╝ | |
| set -e | |
| # --- Detect OS --------------------------------------------------------------- | |
| OS="$(uname -s)" | |
| case "$OS" in | |
| Darwin) IS_MAC=true; IS_LINUX=false ;; | |
| Linux) IS_MAC=false; IS_LINUX=true ;; | |
| *) | |
| echo "Unsupported OS: $OS" | |
| exit 1 | |
| ;; | |
| esac | |
| # --- Colors ------------------------------------------------------------------ | |
| BOLD='\033[1m' | |
| DIM='\033[2m' | |
| ITALIC='\033[3m' | |
| UNDERLINE='\033[4m' | |
| RED='\033[31m' | |
| GREEN='\033[32m' | |
| YELLOW='\033[33m' | |
| BLUE='\033[34m' | |
| CYAN='\033[36m' | |
| WHITE='\033[97m' | |
| BRIGHT_BLUE='\033[94m' | |
| BRIGHT_CYAN='\033[96m' | |
| BRIGHT_GREEN='\033[92m' | |
| RESET='\033[0m' | |
| echo "" | |
| echo -e "${BOLD}${BRIGHT_CYAN}🖥️ Git + GitHub Setup${RESET}" | |
| echo -e "${DIM}======================${RESET}" | |
| echo "" | |
| # --- 1. Developer Tools (git, ssh-keygen, etc.) ----------------------------- | |
| echo -e "${BOLD}${CYAN}📦 Step 1: Developer Tools${RESET}" | |
| echo "" | |
| if $IS_MAC; then | |
| if ! xcode-select -p &>/dev/null; then | |
| echo -e " Installing Xcode Command Line Tools ${DIM}(this gives you git)${RESET}..." | |
| echo -e " ${YELLOW}A popup will appear — click 'Install' and wait for it to finish.${RESET}" | |
| echo "" | |
| xcode-select --install 2>/dev/null || true | |
| echo "" | |
| echo -e " ${YELLOW}⏳ Press Enter here once the installer finishes${RESET}" | |
| read -r </dev/tty | |
| if ! xcode-select -p &>/dev/null; then | |
| echo -e " ${RED}❌ Xcode Command Line Tools don't seem to be installed yet.${RESET}" | |
| echo -e " ${RED} Please finish the installation and re-run this script.${RESET}" | |
| exit 1 | |
| fi | |
| echo -e " ${GREEN}✅ Xcode Command Line Tools installed!${RESET}" | |
| else | |
| echo -e " ${GREEN}✅ Xcode Command Line Tools already installed${RESET}" | |
| fi | |
| else | |
| # Linux — ensure git and ssh are available | |
| if command -v git &>/dev/null && command -v ssh-keygen &>/dev/null; then | |
| echo -e " ${GREEN}✅ git and ssh already installed${RESET}" | |
| else | |
| echo -e " Installing git and ssh..." | |
| if command -v apt-get &>/dev/null; then | |
| sudo apt-get update -qq && sudo apt-get install -y -qq git openssh-client | |
| elif command -v dnf &>/dev/null; then | |
| sudo dnf install -y -q git openssh-clients | |
| elif command -v yum &>/dev/null; then | |
| sudo yum install -y -q git openssh-clients | |
| else | |
| echo -e " ${RED}❌ Could not detect package manager. Please install git and openssh manually.${RESET}" | |
| exit 1 | |
| fi | |
| echo -e " ${GREEN}✅ git and ssh installed!${RESET}" | |
| fi | |
| fi | |
| echo "" | |
| # --- 2. Git identity --------------------------------------------------------- | |
| echo -e "${BOLD}${CYAN}👤 Step 2: Git Identity${RESET}" | |
| echo "" | |
| current_name=$(git config --global user.name 2>/dev/null || true) | |
| current_email=$(git config --global user.email 2>/dev/null || true) | |
| if [ -n "$current_name" ] && [ -n "$current_email" ]; then | |
| echo -e " You already have git configured as:" | |
| echo -e " Name: ${BOLD}${WHITE}$current_name${RESET}" | |
| echo -e " Email: ${BOLD}${WHITE}$current_email${RESET}" | |
| echo "" | |
| echo -en " ${YELLOW}Keep these? (Y/n) ${RESET}" | |
| read -r keep </dev/tty | |
| if [[ "$keep" =~ ^[Nn] ]]; then | |
| current_name="" | |
| current_email="" | |
| fi | |
| fi | |
| if [ -z "$current_name" ]; then | |
| echo -en " ${YELLOW}Your full name: ${RESET}" | |
| read -r current_name </dev/tty | |
| git config --global user.name "$current_name" | |
| fi | |
| if [ -z "$current_email" ]; then | |
| echo -en " ${YELLOW}Your work email: ${RESET}" | |
| read -r current_email </dev/tty | |
| git config --global user.email "$current_email" | |
| fi | |
| echo "" | |
| echo -e " ${GREEN}✅ Git configured as: ${BOLD}$current_name${RESET} ${GREEN}<${BOLD}$current_email${RESET}${GREEN}>${RESET}" | |
| echo "" | |
| # --- 3. SSH key -------------------------------------------------------------- | |
| echo -e "${BOLD}${CYAN}🔐 Step 3: SSH Key${RESET}" | |
| echo "" | |
| SSH_KEY="$HOME/.ssh/id_ed25519" | |
| if [ -f "$SSH_KEY" ]; then | |
| echo -e " ${GREEN}✅ SSH key already exists${RESET}" | |
| else | |
| echo -e " Generating SSH key..." | |
| mkdir -p "$HOME/.ssh" | |
| ssh-keygen -t ed25519 -C "$current_email" -f "$SSH_KEY" -N "" | |
| echo -e " ${GREEN}✅ SSH key created!${RESET}" | |
| fi | |
| echo "" | |
| # Pre-add GitHub's SSH host keys so the first connection doesn't prompt | |
| KNOWN_HOSTS="$HOME/.ssh/known_hosts" | |
| mkdir -p "$HOME/.ssh" | |
| if ! grep -q "github.com" "$KNOWN_HOSTS" 2>/dev/null; then | |
| ssh-keyscan -t ed25519,rsa github.com >> "$KNOWN_HOSTS" 2>/dev/null | |
| fi | |
| # Start ssh-agent and add key | |
| eval "$(ssh-agent -s)" >/dev/null 2>&1 | |
| # Ensure ssh config exists with AddKeysToAgent | |
| SSH_CONFIG="$HOME/.ssh/config" | |
| if ! grep -q "AddKeysToAgent yes" "$SSH_CONFIG" 2>/dev/null; then | |
| mkdir -p "$HOME/.ssh" | |
| if $IS_MAC; then | |
| cat >> "$SSH_CONFIG" <<'SSHCONF' | |
| Host github.com | |
| AddKeysToAgent yes | |
| UseKeychain yes | |
| IdentityFile ~/.ssh/id_ed25519 | |
| SSHCONF | |
| else | |
| cat >> "$SSH_CONFIG" <<'SSHCONF' | |
| Host github.com | |
| AddKeysToAgent yes | |
| IdentityFile ~/.ssh/id_ed25519 | |
| SSHCONF | |
| fi | |
| echo -e " ${GREEN}✅ SSH config updated${RESET}" | |
| fi | |
| if $IS_MAC; then | |
| ssh-add --apple-use-keychain "$SSH_KEY" 2>/dev/null || ssh-add "$SSH_KEY" 2>/dev/null || true | |
| else | |
| ssh-add "$SSH_KEY" 2>/dev/null || true | |
| fi | |
| # --- 4. GitHub CLI ----------------------------------------------------------- | |
| echo "" | |
| echo -e "${BOLD}${CYAN}⬇️ Step 4: GitHub CLI${RESET}" | |
| echo "" | |
| GH_INSTALLED=false | |
| if command -v gh &>/dev/null; then | |
| echo -e " ${GREEN}✅ GitHub CLI already installed${RESET}" | |
| GH_INSTALLED=true | |
| else | |
| echo -e " Installing GitHub CLI ${DIM}(this lets us link your key automatically)${RESET}..." | |
| echo "" | |
| if $IS_MAC; then | |
| # macOS — try Homebrew first, then direct download (no sudo needed) | |
| if command -v brew &>/dev/null; then | |
| echo -e " ${DIM}Installing gh via Homebrew...${RESET}" | |
| brew install gh 2>/dev/null | |
| if command -v gh &>/dev/null; then | |
| echo -e " ${GREEN}✅ GitHub CLI installed!${RESET}" | |
| GH_INSTALLED=true | |
| fi | |
| fi | |
| # Fallback: download gh binary directly (works without admin/sudo) | |
| if [ "$GH_INSTALLED" = false ]; then | |
| echo -e " ${DIM}Downloading GitHub CLI directly...${RESET}" | |
| GH_VERSION=$(curl -sL https://api.github.com/repos/cli/cli/releases/latest | grep '"tag_name"' | head -1 | sed 's/.*"v\(.*\)".*/\1/') | |
| if [ -n "$GH_VERSION" ]; then | |
| GH_ARCH="$(uname -m)" | |
| case "$GH_ARCH" in | |
| arm64|aarch64) GH_ARCH="arm64" ;; | |
| x86_64) GH_ARCH="amd64" ;; | |
| esac | |
| GH_URL="https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_macOS_${GH_ARCH}.zip" | |
| GH_TMP="$(mktemp -d)" | |
| if curl -sL "$GH_URL" -o "$GH_TMP/gh.zip" && unzip -q "$GH_TMP/gh.zip" -d "$GH_TMP"; then | |
| mkdir -p "$HOME/.local/bin" | |
| cp "$GH_TMP"/gh_*/bin/gh "$HOME/.local/bin/gh" | |
| chmod +x "$HOME/.local/bin/gh" | |
| export PATH="$HOME/.local/bin:$PATH" | |
| # Add ~/.local/bin to PATH permanently in shell profile | |
| SHELL_RC="$HOME/.zshrc" | |
| if [ -n "$BASH_VERSION" ] || [ "$(basename "$SHELL")" = "bash" ]; then | |
| SHELL_RC="$HOME/.bashrc" | |
| fi | |
| if ! grep -q '\.local/bin' "$SHELL_RC" 2>/dev/null; then | |
| echo '' >> "$SHELL_RC" | |
| echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$SHELL_RC" | |
| fi | |
| if command -v gh &>/dev/null; then | |
| echo -e " ${GREEN}✅ GitHub CLI installed!${RESET}" | |
| GH_INSTALLED=true | |
| fi | |
| fi | |
| rm -rf "$GH_TMP" | |
| fi | |
| fi | |
| else | |
| # Linux — install via official GitHub apt/dnf repo | |
| if command -v apt-get &>/dev/null; then | |
| echo -e " ${DIM}Adding GitHub CLI repository...${RESET}" | |
| (type -p wget >/dev/null || sudo apt-get install -y -qq wget) \ | |
| && sudo mkdir -p -m 755 /etc/apt/keyrings \ | |
| && out=$(mktemp) \ | |
| && wget -qO "$out" https://cli.github.com/packages/githubcli-archive-keyring.gpg \ | |
| && cat "$out" | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \ | |
| && sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \ | |
| && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ | |
| && sudo apt-get update -qq \ | |
| && sudo apt-get install -y -qq gh | |
| rm -f "$out" | |
| elif command -v dnf &>/dev/null; then | |
| sudo dnf install -y -q 'dnf-command(config-manager)' 2>/dev/null || true | |
| sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo | |
| sudo dnf install -y -q gh | |
| elif command -v yum &>/dev/null; then | |
| sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo | |
| sudo yum install -y -q gh | |
| fi | |
| if command -v gh &>/dev/null; then | |
| echo -e " ${GREEN}✅ GitHub CLI installed!${RESET}" | |
| GH_INSTALLED=true | |
| fi | |
| fi | |
| if [ "$GH_INSTALLED" = false ]; then | |
| echo -e " ${YELLOW}⚠️ Could not install GitHub CLI — no worries, we'll do it manually${RESET}" | |
| fi | |
| fi | |
| # --- 5. Add SSH key to GitHub ------------------------------------------------ | |
| echo "" | |
| echo -e "${BOLD}${CYAN}🔗 Step 5: Connect to GitHub${RESET}" | |
| echo "" | |
| COMPUTER_NAME="$(scutil --get ComputerName 2>/dev/null || hostname)" | |
| if [ "$GH_INSTALLED" = true ]; then | |
| if ! gh auth status &>/dev/null 2>&1; then | |
| echo -e " ${YELLOW}Your browser will open to log in to GitHub.${RESET}" | |
| echo -e " ${YELLOW}If you don't have an account yet, create one there first!${RESET}" | |
| echo "" | |
| gh auth login -h github.com -p ssh -w --skip-ssh-key -s admin:public_key </dev/tty | |
| fi | |
| echo "" | |
| # Try to add the SSH key — use if/elif to prevent set -e from killing the script | |
| if gh ssh-key add "${SSH_KEY}.pub" --title "Setup ($COMPUTER_NAME)" 2>/dev/null; then | |
| echo -e " ${GREEN}✅ SSH key added to GitHub automatically!${RESET}" | |
| elif gh ssh-key add "${SSH_KEY}.pub" --title "Setup ($COMPUTER_NAME)" 2>&1 | grep -qi "already exists"; then | |
| echo -e " ${GREEN}✅ Key already added to GitHub${RESET}" | |
| else | |
| # Likely missing admin:public_key scope — refresh and retry | |
| echo -e " ${DIM}Requesting permission to manage SSH keys...${RESET}" | |
| echo -e " ${YELLOW}Your browser will open one more time — please approve the request.${RESET}" | |
| echo "" | |
| gh auth refresh -h github.com -s admin:public_key </dev/tty | |
| if gh ssh-key add "${SSH_KEY}.pub" --title "Setup ($COMPUTER_NAME)" 2>/dev/null; then | |
| echo -e " ${GREEN}✅ SSH key added to GitHub automatically!${RESET}" | |
| else | |
| echo -e " ${YELLOW}⚠️ Could not add SSH key — you may need to add it manually${RESET}" | |
| fi | |
| fi | |
| else | |
| echo -e " Your public key is:" | |
| echo "" | |
| echo -e " ${BRIGHT_BLUE}$(cat "${SSH_KEY}.pub")${RESET}" | |
| echo "" | |
| # Copy to clipboard | |
| COPIED=false | |
| if $IS_MAC; then | |
| pbcopy < "${SSH_KEY}.pub" 2>/dev/null && COPIED=true | |
| else | |
| if command -v xclip &>/dev/null; then | |
| xclip -selection clipboard < "${SSH_KEY}.pub" 2>/dev/null && COPIED=true | |
| elif command -v xsel &>/dev/null; then | |
| xsel --clipboard < "${SSH_KEY}.pub" 2>/dev/null && COPIED=true | |
| fi | |
| fi | |
| if [ "$COPIED" = true ]; then | |
| echo -e " ${BOLD}${UNDERLINE}${WHITE}📋 This has already been copied to your clipboard 📋${RESET}" | |
| fi | |
| echo "" | |
| echo "" | |
| echo -e " Now add it to GitHub:" | |
| echo -e " ${WHITE}1.${RESET} Go to: ${UNDERLINE}${CYAN}https://github.com/settings/ssh/new${RESET}" | |
| echo -e " ${WHITE}2.${RESET} Title: ${BOLD}My Computer${RESET}" | |
| echo -e " ${WHITE}3.${RESET} Paste the key and click ${BOLD}'Add SSH key'${RESET}" | |
| echo "" | |
| echo -e " ${YELLOW}Press Enter once you've added the key to GitHub...${RESET}" | |
| read -r </dev/tty | |
| fi | |
| # --- 6. Test GitHub SSH access ----------------------------------------------- | |
| echo "" | |
| echo -e "${BOLD}${CYAN}🔍 Step 6: Testing Connection${RESET}" | |
| echo "" | |
| if ssh -T git@github.com 2>&1 | grep -q "successfully authenticated"; then | |
| echo -e " ${GREEN}✅ GitHub SSH access works!${RESET}" | |
| echo "" | |
| echo -e "${BOLD}${BRIGHT_GREEN}=========================================${RESET}" | |
| echo -e "${BOLD}${BRIGHT_GREEN}🎉 All done! Git and GitHub are ready.${RESET}" | |
| echo -e "${BOLD}${BRIGHT_GREEN}=========================================${RESET}" | |
| echo "" | |
| echo -e " You're set up as: ${BOLD}${WHITE}$current_name${RESET} <${BOLD}${WHITE}$current_email${RESET}>" | |
| else | |
| echo "" | |
| echo -e " ${RED}❌ GitHub SSH access failed.${RESET}" | |
| echo "" | |
| echo -e " ${YELLOW}Make sure you:${RESET}" | |
| echo -e " ${WHITE}1.${RESET} Added the key at: ${UNDERLINE}${CYAN}https://github.com/settings/ssh/new${RESET}" | |
| echo -e " ${WHITE}2.${RESET} Pasted the ${BOLD}entire${RESET} key (starts with ssh-ed25519)" | |
| echo -e " ${WHITE}3.${RESET} Clicked ${BOLD}'Add SSH key'${RESET}" | |
| echo "" | |
| echo -e " ${DIM}Once you've added the key, test it by running:${RESET}" | |
| echo -e " ${BOLD}${WHITE}ssh -T git@github.com${RESET}" | |
| fi | |
| echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment