{"id":8620,"date":"2025-03-28T12:17:47","date_gmt":"2025-03-28T12:17:47","guid":{"rendered":"https:\/\/chemicloud.com\/kb\/?post_type=ht_kb&#038;p=8620"},"modified":"2025-03-28T12:17:47","modified_gmt":"2025-03-28T12:17:47","slug":"ssh-permission-denied-publickey-error","status":"publish","type":"ht_kb","link":"https:\/\/chemicloud.com\/kb\/article\/ssh-permission-denied-publickey-error\/","title":{"rendered":"How to Fix SSH Permission Denied (publickey) Error on Linux and Mac"},"content":{"rendered":"<p>The &#8220;Permission denied (publickey,gssapi-keyex,gssapi-with-mic)&#8221; error you&#8217;re encountering suggests that SSH is unable to authenticate using the private key located at:<\/p>\n<p>~\/.ssh\/id_rsa<\/p>\n<p>Here\u2019s a step-by-step guide to troubleshoot and resolve this:<\/p>\n<p data-start=\"209\" data-end=\"266\"><strong>Step 1) Check If SSH Agent Is Running and Add the Key<\/strong><\/p>\n<p class=\"\" data-start=\"267\" data-end=\"333\">Run the following to check if your SSH key is loaded in the agent:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-bash\">ssh-add -l<br \/>\n<\/code><\/div>\n<\/div>\n<ul data-start=\"359\" data-end=\"387\">\n<li class=\"\" data-start=\"359\" data-end=\"387\">\n<p class=\"\" data-start=\"361\" data-end=\"387\">If you see something like:<\/p>\n<\/li>\n<\/ul>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\"><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre\"><span class=\"hljs-attribute\">The<\/span> agent has <span class=\"hljs-literal\">no<\/span> identities.<br \/>\n<\/code><\/div>\n<\/div>\n<p data-start=\"426\" data-end=\"454\">Add the key manually:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-bash\">ssh-add ~\/.ssh\/id_rsa<br \/>\n<\/code><\/div>\n<\/div>\n<ul data-start=\"490\" data-end=\"585\">\n<li class=\"\" data-start=\"490\" data-end=\"549\">\n<p class=\"\" data-start=\"492\" data-end=\"549\">If your key is encrypted, it will ask for the passphrase.<\/p>\n<\/li>\n<li class=\"\" data-start=\"550\" data-end=\"585\">\n<p class=\"\" data-start=\"552\" data-end=\"585\">Once added, try connecting again:<\/p>\n<\/li>\n<\/ul>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\"><\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-bash\">ssh username@server-ip-address<\/code><code class=\"!whitespace-pre language-bash\"><\/code><\/div>\n<\/div>\n<hr class=\"\" data-start=\"624\" data-end=\"627\" \/>\n<p data-start=\"629\" data-end=\"663\"><strong>Step 2) Check File Permissions<\/strong><\/p>\n<p class=\"\" data-start=\"664\" data-end=\"750\">Incorrect file permissions can cause the <code data-start=\"705\" data-end=\"724\">Permission denied<\/code> error. Run the following:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"sticky top-9\">\n<div class=\"absolute bottom-0 right-0 flex h-9 items-center pr-2\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><\/div>\n<\/div>\n<\/div>\n<pre class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-bash\"><span class=\"hljs-comment\"># Correct permissions for private key<\/span>\r\n<span class=\"hljs-built_in\">chmod<\/span> 600 ~\/.ssh\/id_rsa\r\n\r\n<span class=\"hljs-comment\"># \r\nCorrect permissions for public key<\/span>\r\n<span class=\"hljs-built_in\">chmod<\/span> 644 ~\/.ssh\/id_rsa.pub\r\n\r\n<span class=\"hljs-comment\"># Correct permissions for the .ssh folder<\/span>\r\n<span class=\"hljs-built_in\">chmod<\/span> 700 ~\/.ssh\r\n<\/code><\/pre>\n<\/div>\n<hr class=\"\" data-start=\"953\" data-end=\"956\" \/>\n<p data-start=\"958\" data-end=\"1011\"><strong>Step 3) Verify Key Usage in SSH Config (Optional)<\/strong><\/p>\n<p class=\"\" data-start=\"1012\" data-end=\"1093\">If you are using a custom SSH key or different config, check the SSH config file:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-bash\">nano ~\/.ssh\/config<br \/>\n<\/code><\/div>\n<\/div>\n<p class=\"\" data-start=\"1127\" data-end=\"1200\">Ensure the following is in place (replace with the correct IP if needed):<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<pre class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre\"><span class=\"hljs-attribute\">Host<\/span> <span class=\"hljs-number\">server-ip-address <\/span>User user-to-connect\u00a0 \u00a0 \u00a0IdentityFile ~\/.ssh\/id_rsa\r\n<\/code><\/pre>\n<\/div>\n<hr class=\"\" data-start=\"1277\" data-end=\"1280\" \/>\n<p data-start=\"1282\" data-end=\"1325\"><strong>Step 4) Test Verbose Mode for Debugging<\/strong><\/p>\n<p class=\"\" data-start=\"1326\" data-end=\"1396\">If it still doesn\u2019t work, run SSH in verbose mode to get more details:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-bash\">ssh -v username@server-ip-address-or-hostname<\/code><\/div>\n<\/div>\n<p class=\"\" data-start=\"1439\" data-end=\"1488\">This will help identify any configuration issues.<\/p>\n<hr class=\"\" data-start=\"1490\" data-end=\"1493\" \/>\n<p data-start=\"1495\" data-end=\"1537\"><strong>Step 5) Regenerate SSH Key (if needed)<\/strong><\/p>\n<p class=\"\" data-start=\"1538\" data-end=\"1595\">If the key is corrupted or invalid, regenerate a new key:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-bash\">ssh-keygen -t rsa -b 4096 -C <span class=\"hljs-string\">\"your_email@example.com\"<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<ul data-start=\"1664\" data-end=\"1793\">\n<li class=\"\" data-start=\"1664\" data-end=\"1721\">\n<p class=\"\" data-start=\"1666\" data-end=\"1721\">Save the new key as <code data-start=\"1686\" data-end=\"1694\">id_rsa<\/code> in the <code data-start=\"1702\" data-end=\"1710\">~\/.ssh<\/code> directory.<\/p>\n<\/li>\n<li class=\"\" data-start=\"1722\" data-end=\"1793\">\n<p class=\"\" data-start=\"1724\" data-end=\"1793\">Add the new public key to the server\u2019s <code data-start=\"1763\" data-end=\"1787\">~\/.ssh\/authorized_keys<\/code> file.<\/p>\n<\/li>\n<\/ul>\n<hr class=\"\" data-start=\"1795\" data-end=\"1798\" \/>\n<p data-start=\"1800\" data-end=\"1850\"><strong>Step 6) Check if Public Key is added on the Server<\/strong><\/p>\n<p class=\"\" data-start=\"1851\" data-end=\"1904\">If you suspect the key is missing on the server, ensure that your public key is added to the <code data-start=\"2006\" data-end=\"2030\">~\/.ssh\/authorized_keys<\/code> on the server.<\/p>\n<hr class=\"\" data-start=\"2367\" data-end=\"2370\" \/>\n<p class=\"\" data-start=\"2372\" data-end=\"2423\">If none of these steps work, send the output of verbose mode to your server administrator.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The &#8220;Permission denied (publickey,gssapi-keyex,gssapi-with-mic)&#8221; error you&#8217;re encountering suggests that SSH is unable to authenticate using the private key located at: ~\/.ssh\/id_rsa Here\u2019s a step-by-step guide to troubleshoot and resolve this: Step 1) Check If SSH Agent Is Running and Add the Key Run the following to check if your SSH&#8230;<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"ht-kb-category":[37],"ht-kb-tag":[],"class_list":["post-8620","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-ftp-and-ssh-access"],"_links":{"self":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/8620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/comments?post=8620"}],"version-history":[{"count":1,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/8620\/revisions"}],"predecessor-version":[{"id":8621,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/8620\/revisions\/8621"}],"wp:attachment":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/media?parent=8620"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=8620"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=8620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}