{"id":646,"date":"2016-09-28T00:00:00","date_gmt":"2016-09-28T00:00:00","guid":{"rendered":"http:\/\/blog.hostinger.io\/hostinger-tutorials\/uncategorized\/sshhow-to-set-up-ssh-keys\/"},"modified":"2026-10-27T23:32:18","modified_gmt":"2026-10-27T23:32:18","slug":"how-to-set-up-ssh-keys","status":"publish","type":"post","link":"\/au\/tutorials\/how-to-set-up-ssh-keys\/","title":{"rendered":"How to set up SSH keys for secure server authentication"},"content":{"rendered":"<p class=\"wp-block-paragraph\">SSH keys let you authenticate to a remote server using a pair of authentication keys; one public, one private. You use this pair of keys instead of a password to make remote access more secure. It&rsquo;s also faster than typing a password each time. <\/p><p class=\"wp-block-paragraph\">Setting up SSH keys involves five steps:<\/p><ol class=\"wp-block-list\">\n<li>Generating an SSH key pair.<\/li>\n\n\n\n<li>Saving the key and adding a passphrase.<\/li>\n\n\n\n<li>Adding the public key to the server or hPanel.<\/li>\n\n\n\n<li>Testing SSH key authentication.<\/li>\n\n\n\n<li>Disabling password authentication after SSH key login works.<\/li>\n\n\n\n<li>Managing and troubleshooting SSH keys.<\/li>\n<\/ol><h2 class=\"wp-block-heading h-t-title-2\" id=\"h-how-do-ssh-keys-work\">How do SSH keys work?<\/h2><p class=\"wp-block-paragraph\"><a data-click-id=\"hgr-post-content-link-ssh\" href=\"\/au\/tutorials\/what-is-ssh\/\" data-wpel-link=\"internal\" rel=\"follow\">SSH<\/a> keys authenticate the connection by signature, not by sending a password. The keys work as a matched pair: one <strong>public key<\/strong> and one <strong>private key<\/strong>. The public key goes on the remote server, where it checks that signature. The private key stays on your local machine and signs the server&rsquo;s challenge when prompted. <\/p><p class=\"wp-block-paragraph\">The server then verifies the signature with the stored public key. If it matches, access is granted, all without sending a password over the network. You should never share your private SSH keys with anyone.<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td colspan=\"1\" rowspan=\"1\"><p><strong>Key type<\/strong><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><strong>Where it lives<\/strong><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><strong>What it does<\/strong><\/p><\/td><\/tr><tr><td colspan=\"1\" rowspan=\"1\"><p><strong>Public key<\/strong><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Remote server<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Verifies your identity<\/span><\/p><\/td><\/tr><tr><td colspan=\"1\" rowspan=\"1\"><p><strong>Private key<\/strong><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Your local machine<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Authenticates the connection<\/span><\/p><\/td><\/tr><\/tbody><\/table><\/figure><p class=\"wp-block-paragraph\">Using SSH keys is more secure than normal password authentication. It&rsquo;s resistant to cyberattacks that target passwords (like brute-force attacks). Even if bad actors intercept your network traffic, the private key doesn&rsquo;t leave your machine.<\/p><h2 class=\"wp-block-heading h-t-title-2\" id=\"h-what-do-you-need-before-setting-up-ssh-keys\">What do you need before setting up SSH keys?<\/h2><p class=\"wp-block-paragraph\">Before you can generate SSH keys, you&rsquo;ll need these three things:<\/p><ul class=\"wp-block-list\">\n<li><strong>A local computer with a terminal.<\/strong> Linux and macOS users can use the built-in Terminal. Windows users can use PowerShell, Windows Subsystem for Linux (WSL), Git Bash, or<a data-click-id=\"hgr-post-content-link-au-tutorials-how-to-use-putty-ssh\" aria-label=\"How to use putty ssh\" href=\"\/au\/tutorials\/how-to-use-putty-ssh\/\" data-wpel-link=\"internal\" rel=\"follow\"> <\/a><a data-click-id=\"hgr-post-content-link-putty-for-ssh\" href=\"\/au\/tutorials\/how-to-use-putty-ssh\/\" data-wpel-link=\"internal\" rel=\"follow\">PuTTY for SSH<\/a>.<\/li>\n\n\n\n<li><strong>Your remote server&rsquo;s username and IP address.<\/strong> You use both to copy the public key to the server and to test the login.<\/li>\n\n\n\n<li><strong>Initial access to your server.<\/strong> Log in with a password, open the console, or add the key in hPanel before you turn off password authentication.<\/li>\n<\/ul><p class=\"wp-block-paragraph\"><\/p><p class=\"wp-block-paragraph\"> You also need permission to edit the server&rsquo;s SSH configuration if you plan to disable password authentication after setting up SSH keys.<\/p><p class=\"wp-block-paragraph\">    <div class=\"announcement-block announcement-block--warning\">\n        <span class=\"announcement-block__heading\">\n            <svg width=\"24\" height=\"26\" viewBox=\"0 0 24 26\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                d=\"M12 23.5C17.799 23.5 22.5 18.799 22.5 13C22.5 7.20101 17.799 2.5 12 2.5C6.20101 2.5 1.5 7.20101 1.5 13C1.5 18.799 6.20101 23.5 12 23.5ZM13.637 8.65198C13.637 7.74791 12.9041 7.01501 12 7.01501C11.0959 7.01501 10.363 7.74791 10.363 8.65198C10.5335 10.5375 10.875 14.383 10.875 14.383C10.875 15.0043 11.3787 15.508 12 15.508C12.6213 15.508 13.125 15.0043 13.125 14.383V14.38L13.637 8.65198ZM11.9927 16.714C11.3714 16.714 10.8677 17.2177 10.8677 17.839C10.8677 18.4603 11.3714 18.964 11.9927 18.964H12.0073C12.6286 18.964 13.1323 18.4603 13.1323 17.839C13.1323 17.2177 12.6286 16.714 12.0073 16.714H11.9927Z\"\n                fill=\"#BE1025\"\/>\n            <\/svg>\n            Warning        <\/span>\n        <p class=\"announcement-block__content\">\n            Keep your current SSH session open while changing authentication settings. You could lock yourself out of the server if the new key doesn't work and you've already closed your only session.        <\/p>\n    <\/div>\n\n    <\/p><h2 class=\"wp-block-heading h-t-title-2\" id=\"h-how-to-set-up-ssh-keys-step-by-step\">How to set up SSH keys step by step<\/h2><p class=\"wp-block-paragraph\">SSH key setup requires five steps, starting with key pair generation and ending with disabling password authentication once key-based login is confirmed.<\/p><h3 class=\"wp-block-heading h-t-title-3\">1. Generate an SSH key pair<\/h3><p class=\"wp-block-paragraph\">SSH key generation creates two files: a private key and a public key. Generate an Ed25519 key. It&rsquo;s the recommended algorithm: a 256-bit key, supported on current macOS, Linux, and Windows OpenSSH.<\/p><p class=\"wp-block-paragraph\"> Use RSA with a 4096-bit key size instead if your server or client is older and doesn&rsquo;t support Ed25519<\/p><p class=\"wp-block-paragraph\">Open your terminal and run:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ssh-keygen -t ed25519<\/pre><div class=\"wp-block-image wp-block-image aligncenter size-large\"><figure class=\"wp-lightbox-container\" data-wp-context='{\"imageId\":\"6ae78a6e9ced8\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6ae78a6e9ced8\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2026\/10\/1793143123800-0.png\/public\" alt=\"Terminal output of the ssh-keygen command showing a generated Ed25519 key pair, including the fingerprint and randomart image.\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" data-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.thisImage.buttonRight\" data-wp-style--top=\"state.thisImage.buttonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p class=\"wp-block-paragraph\">For RSA, use:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ssh-keygen -t rsa -b 4096<\/pre><p class=\"wp-block-paragraph\">The rest of this tutorial uses Ed25519 file names. Substitute <strong>id_rsa<\/strong> wherever you see <strong>id_ed25519<\/strong> if you generated an RSA key.<\/p><p class=\"wp-block-paragraph\">You can also add a comment to label the key &ndash; useful when managing multiple keys for different servers or accounts:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ssh-keygen -t ed25519 -C \"your-label\"<\/pre><p class=\"wp-block-paragraph\">Replace <strong>your-label<\/strong> with something identifiable, like a server name or project name.<\/p><p class=\"wp-block-paragraph\"><div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                PuTTY uses its own key format and generator. Follow our guide to<a data-click-id=\"hgr-post-content-link-generate-ssh-keys-with-putty\" data-wpel-link=\"internal\" href=\"\/au\/tutorials\/how-to-generate-ssh-keys-on-putty\/\" rel=\"follow\"> generate SSH keys with PuTTY<\/a> instead.\n            <\/p><\/div><\/p><h3 class=\"wp-block-heading h-t-title-3\">2. Choose the key location and add a passphrase<\/h3><p class=\"wp-block-paragraph\">After running <strong>ssh-keygen<\/strong>, the command asks where to save the key:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Enter file in which to save the key (\/home\/username\/.ssh\/id_ed25519):<\/pre><p class=\"wp-block-paragraph\">Press <strong>Enter<\/strong> to accept the path. On macOS the default is <strong>\/Users\/username\/.ssh\/id_ed25519<\/strong>. On Windows OpenSSH it is <strong>C:Usersusername.sshid_ed25519<\/strong>. Type a custom path only when you keep more than one key.<\/p><p class=\"wp-block-paragraph\">    <div class=\"announcement-block announcement-block--warning\">\n        <span class=\"announcement-block__heading\">\n            <svg width=\"24\" height=\"26\" viewBox=\"0 0 24 26\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                d=\"M12 23.5C17.799 23.5 22.5 18.799 22.5 13C22.5 7.20101 17.799 2.5 12 2.5C6.20101 2.5 1.5 7.20101 1.5 13C1.5 18.799 6.20101 23.5 12 23.5ZM13.637 8.65198C13.637 7.74791 12.9041 7.01501 12 7.01501C11.0959 7.01501 10.363 7.74791 10.363 8.65198C10.5335 10.5375 10.875 14.383 10.875 14.383C10.875 15.0043 11.3787 15.508 12 15.508C12.6213 15.508 13.125 15.0043 13.125 14.383V14.38L13.637 8.65198ZM11.9927 16.714C11.3714 16.714 10.8677 17.2177 10.8677 17.839C10.8677 18.4603 11.3714 18.964 11.9927 18.964H12.0073C12.6286 18.964 13.1323 18.4603 13.1323 17.839C13.1323 17.2177 12.6286 16.714 12.0073 16.714H11.9927Z\"\n                fill=\"#BE1025\"\/>\n            <\/svg>\n            Warning        <\/span>\n        <p class=\"announcement-block__content\">\n            If that file already exists, ssh-keygen asks Overwrite (y\/n)?. It overwrites the key only if you type <strong>y<\/strong>. Type <strong>n<\/strong> unless the existing key is no longer in use.        <\/p>\n    <\/div>\n\n    <\/p><p class=\"wp-block-paragraph\">Next, the command prompts for a passphrase:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Enter passphrase (leave empty for no passphrase):<\/pre><p class=\"wp-block-paragraph\">A passphrase is optional, but strongly recommended. It encrypts the private key on disk, so if someone gains access to your machine, they still can&rsquo;t use the key without knowing your passphrase. <\/p><p class=\"wp-block-paragraph\">Choose something long and unique. A short phrase or a mix of unrelated words works well.<\/p><p class=\"wp-block-paragraph\">Enter the passphrase twice to confirm. The command outputs a fingerprint and random art image confirming the key was created.<\/p><p class=\"wp-block-paragraph\">Your two key files are now saved in the specified location. The public key has a <strong>.pub<\/strong> extension &ndash; for example, <strong>id_ed25519.pub<\/strong>. The private key has no extension.<\/p><h3 class=\"wp-block-heading h-t-title-3\">3. Copy the public key to the remote server<\/h3><p class=\"wp-block-paragraph\">The public key has to be on the server for SSH key authentication to work. The server uses it to verify that your machine holds the matching private key. Only the public key goes to the server &ndash; never copy your private key file.<\/p><p class=\"wp-block-paragraph\">There are three ways to do this.<\/p><p class=\"wp-block-paragraph\"><strong>Option 1: Add the key through hPanel<\/strong><\/p><p class=\"wp-block-paragraph\">Hostinger VPS users can add the public key directly through Hostinger dashboard:<\/p><ol class=\"wp-block-list\">\n<li>Open the <strong>id_ed25519.pub<\/strong> file in a text editor and copy its contents.<\/li>\n\n\n\n<li>Log in to Hostinger dashboard and go to <strong>VPS<\/strong> &rarr; your server &rarr; <strong>Settings<\/strong> &rarr; <strong>SSH keys<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image wp-block-image aligncenter size-large\"><figure class=\"wp-lightbox-container\" data-wp-context='{\"imageId\":\"6ae78a6e9df5e\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6ae78a6e9df5e\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2026\/10\/1793143130291-0.png\/public\" alt=\"The SSH keys tab under VPS Settings in hPanel, showing the option to add an SSH key to the account.\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" data-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.thisImage.buttonRight\" data-wp-style--top=\"state.thisImage.buttonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><ol start=\"3\" class=\"wp-block-list\">\n<li>Click <strong>+ SSH key<\/strong>, paste the public key into the <strong>SSH key content<\/strong> field, then click <strong>Save<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image wp-block-image aligncenter size-large\"><figure class=\"wp-lightbox-container\" data-wp-context='{\"imageId\":\"6ae78a6e9e91e\"}' data-wp-interactive=\"core\/image\" data-wp-key=\"6ae78a6e9e91e\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2026\/10\/1793143135232-0.png\/public\" alt=\"The Add SSH Key form in hPanel showing the SSH key content field where users paste their public key.\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" data-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on--click=\"actions.showLightbox\" data-wp-style--right=\"state.thisImage.buttonRight\" data-wp-style--top=\"state.thisImage.buttonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p class=\"wp-block-paragraph\">Want to see this key generation and hPanel setup in action, across Linux, macOS, and Windows? This video also covers managing multiple SSH keys with an SSH agent.<\/p><figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"How to Create &amp; Add SSH Keys on Any OS | Secure Your VPS\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/mdN3jKk2jg0?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure><p>\n  <div class=\"youtube-shortcode\">\n    <div class=\"row\">\n      <div class=\"col-7 col-sm-8 d-flex align-items-center\">\n        <img decoding=\"async\" class=\"channel-logo\" src=\"https:\/\/www.hostinger.com\/au\/tutorials\/wp-content\/themes\/tutorialsthemeuplift\/public\/images\/youtube-channels\/hostinger-academy.jpg\" alt=\"youtube channel logo\">\n        <div class=\"d-flex flex-column justify-content-between\">\n          <span class=\"slogan d-none d-sm-block\">Subscribe For more educational videos!<\/span>\n          <span class=\"channel-name\">Hostinger Academy<\/span>\n                    <\/div>\n      <\/div>\n      <div class=\"col-5 col-sm-4 d-flex align-items-center justify-content-end\">\n          <a data-click-id=\"hgr-post-content-link-subscribe\" class=\"subscribe-button\" target=\"_blank\" rel=\"nofollow noopener noreferrer\" href=\"http:\/\/www.youtube.com\/channel\/UCbNIC-svDbtUOH2qsLnPQPg?sub_confirmation=1\">\n            <img decoding=\"async\" src=\"https:\/\/www.hostinger.com\/au\/tutorials\/wp-content\/themes\/tutorialsthemeuplift\/public\/images\/icons\/youtube.svg\" alt=\"subscribe\">\n            <span>Subscribe<\/span>\n          <\/a>\n      <\/div>\n    <\/div>\n  <\/div>\n\n    \n\n\n<figure class=\"wp-block-image size-large\"><a data-click-id=\"hgr-post-content-link-au-vps-hosting\" aria-label=\"Vps hosting\" class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/au\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-77934\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<\/p><p class=\"wp-block-paragraph\"><strong>Option 2: Use ssh-copy-id<\/strong><\/p><p class=\"wp-block-paragraph\"><strong>ssh-copy-id<\/strong> copies the public key to the server automatically, enabling<a data-click-id=\"hgr-post-content-link-au-tutorials-how-to-setup-passwordless-ssh\" aria-label=\"How to setup passwordless ssh\" href=\"\/au\/tutorials\/how-to-setup-passwordless-ssh\/\" data-wpel-link=\"internal\" rel=\"follow\"> <\/a><a data-click-id=\"hgr-post-content-link-passwordless-ssh-login\" href=\"\/au\/tutorials\/how-to-setup-passwordless-ssh\/\" data-wpel-link=\"internal\" rel=\"follow\">passwordless SSH login<\/a> over an existing password connection:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ssh-copy-id username@192.0.2.1<\/pre><p class=\"wp-block-paragraph\">Replace <strong>username<\/strong> with your server username and <strong>192.0.2.1<\/strong> with your server&rsquo;s IP address. Enter your password when prompted. A successful transfer shows:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Number of key(s) added: 1<\/pre><p class=\"wp-block-paragraph\"><strong>Option 3: Add the key manually<\/strong><\/p><p class=\"wp-block-paragraph\">Log in to the server with your password and add the public key manually if <strong>ssh-copy-id<\/strong> isn&rsquo;t available:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mkdir -p ~\/.ssh chmod 700 ~\/.ssh echo \"your-public-key-content\" &gt;&gt; ~\/.ssh\/authorized_keys chmod 600 ~\/.ssh\/authorized_keys<\/pre><p class=\"wp-block-paragraph\">Replace <strong>your-public-key-content<\/strong> with the full contents of your <strong>.pub<\/strong> file.<\/p><h3 class=\"wp-block-heading h-t-title-3\">4. Test SSH key authentication<\/h3><p class=\"wp-block-paragraph\">Test the connection before making any other changes to your server&rsquo;s SSH settings:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ssh username@192.0.2.1<\/pre><p class=\"wp-block-paragraph\">A successful login ends at the server shell prompt. When you set a passphrase, SSH asks for that passphrase first, then opens the shell. A server password prompt could mean key authentication didn&rsquo;t work.<\/p><p class=\"wp-block-paragraph\">When the server still asks for a password, these are four common reasons:<\/p><ul class=\"wp-block-list\">\n<li>You didn&rsquo;t add the public key to the correct user account on the server.<\/li>\n\n\n\n<li>You used the wrong private key locally.<\/li>\n\n\n\n<li>Password authentication is still active as a fallback.<\/li>\n\n\n\n<li>File permissions on <strong>~\/.ssh<\/strong> or <strong>authorized_keys<\/strong> are too open.<\/li>\n<\/ul><p class=\"wp-block-paragraph\">Check these before you proceed to the next step. A &ldquo;Permission denied&rdquo; error or persistent password prompt usually points to a misconfigured <strong>authorized_keys<\/strong> file or incorrect file permissions on the server.<\/p><h3 class=\"wp-block-heading h-t-title-3\">5. Disable password authentication after SSH keys work<\/h3><p class=\"wp-block-paragraph\">Once SSH key login is confirmed, you can <a data-click-id=\"hgr-post-content-link-disable-ssh-password-authentication\" href=\"\/au\/tutorials\/how-to-disable-ssh-password-login-on-vps\/\" data-wpel-link=\"internal\" rel=\"follow\">disable SSH password authentication<\/a> to close password logins, so brute-force and credential-stuffing attacks have no password to guess.<\/p><p class=\"wp-block-paragraph\">    <div class=\"announcement-block announcement-block--warning\">\n        <span class=\"announcement-block__heading\">\n            <svg width=\"24\" height=\"26\" viewBox=\"0 0 24 26\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                d=\"M12 23.5C17.799 23.5 22.5 18.799 22.5 13C22.5 7.20101 17.799 2.5 12 2.5C6.20101 2.5 1.5 7.20101 1.5 13C1.5 18.799 6.20101 23.5 12 23.5ZM13.637 8.65198C13.637 7.74791 12.9041 7.01501 12 7.01501C11.0959 7.01501 10.363 7.74791 10.363 8.65198C10.5335 10.5375 10.875 14.383 10.875 14.383C10.875 15.0043 11.3787 15.508 12 15.508C12.6213 15.508 13.125 15.0043 13.125 14.383V14.38L13.637 8.65198ZM11.9927 16.714C11.3714 16.714 10.8677 17.2177 10.8677 17.839C10.8677 18.4603 11.3714 18.964 11.9927 18.964H12.0073C12.6286 18.964 13.1323 18.4603 13.1323 17.839C13.1323 17.2177 12.6286 16.714 12.0073 16.714H11.9927Z\"\n                fill=\"#BE1025\"\/>\n            <\/svg>\n            Warning        <\/span>\n        <p class=\"announcement-block__content\">\n            Only do this after testing SSH key login in a separate session. You'll lose access to the server. Keep at least one active SSH session open as a safety net if you disable password authentication and your key doesn't work.        <\/p>\n    <\/div>\n\n     <\/p><p class=\"wp-block-paragraph\">The process involves editing the <strong>sshd_config<\/strong> file on your server, setting <strong>PasswordAuthentication<\/strong> to <strong>no<\/strong>, and reloading the SSH service to apply the change.<\/p><h2 class=\"wp-block-heading h-t-title-2\" id=\"h-how-to-manage-ssh-keys-securely\">How to manage SSH keys securely<\/h2><p class=\"wp-block-paragraph\">SSH key management covers three areas: how to keep passphrases accessible without retyping them, how to organize multiple keys across servers, and how to respond when a key is lost or compromised.<\/p><h3 class=\"wp-block-heading h-t-title-3\">Use ssh-agent to manage passphrase-protected keys<\/h3><p class=\"wp-block-paragraph\"><strong>ssh-agent<\/strong> runs in the background and stores your unlocked private keys for the duration of a session. Once you add a key to the agent, you don&rsquo;t need to enter the passphrase every time you connect to a server.<\/p><p class=\"wp-block-paragraph\">To start the agent and add a key:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">eval \"$(ssh-agent -s)\" ssh-add ~\/.ssh\/id_ed25519<\/pre><p class=\"wp-block-paragraph\">Replace <strong>~\/.ssh\/id_ed25519<\/strong> with your private key path if it differs. To confirm the key was added:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ssh-add -l<\/pre><p class=\"wp-block-paragraph\">This lists all identities currently held by the agent.<\/p><p class=\"wp-block-paragraph\">Those commands above work on any Linux distribution. For other operating systems:<\/p><ul class=\"wp-block-list\">\n<li><strong>macOS.<\/strong> Integrates with Keychain &ndash; add <strong>&ndash;apple-use-keychain<\/strong> to the <strong>ssh-add<\/strong> command to persist the passphrase across reboots.<\/li>\n\n\n\n<li><strong>Windows PuTTY.<\/strong> Users can use Pageant, PuTTY&rsquo;s equivalent key agent, available from the PuTTY downloads page.<\/li>\n<\/ul><h3 class=\"wp-block-heading h-t-title-3\">Use the SSH config file for multiple servers<\/h3><p class=\"wp-block-paragraph\">The SSH config file lets you define connection settings &ndash; server address, username, port, and private key &ndash; for each server in one place. This way, you don&rsquo;t have to type them out each time you connect.<\/p><p class=\"wp-block-paragraph\">The file lives at <strong>~\/.ssh\/config<\/strong>. Here&rsquo;s an example entry:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Host my-server HostName 192.0.2.1 User username IdentityFile ~\/.ssh\/id_ed25519 Port 22<\/pre><p class=\"wp-block-paragraph\">With this in place, <strong>ssh my-server<\/strong> connects using the settings defined above. You can add as many entries as needed, one per server or project.<\/p><p class=\"wp-block-paragraph\">Using a separate key pair for each server is recommended. When one private key is compromised, it only affects the server it&rsquo;s associated with, not every server you manage.<\/p><h3 class=\"wp-block-heading h-t-title-3\">What should you do if an SSH key is lost or compromised?<\/h3><p class=\"wp-block-paragraph\">Remove the public key from every server that has it, then delete the private key and make a new pair. Simply deleting the private key from your local computer isn&rsquo;t enough. Anyone with a copy can still log in.<\/p><p class=\"wp-block-paragraph\">The public key must be removed from every server it was added to. To do this:<\/p><ol class=\"wp-block-list\">\n<li>Remove the affected public key from the server&rsquo;s <strong>authorized_keys<\/strong> file, or delete it through hPanel under <strong>Settings<\/strong> &rarr; <strong>SSH keys<\/strong>.<\/li>\n\n\n\n<li>Delete or quarantine the exposed private key from your local machine.<\/li>\n\n\n\n<li>Generate a new SSH key pair using <strong>ssh-keygen<\/strong>.<\/li>\n\n\n\n<li>Add the new public key to the server through hPanel, <strong>ssh-copy-id<\/strong>, or by editing <strong>authorized_keys<\/strong> manually.<\/li>\n\n\n\n<li>Test the new key to confirm it works before closing your session.<\/li>\n<\/ol><h2 class=\"wp-block-heading h-t-title-2\" id=\"h-how-to-troubleshoot-ssh-key-authentication\">How to troubleshoot SSH key authentication<\/h2><p class=\"wp-block-paragraph\">Match the error to a row below, then run the check in that row. These are the usual causes: wrong permissions, the wrong key, or a configuration change that wasn&rsquo;t applied.<\/p><figure tabindex=\"0\" class=\"wp-block-table\"><table><tbody><tr><td colspan=\"1\" rowspan=\"1\"><p><strong>Issue<\/strong><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><strong>Likely cause<\/strong><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><strong>What to check<\/strong><\/p><\/td><\/tr><tr><td colspan=\"1\" rowspan=\"1\"><p><span>Server still asks for a password<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Public key not installed correctly or password fallback enabled<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Verify the public key is in <\/span><strong>~\/.ssh\/authorized_keys<\/strong><span>&nbsp;on the server<\/span><\/p><\/td><\/tr><tr><td colspan=\"1\" rowspan=\"1\"><p><span>Permission denied error<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Incorrect file permissions on <\/span><strong>~\/.ssh<\/strong><span>&nbsp;or <\/span><strong>authorized_keys<\/strong><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Set <\/span><strong>~\/.ssh<\/strong><span>&nbsp;to <\/span><strong>700<\/strong><span>&nbsp;and <\/span><strong>authorized_keys<\/strong><span>&nbsp;to <\/span><strong>600<\/strong><\/p><\/td><\/tr><tr><td colspan=\"1\" rowspan=\"1\"><p><span>Wrong private key being used<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>SSH client defaulting to a different key<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Use <\/span><strong>ssh -i ~\/.ssh\/id_ed25519 username@192.0.2.1<\/strong><span>&nbsp;to specify the key explicitly<\/span><\/p><\/td><\/tr><tr><td colspan=\"1\" rowspan=\"1\"><p><span>Public key added to wrong user account<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Key added to a different user&rsquo;s <\/span><strong>authorized_keys<\/strong><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Confirm you&rsquo;re connecting with the same username whose <\/span><strong>authorized_keys<\/strong><span>&nbsp;holds the public key<\/span><\/p><\/td><\/tr><tr><td colspan=\"1\" rowspan=\"1\"><p><span>SSH service not reloaded after config changes<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><strong>sshd_config<\/strong><span>&nbsp;changes not applied<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Run <\/span><strong>sudo systemctl reload ssh<\/strong><span>&nbsp;(for Ubuntu\/Debian) or <\/span><strong>sudo systemctl reload sshd<\/strong><span>&nbsp;(for CentOS\/Rocky Linux\/AlmaLinux)<\/span><strong>&nbsp;<\/strong><span>to reload the SSH service<\/span><\/p><\/td><\/tr><tr><td colspan=\"1\" rowspan=\"1\"><p><span>Firewall, port, or IP address issues<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Port 22 blocked or wrong IP used<\/span><\/p><\/td><td colspan=\"1\" rowspan=\"1\"><p><span>Check your firewall rules and confirm the server&rsquo;s IP address and SSH port are correct.<\/span><span><a data-click-id=\"hgr-post-content-link-au-tutorials-ssh-connection-refused\" href=\"\/au\/tutorials\/ssh-connection-refused\/\" data-wpel-link=\"internal\" rel=\"follow\">&nbsp;<\/a><\/span><span><a data-click-id=\"hgr-post-content-link-ssh-connection-refused\" href=\"\/au\/tutorials\/ssh-connection-refused\/\" data-wpel-link=\"internal\" rel=\"follow\">SSH connection refused<\/a><\/span><span>&nbsp;errors often point to a blocked port or incorrect IP<\/span><\/p><\/td><\/tr><\/tbody><\/table><\/figure><h2 class=\"wp-block-heading h-t-title-2\" id=\"h-next-steps-after-setting-up-ssh-keys\">Next steps after setting up SSH keys<\/h2><p class=\"wp-block-paragraph\">Now that you have SSH key authentication in place, your password login is off, and your keys organized, the server connection is secure. SSH key login is set, and the server is ready for daily work. <\/p><p class=\"wp-block-paragraph\">File management, process checks, user permissions, and service settings all happen in the command line, and basic SSH commands cover the ones you use each session.<\/p><p class=\"wp-block-paragraph\">You can learn<a data-click-id=\"hgr-post-content-link-au-tutorials-basic-ssh-commands\" aria-label=\"Basic ssh commands\" href=\"\/au\/tutorials\/basic-ssh-commands\/\" data-wpel-link=\"internal\" rel=\"follow\"> <\/a><a data-click-id=\"hgr-post-content-link-basic-ssh-commands\" href=\"\/au\/tutorials\/basic-ssh-commands\/\" data-wpel-link=\"internal\" rel=\"follow\">basic SSH commands<\/a> to cover the essential operations you&rsquo;ll use for every session. It covers things like navigating directories, transferring files, checking running processes, and managing services.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SSH keys let you authenticate to a remote server using a pair of authentication keys; one public, one private. You use this pair of keys instead of a password to make remote access more secure. It&rsquo;s also faster than typing a password each time. Setting up SSH keys involves five steps: How do SSH keys [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/au\/tutorials\/how-to-set-up-ssh-keys\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":356,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"Learn how to set up SSH keys and manage them effectively","rank_math_description":"Check out this article to learn how to set up SSH keys: 1. Initialize SSH key generation 2. Run the SSH-keygen command + more.","rank_math_focus_keyword":"how to set up ssh keys","footnotes":""},"categories":[22670],"tags":[],"class_list":["post-646","post","type-post","status-publish","format-standard","hentry","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-set-up-ssh-keys","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/como-configurar-chaves-ssh\/","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/generer-cle-ssh\/","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/como-configurar-claves-ssh","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-menggunakan-ssh-keys\/","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-set-up-ssh-keys","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-set-up-ssh-keys","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-set-up-ssh-keys","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-set-up-ssh-keys","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-set-up-ssh-keys","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-set-up-ssh-keys","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-set-up-ssh-keys","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/como-configurar-claves-ssh","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/como-configurar-claves-ssh","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/como-configurar-claves-ssh","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/como-configurar-chaves-ssh\/","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/au\/tutorials\/wp-json\/wp\/v2\/posts\/646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/au\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/au\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/au\/tutorials\/wp-json\/wp\/v2\/users\/356"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/au\/tutorials\/wp-json\/wp\/v2\/comments?post=646"}],"version-history":[{"count":34,"href":"https:\/\/www.hostinger.com\/au\/tutorials\/wp-json\/wp\/v2\/posts\/646\/revisions"}],"predecessor-version":[{"id":151724,"href":"https:\/\/www.hostinger.com\/au\/tutorials\/wp-json\/wp\/v2\/posts\/646\/revisions\/151724"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/au\/tutorials\/wp-json\/wp\/v2\/media?parent=646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/au\/tutorials\/wp-json\/wp\/v2\/categories?post=646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/au\/tutorials\/wp-json\/wp\/v2\/tags?post=646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}