How to recover deleted .ssh/known_host entry?












0














I created a droplet (basically a server) to host a website on DigitalOcean. I connected to it using openssh on my computer, and it was working fine. Then I decided to delete the 3rd out of 3 entries inside of the ~/.ssh/known_hosts file (I'm, not sure why I did this).



Now when I try to connect to the droplet using ssh username@ipaddress it returns an error: username@ipaddress Permission denied (publickey). Is there a way to obtain the history of the known_hosts file? Maybe I need to copy-paste my public key somewhere?



Conclusion: delete server and start all over










share|improve this question





























    0














    I created a droplet (basically a server) to host a website on DigitalOcean. I connected to it using openssh on my computer, and it was working fine. Then I decided to delete the 3rd out of 3 entries inside of the ~/.ssh/known_hosts file (I'm, not sure why I did this).



    Now when I try to connect to the droplet using ssh username@ipaddress it returns an error: username@ipaddress Permission denied (publickey). Is there a way to obtain the history of the known_hosts file? Maybe I need to copy-paste my public key somewhere?



    Conclusion: delete server and start all over










    share|improve this question



























      0












      0








      0







      I created a droplet (basically a server) to host a website on DigitalOcean. I connected to it using openssh on my computer, and it was working fine. Then I decided to delete the 3rd out of 3 entries inside of the ~/.ssh/known_hosts file (I'm, not sure why I did this).



      Now when I try to connect to the droplet using ssh username@ipaddress it returns an error: username@ipaddress Permission denied (publickey). Is there a way to obtain the history of the known_hosts file? Maybe I need to copy-paste my public key somewhere?



      Conclusion: delete server and start all over










      share|improve this question















      I created a droplet (basically a server) to host a website on DigitalOcean. I connected to it using openssh on my computer, and it was working fine. Then I decided to delete the 3rd out of 3 entries inside of the ~/.ssh/known_hosts file (I'm, not sure why I did this).



      Now when I try to connect to the droplet using ssh username@ipaddress it returns an error: username@ipaddress Permission denied (publickey). Is there a way to obtain the history of the known_hosts file? Maybe I need to copy-paste my public key somewhere?



      Conclusion: delete server and start all over







      server 18.04 permissions ssh openssh






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 16 at 15:06

























      asked Dec 16 at 14:16









      JTizzle

      12




      12






















          1 Answer
          1






          active

          oldest

          votes


















          4















          Now when I try to connect to the droplet using ssh username@ipaddress it returns an error: username@ipaddress Permission denied (publickey). Is there a way to obtain the history of the known_hosts file? Maybe I need to copy-paste my public key somewhere?




          known_hosts keep a history of the public server keys your client has seen. It is used to protect against a man in the middle-attack, as that would lead to a changed remote public key.



          It is thus used to authenticate the server to the client, not the opposite way. If you connect to an unknown host, you will be prompted if you want to trust the key or not.



          You deleting lines in known_hosts is not the reason why you get permission denied when you try to connect using a keypair. Run ssh -vvv user@host to get more information about why you get connection denied.






          share|improve this answer





















          • You might be correct, but I assumed since it happened after the case that it was the problem. It attempts 'trying private key' 3 times but fails because of 'No such file or directory'. From what I know about keys, it should try id_rsa against the id_rsa.public on the server, but it doesn't. Any ideas?
            – JTizzle
            Dec 16 at 14:36












          • The key should be added to ~/.ssh/authorized_keys on the server.
            – vidarlo
            Dec 16 at 14:38










          • The key is in there, yes. But the ssh -vvv makes it look like the private key version of the authorized key in the server wasn't used in 'Trying private key'.
            – JTizzle
            Dec 16 at 14:42













          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1102327%2fhow-to-recover-deleted-ssh-known-host-entry%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4















          Now when I try to connect to the droplet using ssh username@ipaddress it returns an error: username@ipaddress Permission denied (publickey). Is there a way to obtain the history of the known_hosts file? Maybe I need to copy-paste my public key somewhere?




          known_hosts keep a history of the public server keys your client has seen. It is used to protect against a man in the middle-attack, as that would lead to a changed remote public key.



          It is thus used to authenticate the server to the client, not the opposite way. If you connect to an unknown host, you will be prompted if you want to trust the key or not.



          You deleting lines in known_hosts is not the reason why you get permission denied when you try to connect using a keypair. Run ssh -vvv user@host to get more information about why you get connection denied.






          share|improve this answer





















          • You might be correct, but I assumed since it happened after the case that it was the problem. It attempts 'trying private key' 3 times but fails because of 'No such file or directory'. From what I know about keys, it should try id_rsa against the id_rsa.public on the server, but it doesn't. Any ideas?
            – JTizzle
            Dec 16 at 14:36












          • The key should be added to ~/.ssh/authorized_keys on the server.
            – vidarlo
            Dec 16 at 14:38










          • The key is in there, yes. But the ssh -vvv makes it look like the private key version of the authorized key in the server wasn't used in 'Trying private key'.
            – JTizzle
            Dec 16 at 14:42


















          4















          Now when I try to connect to the droplet using ssh username@ipaddress it returns an error: username@ipaddress Permission denied (publickey). Is there a way to obtain the history of the known_hosts file? Maybe I need to copy-paste my public key somewhere?




          known_hosts keep a history of the public server keys your client has seen. It is used to protect against a man in the middle-attack, as that would lead to a changed remote public key.



          It is thus used to authenticate the server to the client, not the opposite way. If you connect to an unknown host, you will be prompted if you want to trust the key or not.



          You deleting lines in known_hosts is not the reason why you get permission denied when you try to connect using a keypair. Run ssh -vvv user@host to get more information about why you get connection denied.






          share|improve this answer





















          • You might be correct, but I assumed since it happened after the case that it was the problem. It attempts 'trying private key' 3 times but fails because of 'No such file or directory'. From what I know about keys, it should try id_rsa against the id_rsa.public on the server, but it doesn't. Any ideas?
            – JTizzle
            Dec 16 at 14:36












          • The key should be added to ~/.ssh/authorized_keys on the server.
            – vidarlo
            Dec 16 at 14:38










          • The key is in there, yes. But the ssh -vvv makes it look like the private key version of the authorized key in the server wasn't used in 'Trying private key'.
            – JTizzle
            Dec 16 at 14:42
















          4












          4








          4







          Now when I try to connect to the droplet using ssh username@ipaddress it returns an error: username@ipaddress Permission denied (publickey). Is there a way to obtain the history of the known_hosts file? Maybe I need to copy-paste my public key somewhere?




          known_hosts keep a history of the public server keys your client has seen. It is used to protect against a man in the middle-attack, as that would lead to a changed remote public key.



          It is thus used to authenticate the server to the client, not the opposite way. If you connect to an unknown host, you will be prompted if you want to trust the key or not.



          You deleting lines in known_hosts is not the reason why you get permission denied when you try to connect using a keypair. Run ssh -vvv user@host to get more information about why you get connection denied.






          share|improve this answer













          Now when I try to connect to the droplet using ssh username@ipaddress it returns an error: username@ipaddress Permission denied (publickey). Is there a way to obtain the history of the known_hosts file? Maybe I need to copy-paste my public key somewhere?




          known_hosts keep a history of the public server keys your client has seen. It is used to protect against a man in the middle-attack, as that would lead to a changed remote public key.



          It is thus used to authenticate the server to the client, not the opposite way. If you connect to an unknown host, you will be prompted if you want to trust the key or not.



          You deleting lines in known_hosts is not the reason why you get permission denied when you try to connect using a keypair. Run ssh -vvv user@host to get more information about why you get connection denied.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 16 at 14:20









          vidarlo

          8,99342442




          8,99342442












          • You might be correct, but I assumed since it happened after the case that it was the problem. It attempts 'trying private key' 3 times but fails because of 'No such file or directory'. From what I know about keys, it should try id_rsa against the id_rsa.public on the server, but it doesn't. Any ideas?
            – JTizzle
            Dec 16 at 14:36












          • The key should be added to ~/.ssh/authorized_keys on the server.
            – vidarlo
            Dec 16 at 14:38










          • The key is in there, yes. But the ssh -vvv makes it look like the private key version of the authorized key in the server wasn't used in 'Trying private key'.
            – JTizzle
            Dec 16 at 14:42




















          • You might be correct, but I assumed since it happened after the case that it was the problem. It attempts 'trying private key' 3 times but fails because of 'No such file or directory'. From what I know about keys, it should try id_rsa against the id_rsa.public on the server, but it doesn't. Any ideas?
            – JTizzle
            Dec 16 at 14:36












          • The key should be added to ~/.ssh/authorized_keys on the server.
            – vidarlo
            Dec 16 at 14:38










          • The key is in there, yes. But the ssh -vvv makes it look like the private key version of the authorized key in the server wasn't used in 'Trying private key'.
            – JTizzle
            Dec 16 at 14:42


















          You might be correct, but I assumed since it happened after the case that it was the problem. It attempts 'trying private key' 3 times but fails because of 'No such file or directory'. From what I know about keys, it should try id_rsa against the id_rsa.public on the server, but it doesn't. Any ideas?
          – JTizzle
          Dec 16 at 14:36






          You might be correct, but I assumed since it happened after the case that it was the problem. It attempts 'trying private key' 3 times but fails because of 'No such file or directory'. From what I know about keys, it should try id_rsa against the id_rsa.public on the server, but it doesn't. Any ideas?
          – JTizzle
          Dec 16 at 14:36














          The key should be added to ~/.ssh/authorized_keys on the server.
          – vidarlo
          Dec 16 at 14:38




          The key should be added to ~/.ssh/authorized_keys on the server.
          – vidarlo
          Dec 16 at 14:38












          The key is in there, yes. But the ssh -vvv makes it look like the private key version of the authorized key in the server wasn't used in 'Trying private key'.
          – JTizzle
          Dec 16 at 14:42






          The key is in there, yes. But the ssh -vvv makes it look like the private key version of the authorized key in the server wasn't used in 'Trying private key'.
          – JTizzle
          Dec 16 at 14:42




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Ask Ubuntu!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1102327%2fhow-to-recover-deleted-ssh-known-host-entry%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

          Mangá

           ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