{"id":2879,"date":"2020-02-06T03:20:00","date_gmt":"2020-02-06T03:20:00","guid":{"rendered":"https:\/\/lamp.ciscoar.com\/?page_id=2879"},"modified":"2021-01-12T00:05:30","modified_gmt":"2021-01-12T00:05:30","slug":"copy-ssh-public-key-to-remote-server","status":"publish","type":"page","link":"https:\/\/lamp.ciscoar.com\/?page_id=2879","title":{"rendered":"Copy SSH Public key to remote server"},"content":{"rendered":"\n\n\n<h2 class=\"wp-block-heading\">WinSCP GUI vs the CLI<\/h2>\n\n\n\n<p>Here once again we&#8217;re going to have the two options, the CLI or the WinSCP GUI, I&#8217;m going to use the second option due to its simplicity but also include the correspondent CLI commands you should use if working with the terminal.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to copy the Public SSH key to the remote server <\/h2>\n\n\n\n<p>As we have already discussed on<a rel=\"noreferrer noopener\" aria-label=\" this article (opens in a new tab)\" href=\"\/telnet-vs-ssh\/#Authorized_Keys_file\" target=\"_blank\"> this article<\/a> the SSH public key must be copied to an specific file (<a rel=\"noreferrer noopener\" aria-label=\"authorized_keys (opens in a new tab)\" href=\"\/telnet-vs-ssh\/#Authorized_Keys_file\" target=\"_blank\">authorized_keys<\/a>) located on an specific folder (<a rel=\"noreferrer noopener\" aria-label=\".ssh (opens in a new tab)\" href=\"\/telnet-vs-ssh\/#Linux_CentOS_SSH_files_and_folders\" target=\"_blank\">.ssh<\/a>) located inside the user&#8217;s home directory, as it is dictated by the <a rel=\"noreferrer noopener\" aria-label=\"Global SSH settings file (opens in a new tab)\" href=\"\/ssh-global-settings\/\" target=\"_blank\">Global SSH settings file<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Ownership and permissions<\/h2>\n\n\n\n<p>Both the folder(<strong>.ssh<\/strong>)and the file (<strong>authorized_keys<\/strong>)must be configured to only allow the current user to be able to use them, proper ownership and permissions are the key here.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">WinSCP quick copy, It&#8217;s a kind of magic!<\/h2>\n\n\n\n<p>As I told you before, WinSCP is way more simple completing this task than using the CLI, the following animation shows how fast this process can be, by default no user has the folder &#8220;<strong>.ssh<\/strong>&#8221; nor the file &#8220;<strong>authorized_keys<\/strong>&#8221; it is your job to create them and to set them properly, or let WinSCP to do everything for you, let him do its magic!<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"504\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server.gif\" alt=\"\" class=\"wp-image-2888\"\/><figcaption>WinSCP doing its magic!<\/figcaption><\/figure><\/div>\n\n\n\n<p>You witnessed how WinSCP with just a few clicks did create the folder(<strong>.ssh<\/strong>), the file(<strong>authorized_keys<\/strong>), set proper ownership and permissions and not only that it also copied the Public key inside the file and now everything is there ready to be used.<\/p>\n\n\n\n<p>Amazing! wasn&#8217;t that terrific! I told you, once you start using WinSCP you automatically fall in love with it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step by step screenshots<\/h2>\n\n\n\n<p>Is the animation a little bit fast and hard to see each step? do not worry, here you are the separated screenshots.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-01.png\"><img loading=\"lazy\" decoding=\"async\" width=\"623\" height=\"335\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-01.png\" alt=\"\" class=\"wp-image-2891\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-01.png 623w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-01-300x161.png 300w\" sizes=\"auto, (max-width: 623px) 100vw, 623px\" \/><\/a><figcaption>WinSCP install Public Key into remote server<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-02.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"554\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-02-1024x554.png\" alt=\"\" class=\"wp-image-2892\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-02-1024x554.png 1024w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-02-300x162.png 300w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-02-768x416.png 768w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-02.png 1075w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><figcaption>See all files<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-03.png\"><img loading=\"lazy\" decoding=\"async\" width=\"961\" height=\"548\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-03.png\" alt=\"\" class=\"wp-image-2893\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-03.png 961w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-03-300x171.png 300w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-03-768x438.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><figcaption>select the public key<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-04.png\"><img loading=\"lazy\" decoding=\"async\" width=\"780\" height=\"434\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-04.png\" alt=\"\" class=\"wp-image-2894\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-04.png 780w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-04-300x167.png 300w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-04-768x427.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><figcaption>Public key has been installed<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-05.png\"><img loading=\"lazy\" decoding=\"async\" width=\"686\" height=\"410\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-05.png\" alt=\"\" class=\"wp-image-2895\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-05.png 686w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-05-300x179.png 300w\" sizes=\"auto, (max-width: 686px) 100vw, 686px\" \/><\/a><figcaption>refresh<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"711\" height=\"343\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-06.png\" alt=\"\" class=\"wp-image-2896\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-06.png 711w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-06-300x145.png 300w\" sizes=\"auto, (max-width: 711px) 100vw, 711px\" \/><figcaption>now you can see the folder that was automatically created<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-07.png\"><img loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"244\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-07.png\" alt=\"\" class=\"wp-image-2897\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-07.png 666w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-07-300x110.png 300w\" sizes=\"auto, (max-width: 666px) 100vw, 666px\" \/><\/a><figcaption>Open the folder to see the file that was automatically created<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-08.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-08.png\" alt=\"\" class=\"wp-image-2898\" width=\"644\" height=\"454\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-08.png 734w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-08-300x212.png 300w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/><\/a><figcaption>Open the file to see your public key <\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Folder ownership and permissions<\/h2>\n\n\n\n<p>In case you want to double check the folder&#8217;s security settings, I&#8217;m talking about the proper configuration of Ownership and Permissions, go ahead and use the WinSCP GUI to see its properties.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-09.png\"><img loading=\"lazy\" decoding=\"async\" width=\"531\" height=\"560\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-09.png\" alt=\"\" class=\"wp-image-2899\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-09.png 531w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-09-284x300.png 284w\" sizes=\"auto, (max-width: 531px) 100vw, 531px\" \/><\/a><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">File ownership and permissions <\/h2>\n\n\n\n<p>In case you want to double check the file security settings, I&#8217;m talking about the proper configuration of Ownership and Permissions, go ahead and use the WinSCP GUI to see its properties. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-10.png\"><img loading=\"lazy\" decoding=\"async\" width=\"641\" height=\"608\" src=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-10.png\" alt=\"\" class=\"wp-image-2900\" srcset=\"https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-10.png 641w, https:\/\/lamp.ciscoar.com\/wp-content\/uploads\/2020\/02\/WinSCP-How_to_copy_the_Public_SSH_key_to_the_remote_server-10-300x285.png 300w\" sizes=\"auto, (max-width: 641px) 100vw, 641px\" \/><\/a><figcaption>SSH file ownership and permissions<\/figcaption><\/figure><\/div>\n\n\n\n<p>Did you noticed that not even the &#8220;root&#8221; account has &#8220;executable&#8221; permissions over the file, that&#8217;s because the content of the file is not executable code written in any programming language, it is instead a bunch of characters representing an SSH key, and that&#8217;s perfectly fine because when it comes to permissions we always want to give the absolute necessary and nothing more.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CLI commands<\/h2>\n\n\n\n<p>As you saw, the above task was completed almost effortless using WinSCP, but if you prefer to use the terminal here you are the CLI commands you must use to achieve the same results, with the exception that you must use the text editor &#8220;vi&#8221; to paste the Public SSH key inside the file.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; highlight: [3]; title: ; notranslate\" title=\"\">\nmkdir .ssh\nchmod 700 .ssh\nvi .ssh\/authorized_keys (paste pub key)\nchmod 600 .ssh\/authorized_keys\nexit\n<\/pre><\/div>\n\n\n<p>Be careful with line number three, the words inside the parenthesis are not part of the CLI command they are there acting as a reminder that once inside the file and using &#8220;vi&#8221; you must copy the public key from the clipboard and into the file, if you want to learn a little bit more about &#8220;vi&#8221; you can take a look at <a rel=\"noreferrer noopener\" aria-label=\"this article (opens in a new tab)\" href=\"\/vi-and-vim\/\" target=\"_blank\">this article<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Where to go next?<\/h2>\n\n\n\n<p>We can perfectly say that most of the dirty job has been already done, and you are now just a couple of steps from completing the task, I\u2019m talking about the following steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"\/linux\/ssh-private-key\/map-private-ssh-key-to-a-winscp-session\/\">Map SSH Private Key to your WinSCP session<\/a><\/li><li><a href=\"\/connecting-to-server-using-ssh-keys\/\">Connecting to your remote server using SSH Keys<\/a><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>WinSCP GUI vs the CLI Here once again we&#8217;re going to have the two options, the CLI or the WinSCP GUI, I&#8217;m going to use the second option due to its simplicity but also include the correspondent CLI commands you should use if working with the terminal. How to copy the Public SSH key to &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/lamp.ciscoar.com\/?page_id=2879\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Copy SSH Public key to remote server&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2879","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages\/2879","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2879"}],"version-history":[{"count":25,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages\/2879\/revisions"}],"predecessor-version":[{"id":5750,"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=\/wp\/v2\/pages\/2879\/revisions\/5750"}],"wp:attachment":[{"href":"https:\/\/lamp.ciscoar.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}