<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: VeloxaHost</title>
    <description>The latest articles on DEV Community by VeloxaHost (@veloxahost_com).</description>
    <link>https://dev.to/veloxahost_com</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4274944%2F76399ba0-9f2a-4e61-b409-a1dd1a1808f3.png</url>
      <title>DEV Community: VeloxaHost</title>
      <link>https://dev.to/veloxahost_com</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/veloxahost_com"/>
    <language>en</language>
    <item>
      <title>Permission denied (publickey)? 7 causes and 2 commands to find yours</title>
      <dc:creator>VeloxaHost</dc:creator>
      <pubDate>Mon, 30 Nov 2026 19:06:02 +0000</pubDate>
      <link>https://dev.to/veloxahost_com/permission-denied-publickey-7-causes-and-2-commands-to-find-yours-418o</link>
      <guid>https://dev.to/veloxahost_com/permission-denied-publickey-7-causes-and-2-commands-to-find-yours-418o</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user@your.server: Permission denied (publickey).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;SSH tried key authentication, the server said no, and there was nothing else to try. The message never says &lt;em&gt;why&lt;/em&gt;, so people start regenerating keys at random. Don't. It's almost always one of seven things, and two commands tell you which.&lt;/p&gt;

&lt;h2&gt;
  
  
  First: get the real reason
&lt;/h2&gt;

&lt;p&gt;On your machine, run SSH in verbose mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh -v user@your.server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look for lines like &lt;code&gt;Offering public key: /home/you/.ssh/id_ed25519&lt;/code&gt; and &lt;code&gt;Authentications that can continue: publickey&lt;/code&gt;. They show which keys your client tried.&lt;/p&gt;

