{"id":25039111,"url":"https://github.com/holasoymas/githubssh","last_synced_at":"2026-02-05T10:31:15.699Z","repository":{"id":274444128,"uuid":"922916844","full_name":"holasoymas/githubssh","owner":"holasoymas","description":"Automating SSH Key Authentication for GitHub: A Step-by-Step Guide","archived":false,"fork":false,"pushed_at":"2025-03-02T02:56:16.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-06T14:48:58.719Z","etag":null,"topics":["github-config","github-ssh-key","no-password-ssh"],"latest_commit_sha":null,"homepage":"https://mahesh-lemon.vercel.app/blog/automate-ssh-key-authentication-for-github","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/holasoymas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-27T10:20:51.000Z","updated_at":"2025-03-02T03:08:21.000Z","dependencies_parsed_at":"2025-03-30T21:37:02.179Z","dependency_job_id":null,"html_url":"https://github.com/holasoymas/githubssh","commit_stats":null,"previous_names":["holasoymas/githubssh"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/holasoymas/githubssh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holasoymas%2Fgithubssh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holasoymas%2Fgithubssh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holasoymas%2Fgithubssh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holasoymas%2Fgithubssh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/holasoymas","download_url":"https://codeload.github.com/holasoymas/githubssh/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/holasoymas%2Fgithubssh/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29119232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T09:40:36.738Z","status":"ssl_error","status_checked_at":"2026-02-05T09:36:49.977Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github-config","github-ssh-key","no-password-ssh"],"created_at":"2025-02-06T02:08:17.031Z","updated_at":"2026-02-05T10:31:15.678Z","avatar_url":"https://github.com/holasoymas.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Automating SSH Key Authentication for GitHub: A Step-by-Step Guide\n\n## Introduction\n\nIf you've encountered issues with GitHub pushes due to expired Personal Access Tokens (PATs) or frequent authentication prompts, this guide provides a detailed solution. Instead of relying on PATs for HTTPS-based authentication, this guide will show you how to set up SSH keys for secure, password-free authentication when pushing and pulling from GitHub. Additionally, we'll automate the SSH agent setup so that you don't need to manually run commands every time you start a new terminal session.\n\nUsing SSH keys has many benefits over HTTPS, including enhanced security, permanent authentication (no expiration), and convenience. Follow this guide to set up SSH for GitHub and eliminate the need to repeatedly authenticate using passwords or tokens.\n\n---\n\n## Table of Contents\n\n1. [Why Use SSH Authentication?](#why-use-ssh-authentication)\n2. [Steps to Set Up SSH Authentication for GitHub](#steps-to-set-up-ssh-authentication-for-github)\n   - [Generating an SSH Key](#generating-an-ssh-key)\n   - [Adding the SSH Key to GitHub](#adding-the-ssh-key-to-github)\n   - [Setting Up the SSH Agent](#setting-up-the-ssh-agent)\n   - [Automating SSH Agent Setup (Optional)](#automating-ssh-agent-setup-optional)\n   - [Verifying SSH Connection](#verifying-ssh-connection)\n   - [Configure Git to always use SSH](#configure-git-to-always-use-ssh)\n   - [Switching Remote URL from HTTPS to SSH](#switching-remote-url-from-https-to-ssh)\n3. [Why SSH Over HTTPS?](#why-ssh-over-https)\n\n---\n\n## Why Use SSH Authentication?\n\nGitHub supports multiple authentication methods, with HTTPS and SSH being the most common. Here's why SSH is the better choice for most developers:\n\n### 1. **Security**\n\nSSH keys provide strong encryption, ensuring that your credentials are never transmitted over the internet in an unencrypted format. This makes SSH more secure than passwords, which can be intercepted if not used correctly.\n\n### 2. **No Expiry**\n\nUnlike Personal Access Tokens (PATs) that expire every 3 months, SSH keys remain valid indefinitely, unless you revoke them. This removes the need for you to manually renew authentication tokens.\n\n### 3. **No Repeated Prompts**\n\nOnce you've configured SSH authentication, you don't need to repeatedly enter your username and password (or PAT) every time you interact with GitHub. SSH allows you to authenticate once and enjoy seamless push/pull operations without further prompts.\n\n### 4. **Convenience**\n\nSSH authentication automatically handles your credentials in the background, reducing friction and making your workflow smoother, especially when dealing with multiple repositories.\n\n---\n\n## Steps to Set Up SSH Authentication for GitHub\n\n### Generating an SSH Key\n\nFirst, you'll need to create a new SSH key pair. This consists of a **private key** (which stays on your machine) and a **public key** (which you’ll upload to GitHub).\n\n1. **Generate a new SSH key** by running the following command in your terminal:\n\n   ```bash\n   ssh-keygen -t ed25519 -C \"your_email@example.com\"\n   ```\n\n   - The `-t ed25519` option creates a new key using the Ed25519 algorithm, which is more secure and efficient than RSA.\n   - The `-C` option adds a comment to the key, typically your email address, for identification purposes.\n\n2. **Choose a location** to save your SSH key (default is `~/.ssh/id_ed25519`). If you’ve previously created an SSH key, you can specify a different name or overwrite the existing one.\n\n3. Optionally, set a **passphrase** for added security (not mandatory).\n\n---\n\n### Adding the SSH Key to GitHub\n\nOnce you’ve generated the SSH key pair, the next step is to add the **public key** to your GitHub account.\n\n1. **View your public SSH key**:\n\n   ```bash\n   cat ~/.ssh/id_ed25519.pub\n   ```\n\n   This command will output the contents of the public key. Copy this entire output (it starts with `ssh-ed25519`).\n\n2. **Add your SSH key to GitHub**:\n\n   - Go to **GitHub \u003e Settings \u003e SSH and GPG Keys**.\n   - Click **New SSH Key**.\n   - Paste your public key into the provided field and give it a title (e.g., \"My new SSH Key\").\n   - Click **Add SSH Key**.\n\n   or click here ***https://github.com/settings/keys***\n\n---\n\n### Setting Up the SSH Agent\n\nThe next step is to ensure that your SSH private key is loaded into the SSH agent, which manages your keys for you.\n\n1. **Start the SSH agent**:\n\n   ```bash\n   eval \"$(ssh-agent -s)\"\n   ```\n\n   - This starts the SSH agent, which will manage your SSH keys in memory.\n\n2. **Add your SSH private key to the agent**:\n\n   ```bash\n   ssh-add ~/.ssh/id_ed25519\n   ```\n\n   - This command adds your SSH private key (`id_ed25519`) to the SSH agent so that it can be used for authentication.\n\n---\n\n### Automating SSH Agent Setup (Optional)\n\nTo avoid manually running the above two commands every time you start a terminal session, you can automate this process.\n\nThis guide will help you automate the SSH key management for GitHub to avoid manually running `ssh-add` every time you push to or pull from your GitHub repository. By configuring your `~/.ssh/config` file, your SSH key will be automatically added to the SSH agent, making your GitHub operations smoother and more efficient.\n\n1. Open the SSH config file for editing:\n\n   ```bash\n   nano ~/.ssh/config\n   ```\n\n2. Add the following configuration to the file:\n   ```bash\n   Host * # or a hostname eg : `Host github.com`\n    AddKeysToAgent yes\n    UseKeychain yes       # Only for macOS\n    IdentityFile ~/.ssh/id_ed25519 # path to your ssh key\n   ```\n\n---\n\n### Verifying SSH Connection\n\nNow that everything is set up, verify that your SSH connection to GitHub is working.\n\n1. Run the following command:\n\n   ```bash\n   ssh -T git@github.com\n   ```\n\n2. You should see a message like:\n\n   ```bash\n   Hi \u003cusername\u003e! You've successfully authenticated, but GitHub does not provide shell access.\n   ```\n\n   - **Explanation**: This confirms that your SSH key is correctly set up and that you can authenticate with GitHub using SSH.\n\n---\n\n### Configure Git to always use SSH\n\nIf you prefer to use SSH for all repositories, you can configure Git globally to rewrite HTTPS URLs to SSH URLs. Here's how:\n\n1. Set Up a Global URL Rewrite :\n\n   ```bash\n   git config --global url.\"git@github.com:\".insteadOf \"https://github.com/\"\n   ```\n\n2. Verify the Configuration :\n\n   ```bash\n   git config --global --list\n   ```\n\n   Look line like this :\n\n   ```bash\n   url.git@github.com:.insteadof=https://github.com/\n   ```\n\n---\n\n### Switching Remote URL from HTTPS to SSH\n\nIf your Git repository was previously using HTTPS for pushing and pulling, you’ll want to switch to SSH to avoid future authentication prompts.\n\nTo check if it has been configured with SSH or HTTPS\n\n```bash\ngit remote -v\n```\n\nIf it has configured with HTTPS, if will show like this\n\n```bash\norigin\thttps://github.com/\u003cusername\u003e/\u003crepositery\u003e.git (fetch)\norigin\thttps://github.com/\u003cusername\u003e/\u003crepositery\u003e.git (push)\n```\n\n1. **Change the remote URL** from HTTPS to SSH with the following command:\n\n   ```bash\n   git remote set-url origin git@github.com:\u003cusername\u003e/\u003crepository\u003e.git\n   ```\n\n   - **Why**: This updates your repository’s configuration to use the SSH URL (`git@github.com:\u003cusername\u003e/\u003crepository\u003e.git`) instead of the HTTPS URL (`https://github.com/\u003cusername\u003e/\u003crepository\u003e.git`).\n   - Once you’ve done this, Git will use your SSH key for authentication rather than prompting you for a password or PAT.\n\n---\n\n## Why SSH Over HTTPS?\n\nWhile HTTPS is simple and widely used, SSH has several advantages:\n\n1. **More Secure**: SSH uses public-key cryptography, making it more secure than basic username/password authentication over HTTPS.\n2. **No Expiry**: SSH keys don’t expire like Personal Access Tokens, meaning you don’t have to worry about renewing them every few months.\n3. **Convenience**: Once set up, SSH allows you to push and pull from GitHub without needing to type your credentials each time.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholasoymas%2Fgithubssh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fholasoymas%2Fgithubssh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fholasoymas%2Fgithubssh/lists"}