{"id":41,"date":"2026-07-14T00:00:00","date_gmt":"2026-07-14T00:00:00","guid":{"rendered":"http:\/\/\/var\/www\/html\/?p=41"},"modified":"2026-07-21T01:02:32","modified_gmt":"2026-07-21T01:02:32","slug":"git-error-permission-denied-publickey-ssh-key-agent-missing-on-ubuntu-2204-lts","status":"publish","type":"post","link":"https:\/\/butitworkedlocal.com\/git-error-permission-denied-publickey-ssh-key-agent-missing-on-ubuntu-2204-lts\/","title":{"rendered":"Fixing Git &#8216;Permission Denied (publickey)&#8217; with SSH Agent on Ubuntu 22.04 LTS"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Resolve Git &#039;Permission Denied (publickey)&#039; errors on Ubuntu 22.04 LTS by troubleshooting SSH key agent issues, ensuring correct key setup, and proper Git host authentication.<\/strong><\/p>\n\n\n<p>When working with Git repositories over SSH, encountering a &quot;Permission Denied (publickey)&quot; error can halt your development or deployment workflows. This issue often signals a problem with how your SSH client (on Ubuntu 22.04 LTS) is presenting its authentication credentials (your SSH private key) to the remote Git server (e.g., GitHub, GitLab, Bitbucket). The error message &quot;SSH key agent missing&quot; further points to the <code>ssh-agent<\/code> utility, which is responsible for securely managing your private keys in memory.<\/p>\n<h3>Symptom &amp; Error Signature<\/h3>\n<p>You will typically encounter this error when attempting to perform Git operations that require authentication with a remote server via SSH, such as <code>git clone<\/code>, <code>git push<\/code>, or <code>git pull<\/code>.<\/p>\n<p>The output in your terminal might look similar to one of these:<\/p>\n<pre><code class=\"language-bash\">git@github.com: Permission denied (publickey).\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n<\/code><\/pre>\n<p>Or, with a more explicit &quot;agent missing&quot; hint (though this part is often inferred rather than explicitly stated by Git itself, <code>ssh<\/code> might report it with verbose output):<\/p>\n<pre><code class=\"language-bash\">Cloning into &#039;my-repository&#039;...\ngit@gitlab.com: Permission denied (publickey).\nThe authenticity of host &#039;gitlab.com (X.X.X.X)&#039; can&#039;t be established.\nED25519 key fingerprint is SHA256:....\nThis key is not known by any other names\nAre you sure you want to continue connecting (yes\/no\/[fingerprint])? yes\nWarning: Permanently added &#039;gitlab.com&#039; (ED25519) to the list of known hosts.\ngit@gitlab.com: Permission denied (publickey).\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n<\/code><\/pre>\n<p>In some verbose scenarios, you might see <code>Agent admitted failure to sign using the key.<\/code> or <code>no mutual signature algorithm<\/code> if the agent is running but lacks the correct key.<\/p>\n<h3>Root Cause Analysis<\/h3>\n<p>The &quot;Permission Denied (publickey)&quot; error, especially when combined with issues related to the <code>ssh-agent<\/code>, stems from one or more of the following underlying problems:<\/p>\n<ol>\n<li><strong>Missing or Unloaded Private Key:<\/strong> Your SSH private key (<code>id_rsa<\/code>, <code>id_ed25519<\/code>, etc.) is either not present on your system, or it exists but has not been added to your <code>ssh-agent<\/code> for use. The <code>ssh-agent<\/code> acts as a key manager, allowing <code>ssh<\/code> and <code>git<\/code> to use your keys without repeatedly asking for passphrases.<\/li>\n<li><strong><code>ssh-agent<\/code> Not Running or Misconfigured:<\/strong> The <code>ssh-agent<\/code> process, which holds your keys in memory, might not be running in your current shell session, or it may not have been correctly configured to start automatically with your desktop environment or terminal session.<\/li>\n<li><strong>Incorrect Private Key Permissions:<\/strong> SSH keys require strict file permissions (typically <code>600<\/code> for the private key and <code>700<\/code> for the <code>.ssh<\/code> directory). If permissions are too liberal, <code>ssh<\/code> will refuse to use the key for security reasons.<\/li>\n<li><strong>Public Key Not Registered with Git Hosting Service:<\/strong> Even if your private key is correctly set up locally, the corresponding public key (<code>id_rsa.pub<\/code>, <code>id_ed25519.pub<\/code>) must be uploaded and registered with your Git hosting provider (GitHub, GitLab, Bitbucket) for your user account. The remote server uses this public key to verify your identity.<\/li>\n<li><strong>Incorrect Git Remote URL:<\/strong> You might be attempting to use an HTTPS remote URL (e.g., <code>https:\/\/github.com\/user\/repo.git<\/code>) instead of an SSH URL (e.g., <code>git@github.com:user\/repo.git<\/code>). SSH authentication only works with SSH-formatted remote URLs.<\/li>\n<li><strong><code>~\/.ssh\/config<\/code> Issues:<\/strong> If you have a custom SSH configuration file (<code>~\/.ssh\/config<\/code>), it might be misconfigured, pointing to the wrong key, or overriding necessary default behaviors.<\/li>\n<li><strong>Key Passphrase Not Provided:<\/strong> If your private key is encrypted with a passphrase, and the <code>ssh-agent<\/code> is not running or the passphrase wasn&#039;t provided when adding the key to the agent, authentication will fail.<\/li>\n<\/ol>\n<h3>Step-by-Step Resolution<\/h3>\n<p>Follow these steps sequentially to diagnose and resolve the &quot;Permission Denied (publickey)&quot; error.<\/p>\n<h4>1. Verify SSH Key Existence and Permissions<\/h4>\n<p>First, ensure you have an SSH key pair and that its permissions are correctly set.<\/p>\n<ol>\n<li><p><strong>Check for existing keys:<\/strong><\/p>\n<pre><code class=\"language-bash\">ls -al ~\/.ssh\/\n<\/code><\/pre>\n<p>Look for files like <code>id_rsa<\/code>, <code>id_rsa.pub<\/code>, <code>id_ed25519<\/code>, <code>id_ed25519.pub<\/code>. If you see only <code>.pub<\/code> files or no <code>id_*<\/code> files, you might not have a key.<\/p>\n<\/li>\n<li><p><strong>If no key exists, generate a new one:<\/strong><\/p>\n<pre><code class=\"language-bash\">ssh-keygen -t ed25519 -C &quot;your_email@example.com&quot;\n<\/code><\/pre>\n<blockquote><p><code>ed25519<\/code> is the recommended modern key type. You can use <code>rsa<\/code> with <code>-b 4096<\/code> for older compatibility if needed.\nWhen prompted for a file to save the key, press <code>Enter<\/code> to accept the default (<code>~\/.ssh\/id_ed25519<\/code>).\n<strong>Always set a strong passphrase for your private key.<\/strong> This encrypts your private key at rest, adding a crucial layer of security.<\/p>\n<\/blockquote>\n<\/li>\n<li><p><strong>Set correct permissions for your <code>.ssh<\/code> directory and keys:<\/strong><\/p>\n<pre><code class=\"language-bash\">chmod 700 ~\/.ssh\nchmod 600 ~\/.ssh\/id_ed25519 # Or id_rsa if you use RSA\nchmod 644 ~\/.ssh\/id_ed25519.pub # Or id_rsa.pub\n<\/code><\/pre>\n<blockquote class=\"important\"><p>Incorrect permissions are a very common cause of SSH authentication failures. The private key <em>must<\/em> only be readable by the owner.<\/p>\n<\/blockquote>\n<\/li>\n<\/ol>\n<h4>2. Start <code>ssh-agent<\/code> and Add Your Private Key<\/h4>\n<p>The <code>ssh-agent<\/code> process is key to managing your SSH identities.<\/p>\n<ol>\n<li><p><strong>Check if <code>ssh-agent<\/code> is running:<\/strong><\/p>\n<pre><code class=\"language-bash\">eval &quot;$(ssh-agent -s)&quot;\n<\/code><\/pre>\n<p>If it&#039;s already running, it will output something like <code>SSH_AUTH_SOCK=\/tmp\/ssh-XXXXXX\/agent.YYYY; export SSH_AUTH_SOCK; SSH_AGENT_PID=ZZZZZ; export SSH_AGENT_PID; echo Agent pid ZZZZZ;<\/code>. If it wasn&#039;t running, this command will start it and set the necessary environment variables.<\/p>\n<\/li>\n<li><p><strong>Add your private key to <code>ssh-agent<\/code>:<\/strong><\/p>\n<pre><code class=\"language-bash\">ssh-add ~\/.ssh\/id_ed25519 # Use the path to your private key\n<\/code><\/pre>\n<p>If your key has a passphrase, you will be prompted to enter it.\nIf you have multiple keys, add them all.\nYou can check which keys are loaded with <code>ssh-add -l<\/code>.<\/p>\n<blockquote><p>On Ubuntu, <code>ssh-agent<\/code> is often started automatically with your desktop environment. However, it might not be running in a specific terminal session, or it might not have your key loaded. The <code>eval &quot;$(ssh-agent -s)&quot;<\/code> and <code>ssh-add<\/code> commands are typically needed once per session or set up for persistence.<\/p>\n<\/blockquote>\n<\/li>\n<\/ol>\n<h4>3. Verify Public Key on Git Hosting Service<\/h4>\n<p>Your remote Git server needs to know your public key to authenticate you.<\/p>\n<ol>\n<li><p><strong>Copy your public key to clipboard:<\/strong><\/p>\n<pre><code class=\"language-bash\">cat ~\/.ssh\/id_ed25519.pub\n<\/code><\/pre>\n<p>Copy the entire output, starting with <code>ssh-ed25519<\/code> (or <code>ssh-rsa<\/code>) and ending with your email address.<\/p>\n<\/li>\n<li><p><strong>Add the public key to your Git hosting provider:<\/strong><\/p>\n<ul>\n<li><strong>GitHub:<\/strong> Go to <code>Settings<\/code> -&gt; <code>SSH and GPG keys<\/code> -&gt; <code>New SSH key<\/code>. Paste your public key.<\/li>\n<li><strong>GitLab:<\/strong> Go to <code>User Settings<\/code> -&gt; <code>SSH Keys<\/code>. Paste your public key.<\/li>\n<li><strong>Bitbucket:<\/strong> Go to <code>Profile settings<\/code> -&gt; <code>SSH keys<\/code>. Add key.<\/li>\n<li><strong>Self-hosted Git (e.g., Gitea, plain Git):<\/strong> You&#039;ll typically add it to the <code>~\/.ssh\/authorized_keys<\/code> file of the <code>git<\/code> user on the server.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h4>4. Validate Git Remote URL<\/h4>\n<p>Ensure your local Git repository is configured to use the SSH remote URL, not HTTPS.<\/p>\n<ol>\n<li><p><strong>Check current remote URLs:<\/strong>\nNavigate to your repository directory and run:<\/p>\n<pre><code class=\"language-bash\">git remote -v\n<\/code><\/pre>\n<p>Look for URLs starting with <code>git@<\/code> (SSH) rather than <code>https:\/\/<\/code>.<\/p>\n<p><strong>Example of an SSH URL:<\/strong><\/p>\n<pre><code>origin  git@github.com:your_username\/your_repository.git (fetch)\norigin  git@github.com:your_username\/your_repository.git (push)\n<\/code><\/pre>\n<p><strong>Example of an HTTPS URL (which will cause issues):<\/strong><\/p>\n<pre><code>origin  https:\/\/github.com\/your_username\/your_repository.git (fetch)\norigin  https:\/\/github.com\/your_username\/your_repository.git (push)\n<\/code><\/pre>\n<\/li>\n<li><p><strong>Change remote URL to SSH if necessary:<\/strong>\nIf you&#039;re using an HTTPS URL, update it to SSH:<\/p>\n<pre><code class=\"language-bash\">git remote set-url origin git@github.com:your_username\/your_repository.git\n<\/code><\/pre>\n<p>Replace <code>your_username\/your_repository.git<\/code> with your actual repository path.<\/p>\n<\/li>\n<\/ol>\n<h4>5. Test SSH Connection<\/h4>\n<p>Test your SSH connection to the Git hosting service. This verifies that your local SSH setup can authenticate.<\/p>\n<pre><code class=\"language-bash\">ssh -T git@github.com\n# Or for GitLab: ssh -T git@gitlab.com\n# Or for Bitbucket: ssh -T git@bitbucket.org\n<\/code><\/pre>\n<p>You should see a message indicating successful authentication (e.g., &quot;Hi your_username! You&#039;ve successfully authenticated&#8230;&quot;). If you see &quot;Permission denied (publickey)&quot;, re-evaluate the previous steps.<\/p>\n<blockquote class=\"important\"><p>Use the <code>-v<\/code> flag for verbose output (<code>ssh -vT git@github.com<\/code>) if you&#039;re still facing issues. This can provide valuable debugging information about which keys are being tried and why they&#039;re failing.<\/p>\n<\/blockquote>\n<h4>6. Troubleshoot <code>~\/.ssh\/config<\/code> (Advanced)<\/h4>\n<p>If you have a <code>~\/.ssh\/config<\/code> file, it might be interfering.<\/p>\n<ol>\n<li><p><strong>Inspect <code>~\/.ssh\/config<\/code>:<\/strong><\/p>\n<pre><code class=\"language-bash\">cat ~\/.ssh\/config\n<\/code><\/pre>\n<p>Look for <code>Host<\/code> entries related to your Git provider (e.g., <code>Host github.com<\/code>). Ensure any <code>IdentityFile<\/code> directives point to the correct private key and that there are no conflicting options.<\/p>\n<p>A minimal working configuration might look like this:<\/p>\n<pre><code>Host github.com\n    Hostname ssh.github.com\n    Port 443\n    User git\n    IdentityFile ~\/.ssh\/id_ed25519\n    AddKeysToAgent yes\n    UseKeychain yes # macOS specific, ignore on Ubuntu\n<\/code><\/pre>\n<p>The <code>Port 443<\/code> and <code>Hostname ssh.github.com<\/code> lines are useful if you&#039;re behind a firewall that blocks standard SSH port 22.<\/p>\n<\/li>\n<li><p><strong>Temporarily disable <code>~\/.ssh\/config<\/code>:<\/strong>\nRename it (<code>mv ~\/.ssh\/config ~\/.ssh\/config_backup<\/code>) and try connecting again. If it works, the issue is in your config file.<\/p>\n<\/li>\n<\/ol>\n<h4>7. Persist <code>ssh-agent<\/code> Across Sessions (Optional but Recommended)<\/h4>\n<p>To avoid re-running <code>eval &quot;$(ssh-agent -s)&quot;<\/code> and <code>ssh-add<\/code> every time you open a new terminal or reboot, configure your shell to handle this automatically.<\/p>\n<ol>\n<li><p><strong>For Bash users:<\/strong>\nEdit your <code>~\/.bashrc<\/code> file:<\/p>\n<pre><code class=\"language-bash\">nano ~\/.bashrc\n<\/code><\/pre>\n<p>Add the following lines at the end:<\/p>\n<pre><code class=\"language-bash\"># Start ssh-agent if not running\nif [ -z &quot;$SSH_AUTH_SOCK&quot; ]; then\n    eval &quot;$(ssh-agent -s)&quot;\n    ssh-add ~\/.ssh\/id_ed25519 # Add your private key here\nfi\n<\/code><\/pre>\n<p>Save the file and exit (<code>Ctrl+X<\/code>, <code>Y<\/code>, <code>Enter<\/code>).\nThen, apply the changes: <code>source ~\/.bashrc<\/code>.<\/p>\n<\/li>\n<li><p><strong>For Zsh users:<\/strong>\nEdit your <code>~\/.zshrc<\/code> file:<\/p>\n<pre><code class=\"language-bash\">nano ~\/.zshrc\n<\/code><\/pre>\n<p>Add the same lines as for Bash. Save, exit, and then <code>source ~\/.zshrc<\/code>.<\/p>\n<blockquote class=\"warning\"><p>While convenient, <code>ssh-add<\/code> in <code>.bashrc<\/code>\/<code>.zshrc<\/code> will prompt for your passphrase every time a new shell is opened if the agent doesn&#039;t already have the key. A more robust solution might involve using <code>keychain<\/code> (if available on Ubuntu) or relying on desktop environment integration. For most server environments where you login via SSH directly, the above <code>if<\/code> block is a practical solution.<\/p>\n<\/blockquote>\n<\/li>\n<\/ol>\n<p>By systematically following these steps, you should be able to resolve the &quot;Permission Denied (publickey)&quot; error caused by SSH key agent issues on your Ubuntu 22.04 LTS system and resume your Git operations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Resolve Git &#8216;Permission Denied (publickey)&#8217; errors on Ubuntu 22.04 LTS by troubleshooting SSH key agent issues, ensuring correct key setup, and proper Git host authentication.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[40,106,110,112,6,111],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-git-ci-cd","tag-devops","tag-git","tag-ssh","tag-ssh-agent","tag-troubleshooting","tag-ubuntu-22-04"],"_links":{"self":[{"href":"https:\/\/butitworkedlocal.com\/wp-json\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/butitworkedlocal.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/butitworkedlocal.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/butitworkedlocal.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/butitworkedlocal.com\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":2,"href":"https:\/\/butitworkedlocal.com\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"predecessor-version":[{"id":289,"href":"https:\/\/butitworkedlocal.com\/wp-json\/wp\/v2\/posts\/41\/revisions\/289"}],"wp:attachment":[{"href":"https:\/\/butitworkedlocal.com\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/butitworkedlocal.com\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/butitworkedlocal.com\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}