{"id":3402,"date":"2023-07-28T10:25:19","date_gmt":"2023-07-28T10:25:19","guid":{"rendered":"https:\/\/arzhost.com\/blogs\/?p=3402"},"modified":"2023-10-17T16:31:18","modified_gmt":"2023-10-17T16:31:18","slug":"add-ssh-key-to-droplet","status":"publish","type":"post","link":"https:\/\/arzhost.com\/blogs\/add-ssh-key-to-droplet\/","title":{"rendered":"Add SSH Key to Droplet for Secure Access"},"content":{"rendered":"<p>Today here at <a href=\"https:\/\/arzhost.com\/\">Arzhost<\/a>, our experts discuss how we <span style=\"color: #000000;\"><strong>Add SSH Key to Droplet<\/strong><\/span> in the <strong>Digital Ocean<\/strong>. My <strong>Digital Ocean (DO) droplet<\/strong> is configured so that a password cannot be used to access it. However, since I lost the private SSH Key when I changed my local PC, I can no longer access my droplet. Thankfully, I can still connect to the remote server through Web Console, but it&#8217;s too sluggish and choppy.<\/p>\n<p><iframe title=\"YouTube video player\" src=\"https:\/\/www.youtube.com\/embed\/r3t61OP5mWs\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>I add my current ssh key to the droplet by following these steps:<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/arzhost.com\/blogs\/add-ssh-key-to-droplet\/#1_Create_a_Fresh_Set_of_SSH_Keys_on_Your_Current_Local_Machine\" >1: Create a Fresh Set of SSH Keys on Your Current Local Machine.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/arzhost.com\/blogs\/add-ssh-key-to-droplet\/#2_Store_the_Public_Key_in_a_Different_File\" >2: Store the Public Key in a Different File.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/arzhost.com\/blogs\/add-ssh-key-to-droplet\/#3_Submit_the_Public_Key_to_a_Service_for_File_Sharing\" >3: Submit the Public Key to a Service for File Sharing.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/arzhost.com\/blogs\/add-ssh-key-to-droplet\/#4_Launch_the_Following_Command_after_Logging_in_to_the_DO_Droplet_Using_the_Web_Console\" >4: Launch the Following Command after Logging in to the DO Droplet Using the Web Console:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/arzhost.com\/blogs\/add-ssh-key-to-droplet\/#5_Utilize_the_New_Local_Machine_to_Access_the_Droplet\" >5: Utilize the New Local Machine to Access the Droplet<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"1_Create_a_Fresh_Set_of_SSH_Keys_on_Your_Current_Local_Machine\"><\/span><strong>1: Create a Fresh Set of SSH Keys on Your Current Local Machine.<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Add SSH Key to Droplet, the following command can be used to create a new ssh key pair if there isn&#8217;t one already in the local system ($HOME\/.ssh\/):<\/p>\n<ul>\n<li><code>keygen-ssh -t rsa<\/code><\/li>\n<\/ul>\n<p><u>Alternatively, you can use this command to attach your email to the key:<\/u><\/p>\n<ul>\n<li><code>keygen-ssh -t rsa -b 4096 -C \"your email@example.com\"<\/code><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"2_Store_the_Public_Key_in_a_Different_File\"><\/span><strong>2: Store the Public Key in a Different File.<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><u>To copy id rsa.pub to key.txt, issue the following command to Add SSH Key to Droplet:<\/u><\/p>\n<ul>\n<li><code>cd ~<\/code><\/li>\n<li><code>if (cat \/.ssh\/id rsa.pub &gt; key.txt)<\/code><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"3_Submit_the_Public_Key_to_a_Service_for_File_Sharing\"><\/span><strong>3: Submit the Public Key to a Service for File Sharing.<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><u>Run the command line:<\/u><\/p>\n<ul>\n<li><code>curl key.txt at https:\/\/bashupload.com \u2014data-binary<\/code><\/li>\n<\/ul>\n<p>The reply will provide a download link for the key. Save it for use in the following step to Add SSH Key to Droplet.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"4_Launch_the_Following_Command_after_Logging_in_to_the_DO_Droplet_Using_the_Web_Console\"><\/span><strong>4: Launch the Following Command after Logging in to the DO Droplet Using the Web Console:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><code>cd ~\/.ssh<\/code><\/li>\n<li><code>Link-from-Previous-Step: wget<\/code><\/li>\n<li><code>cat key.txt &gt;&gt; authorized keys<\/code><\/li>\n<\/ul>\n<p>Note: Use &gt;&gt; to guarantee that the key is appended to the authorized keys file rather than being overwritten when using the cat command.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"5_Utilize_the_New_Local_Machine_to_Access_the_Droplet\"><\/span><strong>5: Utilize the New Local Machine to Access the Droplet<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><u>To connect to a droplet via SSH, enter the following command:<\/u><\/p>\n<ul>\n<li><code>Username@IP Address: ssh<\/code><\/li>\n<\/ul>\n<p><strong>Related Article<\/strong><\/p>\n<ul>\n<li><strong><span style=\"color: #ff6600;\"><a style=\"color: #ff6600;\" href=\"https:\/\/arzhost.com\/blogs\/digital-ocean-add-ssh-key-to-droplet\/\">Digital Ocean Add SSH Key to Droplet<\/a><\/span><\/strong><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Today here at Arzhost, our experts discuss how we Add SSH Key to Droplet in the Digital Ocean. My Digital Ocean (DO) droplet is configured so that a password cannot be used to access it. However, since I lost the private SSH Key when I changed my local PC, I can no longer access my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6485,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,15],"tags":[],"table_tags":[],"class_list":["post-3402","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-window","category-wordpress"],"_links":{"self":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/3402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/comments?post=3402"}],"version-history":[{"count":3,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/3402\/revisions"}],"predecessor-version":[{"id":6486,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/posts\/3402\/revisions\/6486"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media\/6485"}],"wp:attachment":[{"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/media?parent=3402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/categories?post=3402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/tags?post=3402"},{"taxonomy":"table_tags","embeddable":true,"href":"https:\/\/arzhost.com\/blogs\/wp-json\/wp\/v2\/table_tags?post=3402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}