&lt;p&gt;If you still have another way in (a console in your provider's dashboard, or a second session), watch the server side at the same time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo journalctl -u ssh -f        &lt;span class="c"&gt;# Ubuntu, Debian&lt;/span&gt;
sudo journalctl -u sshd -f       &lt;span class="c"&gt;# RHEL family&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server log often says exactly what's wrong: bad ownership, an invalid user, or a key type it won't accept.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Wrong user name
&lt;/h2&gt;

&lt;p&gt;Cloud images often disable root login and create a default user instead: &lt;code&gt;ubuntu&lt;/code&gt; on Ubuntu, &lt;code&gt;debian&lt;/code&gt; on Debian, &lt;code&gt;ec2-user&lt;/code&gt; on Amazon Linux. Others do the opposite and only set up root. Use the user your provider documents, or the one you created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh ubuntu@your.server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Your client isn't offering the right key
&lt;/h2&gt;

&lt;p&gt;If &lt;code&gt;ssh -v&lt;/code&gt; never offers the key that's on the server, point at it directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh -i ~/.ssh/id_ed25519 user@your.server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then make it permanent in &lt;code&gt;~/.ssh/config&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ssh"&gt;&lt;code&gt;&lt;span class="nc"&gt;Host&lt;/span&gt; &lt;span class="n"&gt;myserver&lt;/span&gt;
  &lt;span class="nc"&gt;HostName&lt;/span&gt; &lt;span class="n"&gt;your&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;
  &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="n"&gt;deploy&lt;/span&gt;
  &lt;span class="nc"&gt;IdentityFile&lt;/span&gt; &lt;span class="o"&gt;~/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ssh&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;id_ed25519&lt;/span&gt;
  &lt;span class="nc"&gt;IdentitiesOnly&lt;/span&gt; &lt;span class="n"&gt;yes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;IdentitiesOnly yes&lt;/code&gt; matters if you have many keys loaded in an agent. Without it, the client may offer five wrong keys first and hit the server's &lt;code&gt;MaxAuthTries&lt;/code&gt; limit ("Too many authentication failures") before it gets to the right one.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The public key isn't on the server
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;public&lt;/strong&gt; key (&lt;code&gt;id_ed25519.pub&lt;/code&gt;, one line) must be in &lt;code&gt;~/.ssh/authorized_keys&lt;/code&gt; of the user you log in as. The common mistakes are adding it to root's file while logging in as another user, or pasting it with line breaks in the middle.&lt;/p&gt;

&lt;p&gt;From a machine that can still log in, &lt;code&gt;ssh-copy-id&lt;/code&gt; does it correctly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-copy-id -i ~/.ssh/id_ed25519.pub user@your.server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Permissions on the server
&lt;/h2&gt;

&lt;p&gt;sshd refuses keys if the files around them are too open. This is the &lt;code&gt;StrictModes&lt;/code&gt; check, and it's on by default.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R &lt;span class="nv"&gt;$USER&lt;/span&gt;:&lt;span class="nv"&gt;$USER&lt;/span&gt; ~/.ssh
chmod go-w ~
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That last line matters too: if the home directory itself is writable by group or others, the key is refused.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Permissions on your private key
&lt;/h2&gt;

&lt;p&gt;If your client prints &lt;code&gt;WARNING: UNPROTECTED PRIVATE KEY FILE!&lt;/code&gt;, it ignores the key. Fix it locally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;chmod 600 ~/.ssh/id_ed25519
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. The server config says no
&lt;/h2&gt;

&lt;p&gt;Check the settings sshd is actually using, not just what's in one file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo sshd -T &lt;span class="o"&gt;|&lt;/span&gt; grep -Ei &lt;span class="s1"&gt;'pubkeyauthentication|allowusers|authorizedkeysfile|permitrootlogin'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;AllowUsers&lt;/code&gt; that doesn't include your user, &lt;code&gt;PermitRootLogin no&lt;/code&gt; when you log in as root, or a custom &lt;code&gt;AuthorizedKeysFile&lt;/code&gt; path are all common causes after someone hardened the server. Drop-in files in &lt;code&gt;/etc/ssh/sshd_config.d/&lt;/code&gt; count too.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. An old RSA key
&lt;/h2&gt;

&lt;p&gt;Newer OpenSSH versions disabled the old &lt;code&gt;ssh-rsa&lt;/code&gt; signature algorithm (RSA with SHA-1) by default. Very old clients, or old keys used by old tools, can be refused even though the key is in the right place. The clean fix is a modern key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-keygen -t ed25519 -C &lt;span class="s2"&gt;"you@example.com"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then add the new &lt;code&gt;.pub&lt;/code&gt; to the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't lock yourself out
&lt;/h2&gt;

&lt;p&gt;When you change SSH settings or keys, keep your current session open and test the new login in a second terminal. Most providers also have a browser console that works without SSH, so find it before you need it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;ssh -v&lt;/code&gt;: which keys were offered?&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;journalctl -u ssh -f&lt;/code&gt; on the server: what did it say?&lt;/li&gt;
&lt;li&gt;Right user name for the image&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-i&lt;/code&gt; or &lt;code&gt;IdentityFile&lt;/code&gt;, plus &lt;code&gt;IdentitiesOnly yes&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Public key in the right user's &lt;code&gt;authorized_keys&lt;/code&gt;, on one line&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;700&lt;/code&gt; on &lt;code&gt;~/.ssh&lt;/code&gt;, &lt;code&gt;600&lt;/code&gt; on &lt;code&gt;authorized_keys&lt;/code&gt;, home not group-writable&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;600&lt;/code&gt; on your private key&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sshd -T&lt;/code&gt;: AllowUsers, PermitRootLogin, AuthorizedKeysFile&lt;/li&gt;
&lt;li&gt;Old RSA key? Generate ed25519&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;More server fixes, including our &lt;a href="https://veloxahost.com/blog/posts/linux-server-hardening-checklist.html?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=ssh-publickey" rel="noopener noreferrer"&gt;Linux server hardening checklist&lt;/a&gt;, are on the &lt;a href="https://veloxahost.com/blog?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=ssh-publickey" rel="noopener noreferrer"&gt;VeloxaHost blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: we run VeloxaHost, a web hosting and VPS provider. Everything above works on any Linux server.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>ssh</category>
      <category>devops</category>
      <category>security</category>
    </item>
  </channel>
</rss>
