{"id":145,"date":"2017-04-05T21:00:03","date_gmt":"2017-04-06T00:00:03","guid":{"rendered":"https:\/\/www.linuxpro.com.br\/2017\/04\/ssh-sem-senha\/"},"modified":"2026-09-08T02:31:58","modified_gmt":"2026-09-08T05:31:58","slug":"ssh-sem-senha","status":"publish","type":"post","link":"https:\/\/www.linuxpro.com.br\/en\/2017\/04\/ssh-sem-senha\/","title":{"rendered":"Using SSH authentication keys"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" alt=\"Mascote do LinuxPro enfiando a chave na fechadura do servidor, com o t\u00fanel SSH cifrado levando as chaves do notebook at\u00e9 o rack\" src=\"\/wp-content\/uploads\/2026\/09\/ssh-chaves-v4.webp\" width=\"1052\" height=\"652\" \/><\/p>\n<div style=\"background:#fff8e1;border-left:4px solid #8b1a1a;padding:.8em 1em;margin:1em 0\"><strong>Note (2026):<\/strong> The 2017 how-to generated RSA (<code data-no-translation=\"\">ssh-keygen -t rsa<\/code>) and disabled passwords with <code data-no-translation=\"\">UsePAM no<\/code> + <code data-no-translation=\"\">\/etc\/init.d\/ssh restart<\/code>. Today the default is <strong>Ed25519<\/strong>; PAM stays enabled; the drop-in goes in <code data-no-translation=\"\">sshd_config.d<\/code>; only disable passwords after testing the key in a second session.<\/div>\n<p>SSH passwords still fall to brute-force attacks. The key pair \u2014 public on the server, private on your machine, protected by a passphrase \u2014 is the 2026 login method. OpenSSH on Ubuntu 24.04\/26.04 already generates Ed25519 if you call <code data-no-translation=\"\">ssh-keygen<\/code> without flags (since 9.5). The rest is permissions, <code data-no-translation=\"\">ssh-copy-id<\/code> and not locking yourself out.<\/p>\n<p><!-- more --><\/p>\n<h2>Generate the key on the client<\/h2>\n<p>As your user, never as root:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">ssh-keygen -t ed25519 -a 64 -C \"$(whoami)@$(hostname)-2026\"\n<\/code><\/pre>\n<p>Accept <code data-no-translation=\"\">~\/.ssh\/id_ed25519<\/code>. Use a real passphrase \u2014 a private key without one is a login stored in a file. <code data-no-translation=\"\">-a 64<\/code> increases KDF rounds. An old server that does not support Ed25519 (rare): <code data-no-translation=\"\">ssh-keygen -t rsa -b 4096<\/code>. DSA is dead in OpenSSH 7+.<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">chmod 700 ~\/.ssh\nchmod 600 ~\/.ssh\/id_ed25519\nchmod 644 ~\/.ssh\/id_ed25519.pub\n<\/code><\/pre>\n<h2>Install the public key on the server<\/h2>\n<p><code data-no-translation=\"\">ssh-copy-id<\/code> creates <code data-no-translation=\"\">~\/.ssh<\/code>, fixes permissions, and appends the line to <code data-no-translation=\"\">authorized_keys<\/code>:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">ssh-copy-id -i ~\/.ssh\/id_ed25519.pub usuario@servidor\n# porta n\u00e3o padr\u00e3o:\nssh-copy-id -i ~\/.ssh\/id_ed25519.pub -p 2222 usuario@servidor\n<\/code><\/pre>\n<p>Without <code data-no-translation=\"\">ssh-copy-id<\/code>:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">ssh usuario@servidor 'mkdir -p ~\/.ssh &amp;&amp; chmod 700 ~\/.ssh'\ncat ~\/.ssh\/id_ed25519.pub | ssh usuario@servidor 'cat &gt;&gt; ~\/.ssh\/authorized_keys &amp;&amp; chmod 600 ~\/.ssh\/authorized_keys'\n<\/code><\/pre>\n<p>Test it <strong>before<\/strong> changing <code data-no-translation=\"\">sshd<\/code>:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">ssh -i ~\/.ssh\/id_ed25519 -o IdentitiesOnly=yes usuario@servidor\n<\/code><\/pre>\n<p>You must get in without the account password (the agent asks for the key's passphrase, if any). Leave this session open. Open another terminal for hardening.<\/p>\n<h2>Disable passwords \u2014 without UsePAM no<\/h2>\n<p>On Ubuntu, <code data-no-translation=\"\">UsePAM no<\/code> (the 2017 advice) breaks other PAM paths. Keep PAM. Use a drop-in, do not edit the entire <code data-no-translation=\"\">sshd_config<\/code> :<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">sudo tee \/etc\/ssh\/sshd_config.d\/99-keys-only.conf &lt;&lt;'EOF'\nPasswordAuthentication no\nKbdInteractiveAuthentication no\nPubkeyAuthentication yes\nPermitRootLogin prohibit-password\nEOF\nsudo sshd -t &amp;&amp; sudo systemctl reload ssh\n<\/code><\/pre>\n<p>On RHEL\/Rocky the service is <code data-no-translation=\"\">sshd<\/code>: <code data-no-translation=\"\">sudo systemctl reload sshd<\/code>. Confirm in the session you left open, and in a <em>new one<\/em>:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">ssh usuario@servidor\n<\/code><\/pre>\n<p>If the new one fails, the old session can still save you. Do not close the console until the key works twice.<\/p>\n<h2>Agent, config, hardware key<\/h2>\n<p><code data-no-translation=\"\">ssh-agent<\/code> (or gnome-keyring) keeps the private key unlocked in the graphical session:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">eval \"$(ssh-agent -s)\"\nssh-add ~\/.ssh\/id_ed25519\n<\/code><\/pre>\n<p>A <code data-no-translation=\"\">~\/.ssh\/config<\/code> avoids a flag:<\/p>\n<pre data-no-translation=\"\"><code class=\"language-bash\" data-no-translation=\"\">Host lab\n  HostName 192.0.2.10\n  User nilton\n  IdentityFile ~\/.ssh\/id_ed25519\n  IdentitiesOnly yes\n<\/code><\/pre>\n<p>YubiKey \/ FIDO2: <code data-no-translation=\"\">ssh-keygen -t ed25519-sk<\/code> (OpenSSH 8.2+). The private key never leaves the token. <code data-no-translation=\"\">ssh-copy-id -i ~\/.ssh\/id_ed25519_sk.pub usuario@servidor<\/code>.<\/p>\n<h2>Wrap-up<\/h2>\n<p>Ed25519, <code data-no-translation=\"\">ssh-copy-id<\/code>, test, and only then disable passwords. The 2017 diagram (client, session, keys) remains valid; the algorithm and the <code data-no-translation=\"\">init.d<\/code> do not. Man page: <code data-no-translation=\"\">man ssh-keygen<\/code>, <code data-no-translation=\"\">man sshd_config<\/code>.<\/p>","protected":false},"excerpt":{"rendered":"<p>SSH passwords are still vulnerable to brute force. A key pair \u2014 the public key on the server, the private key on your machine, protected by a passphrase \u2014 is how you log in in 2026. OpenSSH on Ubuntu 24.04\/26.04 already generates Ed25519 when you run ssh-keygen \u2026 <a title=\"Using SSH authentication keys\" class=\"read-more\" href=\"https:\/\/www.linuxpro.com.br\/en\/2017\/04\/ssh-sem-senha\/\" aria-label=\"Read more about Usando chaves de autentica\u00e7\u00e3o no SSH\">Read more<\/a><\/p>","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[14,4],"class_list":["post-145","post","type-post","status-publish","format-standard","hentry","category-linux","tag-howto","tag-linux"],"_links":{"self":[{"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/posts\/145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/comments?post=145"}],"version-history":[{"count":4,"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/posts\/145\/revisions"}],"predecessor-version":[{"id":1077,"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/posts\/145\/revisions\/1077"}],"wp:attachment":[{"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/media?parent=145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/categories?post=145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxpro.com.br\/en\/wp-json\/wp\/v2\/tags?post=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}