{"id":3436,"date":"2018-04-28T12:06:53","date_gmt":"2018-04-28T10:06:53","guid":{"rendered":"https:\/\/en.florianbrinkmann.de\/?p=3436"},"modified":"2020-02-09T11:23:01","modified_gmt":"2020-02-09T10:23:01","slug":"ssh-key-and-the-windows-subsystem-for-linux","status":"publish","type":"post","link":"https:\/\/florianbrinkmann.com\/en\/ssh-key-and-the-windows-subsystem-for-linux-3436\/","title":{"rendered":"SSH key and the \u00bbWindows Subsystem for Linux\u00ab"},"content":{"rendered":"\n<p>With <em>Bash on Ubuntu on Windows<\/em>, you can use a <em>Windows Subsystem for Linux<\/em> on Windows 10. With that, you can run many Linux commands, for example, <code class=\"language-bash\">ssh<\/code>. This post shows you how to create an SSH key, which should be used on both, the Linux subsystem and Windows.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div class=\"update-box\">\n<p><strong>Update from May 14, 2018:<\/strong> After updating to the Insider Build 17063, you need to run the following commands on the Windows Subsystem for Linux to make the solution work again, <a href=\"https:\/\/florianbrinkmann.com\/en\/3436\/ssh-key-and-the-windows-subsystem-for-linux\/#comment-2216\">as <em>Entity Black<\/em> points out in his comment under this post<\/a>:<\/p>\n<pre class=\"lang-bash\"><code class=\"lang-bash\">sudo umount \/mnt\/c\nsudo mount -t drvfs C: \/mnt\/c -o metadata <\/code><\/pre>\n<p><strong>Update from May 29, 2018:<\/strong> It seems that the steps with unmounting are only temporary, as pointed out in the comments. To fix this, you need to modify or create a config file and add a little bit of content to it. There are three slightly different ways proposed in the comments \u2013 <a href=\"https:\/\/florianbrinkmann.com\/en\/3436\/ssh-key-and-the-windows-subsystem-for-linux\/#comment-2463\">one by Andrew<\/a>, <a href=\"https:\/\/florianbrinkmann.com\/en\/3436\/ssh-key-and-the-windows-subsystem-for-linux\/#comment-2465\">one by Entity Black<\/a>, and <a href=\"https:\/\/florianbrinkmann.com\/en\/3436\/ssh-key-and-the-windows-subsystem-for-linux\/#comment-2467\">one by Vince<\/a>.<\/p>\n<p><strong>Update from July 10, 2018:<\/strong> <a href=\"https:\/\/florianbrinkmann.com\/en\/3436\/ssh-key-and-the-windows-subsystem-for-linux\/#comment-3109\">Darren mentioned in his comment<\/a>, that using SSH alias with the described solution will fail, and how to solve that.<\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Goal<\/h2>\n\n\n\n<p>I wanted to create an SSH key, which I can use with the Linux subsystem and standard Windows programs. In the best scenario, the key is stored only once on the hard disk. <a href=\"https:\/\/www.howtogeek.com\/249966\/how-to-install-and-use-the-linux-bash-shell-on-windows-10\/\">You can read a tutorial about installing the subsystem on howtogeek.com<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solution<\/h2>\n\n\n\n<p>The default path for SSH keys on Windows is <code class=\"language-bash\">C:\/Users\/Florian\/.ssh<\/code> which matches the path <code class=\"language-bash\">\/mnt\/c\/Users\/Florian\/.ssh<\/code> on the Linux subsystem. Default SSH path on the subsystem is <code class=\"language-bash\">~\/.ssh<\/code>.<\/p>\n\n\n\n<p>Previous to this post update, I had a not optimal solution where the keys needed to exist twice. But in the comments there were several folks with better solutions \u2013 one of them <a href=\"https:\/\/florianbrinkmann.com\/en\/3436\/ssh-key-and-the-windows-subsystem-for-linux\/#comment-984\">Andrey Chirkov, who posted a one-line solution<\/a> that you run on the Windows Subsystem for Linux (the <code class=\"language-bash\">~\/.ssh<\/code> folder must not exist before running it):<\/p>\n\n\n<pre class=\"wp-block-code language-bash\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash\">ln -s \/mnt\/c\/Users\/Florian\/.ssh ~\/.ssh<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>That creates a link from <code class=\"language-bash\">~\/.ssh<\/code> to <code class=\"language-bash\">\/mnt\/c\/Users\/Florian\/.ssh<\/code>. With that, we only need to store our SSH keys in the Windows path and can use them from the Linux shell, too.<\/p>\n\n\n\n<p>After trying it, I noticed that this line was also <a href=\"http:\/\/softwareengineering.stackexchange.com\/a\/335834\">part of the Stack Overflow response<\/a> I linked in the previous version of the post. I have no idea why I did not get it working back then\u2026<\/p>\n\n\n\n<p><em>The original version of this post was published on March 8, 2017.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With Bash on Ubuntu on Windows, you can use a Windows Subsystem for Linux on Windows 10. With that, you can run many Linux commands, for example, ssh. This post shows you how to create an SSH key, which should be used on both, the Linux subsystem and Windows.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wpf_show_in_dewp_planet_feed":false,"flobn_post_versions":"","webmentions_disabled_pings":false,"webmentions_disabled":false,"lazy_load_responsive_images_disabled":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-3436","post","type-post","status-publish","format-standard","hentry","category-web-development"],"wp-worthy-pixel":{"ignored":false,"public":"05c18f744dee4c79b52fb87a881d7cb9","server":"vg04.met.vgwort.de","url":"https:\/\/vg04.met.vgwort.de\/na\/05c18f744dee4c79b52fb87a881d7cb9"},"wp-worthy-type":"normal","_links":{"self":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/comments?post=3436"}],"version-history":[{"count":11,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3436\/revisions"}],"predecessor-version":[{"id":5964,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3436\/revisions\/5964"}],"wp:attachment":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/media?parent=3436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/categories?post=3436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/tags?post=3436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}