Here is a complete, copy-pasteable reference guide you can drop into your notes (like Obsidian or a Markdown file) for whenever you need to do this on a new machine. I’ve also included a bash function at the end that automates the repo setup so you don't have to do it manually every time. The Git SSH Auth Cheat Sheet 1. The Global Setup (Do this once per machine) First, generate your key and configure SSH to always use it without making you manually start the agent or add the key every time. Bash # 1. Generate the key (press Enter for default path, optionally add a passphrase) ssh-keygen -t ed25519 -C "your_email@example.com" # 2. Tell SSH to automatically load keys by creating an SSH config file cat << 'EOF' >> ~/.ssh/config Host * AddKeysToAgent yes IdentityFile ~/.ssh/id_ed25519 EOF # 3. Secure the config file (SSH will ignore it if permissions are too open) chmod 600 ~/.ssh/config 2. Upload the Public Key (Do this once per server) Grab your public key: Bash cat ~/.ssh/id_ed25519.pub For GitHub/GitLab/Gitea: Paste that output into your profile's SSH Keys settings. For a bare FreeBSD/Linux server: Push the key directly via SSH: Bash ssh-copy-id user@your-server-ip Test the connection to make sure the server accepts your key. You should get a welcome message. Bash ssh -T git@github.com # or user@your-server-ip 3. The Per-Repo Setup (Do this for each local project) When you clone a new repo or want to fix an existing one that keeps asking for passwords, force it to use SSH instead of HTTPS. Bash # 1. Switch the remote URL to SSH git remote set-url origin git@github.com:username/repository.git # 2. Make sure your commits have your name attached git config user.name "Your Name" git config user.email "your_email@example.com" # 3. Push and set the upstream branch (assuming you develop on 'dev') git push -u origin dev 🚀 Bonus: Automate the Per-Repo Setup If you don't want to type those per-repo commands out every time, add this function to your ~/.bashrc or ~/.zshrc. It automatically converts an HTTPS origin to SSH, sets your git identity, and pushes your current branch. Bash # Add to ~/.bashrc or ~/.zshrc git-ssh-init() { local origin_url=$(git remote get-url origin 2>/dev/null) if [[ -z "$origin_url" ]]; then echo "No 'origin' remote found. Run 'git remote add origin ' first." return 1 fi # Convert HTTPS GitHub URLs to SSH automatically if [[ "$origin_url" == https://github.com/* ]]; then local ssh_url=$(echo "$origin_url" | sed -e 's|https://github.com/|git@github.com:|') git remote set-url origin "$ssh_url" echo "Switched origin to SSH: $ssh_url" else echo "Current origin: $origin_url" fi # Ensure identity is set git config user.name "Your Name" git config user.email "your_email@example.com" # Push current branch and set upstream local current_branch=$(git branch --show-current) git push -u origin "$current_branch" } Next time you start a project, just type git-ssh-init and you're done. .