{"id":613,"date":"2025-12-19T17:19:10","date_gmt":"2025-12-19T13:19:10","guid":{"rendered":"https:\/\/hostatto.com\/blog\/?p=613"},"modified":"2025-12-19T18:08:40","modified_gmt":"2025-12-19T14:08:40","slug":"setting-up-ssh-access-on-server-and-logging-in-via-ssh-without-a-password","status":"publish","type":"post","link":"https:\/\/hostatto.com\/blog\/setting-up-ssh-access-on-server-and-logging-in-via-ssh-without-a-password.html","title":{"rendered":"Setting up SSH access on server and logging in via SSH without a password"},"content":{"rendered":"<p>On your local computer, in your home directory, find the <strong>.ssh<\/strong> folder, if it doesn't exist, create it.<\/p>\n<blockquote><p>mkdir ~\/.ssh<\/p><\/blockquote>\n<p>For the first login via SSH, we write in the terminal<\/p>\n<blockquote><p>ssh username@your.ip.address\n<\/p><\/blockquote>\n<p>When a question appears, do this:<\/p>\n<blockquote><p>Are you sure you want to continue connecting (yes\/no\/[fingerprint])? <strong>yes<\/strong>\n<\/p><\/blockquote>\n<p>Be sure to answer <strong>yes<\/strong> not <strong>y<\/strong><\/p>\n<p><strong>After this:<\/strong><br \/>\nThe key will be saved in ~\/.ssh\/known_hosts<br \/>\nSSH will ask for the user's password.<\/p>\n<p>Now, to log in via SSH without a password on the local machine, we create a key in the <strong>.ssh<\/strong> directory<\/p>\n<blockquote><p>ssh-keygen -t rsa -b 4096 -a 100<\/p><\/blockquote>\n<p>You can protect your SSH key with a passphrase at the next prompt. This is recommended for added security.<\/p>\n<blockquote><p>~\/.ssh\/id_rsa<br \/>\n~\/.ssh\/id_rsa.pub\n<\/p><\/blockquote>\n<p>We copy these keys to the server<\/p>\n<blockquote><p>ssh-copy-id username@your.ip.address\n<\/p><\/blockquote>\n<p>Enter your password one last time.<br \/>\nDone. The key has been added to<\/p>\n<blockquote><p>\/home\/username\/.ssh\/authorized_keys\n<\/p><\/blockquote>\n<p>Close the connection:<\/p>\n<blockquote><p>exit<\/p><\/blockquote>\n<p>Let's connect again<\/p>\n<blockquote><p>ssh username@your.ip.address\n<\/p><\/blockquote>\n<p>If it doesn't ask for a password, everything works.<\/p>\n<p>Strengthening Security (Highly Recommended)<br \/>\nOpen the file on the server<\/p>\n<blockquote><p>sudo nano \/etc\/ssh\/sshd_config\n<\/p><\/blockquote>\n<p>And add<\/p>\n<blockquote><p>PasswordAuthentication no<br \/>\nPubkeyAuthentication yes<br \/>\nChallengeResponseAuthentication no\n<\/p><\/blockquote>\n<p>If you want to disable root login add <\/p>\n<blockquote><p>PermitRootLogin no\n<\/p><\/blockquote>\n<p>Now let's close the current session<\/p>\n<blockquote><p>sudo systemctl restart ssh\n<\/p><\/blockquote>\n<p>Login summary<\/p>\n<p>\u2714\ufe0f SSH key only<\/p>\n<p>\u274c Password disabled<\/p>\n<p>\u274c Rooting via SSH is prohibited<\/p>\n<p>\u2714\ufe0f Rooting is available via:<\/p>\n<blockquote><p>sudo -i\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>...<\/p>\n","protected":false},"author":1,"featured_media":506,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[78,77,79],"class_list":["post-613","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-ovh","tag-ssh","tag-vps"],"_links":{"self":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/posts\/613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/comments?post=613"}],"version-history":[{"count":0,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/posts\/613\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/media\/506"}],"wp:attachment":[{"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/media?parent=613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/categories?post=613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostatto.com\/blog\/wp-json\/wp\/v2\/tags?post=613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}