{"id":18111,"date":"2022-08-18T06:26:52","date_gmt":"2022-08-18T06:26:52","guid":{"rendered":"https:\/\/linuxways.net\/?p=18111"},"modified":"2022-09-05T16:52:18","modified_gmt":"2022-09-05T16:52:18","slug":"how-to-fi-ssh-permission-denied","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/how-to-fi-ssh-permission-denied\/","title":{"rendered":"How to Fi SSH Permission Denied"},"content":{"rendered":"<h2><strong>How to Fix ssh Permission Denied<\/strong><\/h2>\n<p>Working with SSH is time-saving and secure but can get frustrating when you get the ssh permission denied error and can\u2019t figure out what is causing the error.<\/p>\n<p>With ssh, you can easily login into your remote server and perform all activities, including installing software and working with files.<\/p>\n<p>If you\u2019ve installed SSH on your client and server but still have issues accessing the server, the problems result from the configurations in most cases. Few rules need to be in check for the smooth running of SSH. This guide covers how you can easily fix the SSH error in several ways.<\/p>\n<h2><strong>What Is SSH?<\/strong><\/h2>\n<p>Secure Shell (SSH) is a protocol that allows a client machine to connect to a Linux server remotely and securely using a text-based interface. Upon a successful connection, a shell session will open from where you can work with your server.<\/p>\n<h2><strong>What Causes the ssh Permission Denied Error?<\/strong><\/h2>\n<p>The common reasons include:<\/p>\n<ul>\n<li>Incorrect SSH public key contained in the <strong>authorized_keys <\/strong>file<\/li>\n<li>Incorrect file permissions<\/li>\n<li>Misconfiguration in the SSH server config file<\/li>\n<\/ul>\n<p>Fixing the error is straightforward and we will consider various methods you can use.<\/p>\n<h2><strong>How to Resolve the SSH Permission Denied Error<\/strong><\/h2>\n<p>If you get an error like the one below, we have a solution for it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"134\" class=\"wp-image-18132\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-1.png 786w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-1-300x51.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-1-768x131.png 768w\" sizes=\"auto, (max-width: 786px) 100vw, 786px\" \/><\/p>\n<h3><strong>Solution 1: Enable Password Authentication<\/strong><\/h3>\n<p>You first need to check the <strong>PasswordAuthentication <\/strong>and ensure it is enabled.<\/p>\n<p>You need to open the <strong>sshd_config<\/strong> file on your server using an editor. In our case, we are using nano editor and the command would be:<\/p>\n<pre>$ sudo nano \/etc\/ssh\/sshd_config<\/pre>\n<p>Once opened, locate the <strong>PasswordAuthentication <\/strong>line and ensure it is set to end with <strong>yes.<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"734\" height=\"277\" class=\"wp-image-18135\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-2.png 734w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-2-300x113.png 300w\" sizes=\"auto, (max-width: 734px) 100vw, 734px\" \/><\/p>\n<p>Also, below the PasswordAuthentication, ensure the <strong>ChallengeResponseAuthentication <\/strong>is disabled and ends with a <strong>no.<\/strong><\/p>\n<p>Once you make the changes, save your file and exit. You must restart the ssh service using the command below.<\/p>\n<pre>$ sudo systemctl restart sshd.service<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"123\" class=\"wp-image-18140\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-3.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-3-300x50.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<p>Next, proceed to try the connection again.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"333\" class=\"wp-image-18144\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-4.png 732w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-4-300x136.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/p>\n<p>If the solution doesn\u2019t work for you, try the others below.<\/p>\n<h3><strong>Solution 2. Check Other Configurations<\/strong><\/h3>\n<p>Your sshd_configuration file determines if the ssh connection goes through or not. Therefore, everything needs to be checked to fix the ssh permission denied error. For this solution, you must locate various lines and ensure they match the ones listed below.<\/p>\n<p>First, open the configuration file as we did before.<\/p>\n<pre>$ sudo nano \/etc\/ssh\/sshd_config<\/pre>\n<p>Once opened, locate and edit the lines below to ensure they match. Most of them are commented but you can un-comment them by deleting the # before them. From there, you can edit and align them to match the ones below.<\/p>\n<pre>PermitRootLogin no\r\n\r\nPubkeyAuthentication yes\r\n\r\nUsePAM yes<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"333\" class=\"wp-image-18146\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-5.png 732w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-5-300x136.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/p>\n<p>Finally, save and exit the file. Then, restart sshd<\/p>\n<pre>$ sudo systemctl restart sshd.service<\/pre>\n<p>Your ssh connection should now successfully log in to the server.<\/p>\n<h3><strong>Solution 3. Change File Permissions<\/strong><\/h3>\n<p>The owner permissions of your home directory should be set to read, write, and execute. You can verify so using the command below.<\/p>\n<pre>$ ls -ld<\/pre>\n<p>If not set to <strong>drwx&#8212;&#8212;, <\/strong>set them using the <strong>chmod <\/strong>command.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"732\" height=\"115\" class=\"wp-image-18147\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-6.png 732w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/08\/word-image-18111-6-300x47.png 300w\" sizes=\"auto, (max-width: 732px) 100vw, 732px\" \/><\/p>\n<pre>$ chmod 0700 \/home\/your-username<\/pre>\n<p>Also, the owner permissions for the<strong> authorized_keys<\/strong> in the <strong>.ssh <\/strong>directory should be set to read and write.<\/p>\n<p>Verify so using the command below.<\/p>\n<pre>$ ls -ld authorized_keys<\/pre>\n<p>If not properly set, use the command below.<\/p>\n<pre>$ chmod 0600 \/home\/your-username\/ .ssh\/authorized_keys<\/pre>\n<p>Once you restart sshd, your ssh will start connecting normally and will fix the ssh permission denied error.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>SSH is a must-use when working with a remote Linux server. There are other alternatives, but the protocol offers you a secure remote login. While using SSH, you can encounter the permission denied error which mainly results from a misconfiguration. We\u2019ve seen the various options you can use to resolve this and any of them or at least one will work for your case.<\/p>","protected":false},"excerpt":{"rendered":"<p>While using SSH, you can encounter the permission denied error which results from a misconfiguration. The options you can use to resolve this is discussed here.<\/p>","protected":false},"author":104,"featured_media":18161,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-18111","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/104"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=18111"}],"version-history":[{"count":1,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18111\/revisions"}],"predecessor-version":[{"id":18163,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/18111\/revisions\/18163"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/18161"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=18111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=18111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=18111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}