{"componentChunkName":"component---src-templates-post-template-js","path":"/note-remote-edit-byvscode-en","result":{"data":{"markdownRemark":{"id":"dc062278-b531-5165-8c07-a84f7a03d184","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/note-remote-edit-byvscode\">original page</a>.</p>\n</blockquote>\n<p>Recently, Docker is available on WSL2, so there are fewer occasions where you would deliberately do development on Linux inside a virtual machine.</p>\n<p>Even so, there are still times when I want to develop on a Linux environment that I built as a virtual machine.</p>\n<p>Unless there is a special need, I would prefer to build a Linux environment as CUI-only to save resources, but if I do that, I can no longer use a rich editor like VSCode.</p>\n<p>To solve that problem, this time I will summarize how to set up an environment that lets you use VSCode installed on the host Windows machine to operate files on Ubuntu running in a virtual machine.</p>\n<p>Specifically, you can configure it with the following steps.</p>\n<ol>\n<li>Create a Linux virtual machine in your local environment (Hyper-V is used this time)</li>\n<li>Prepare an environment where the virtual machine and the host machine can connect over SSH</li>\n<li>Prepare a key on the Windows host machine</li>\n<li>Register the created public key in the virtual machine’s <code class=\"language-text\">authorized_keys</code></li>\n<li>Use the RemoteSSH extension in VSCode on the host machine to connect to the virtual machine over SSH</li>\n</ol>\n<p>This time, I will omit the setup for steps 1 and 2.</p>\n<!-- omit in toc -->\n<h2 id=\"contents\" style=\"position:relative;\"><a href=\"#contents\" aria-label=\"contents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Contents</h2>\n<ul>\n<li><a href=\"#prepare-an-ssh-key-on-windows\">Prepare an SSH key on Windows</a></li>\n<li><a href=\"#register-the-public-key-on-the-virtual-machine\">Register the public key on the virtual machine</a></li>\n<li><a href=\"#connect-to-the-virtual-machine-from-vscode\">Connect to the virtual machine from VSCode</a></li>\n<li><a href=\"#summary\">Summary</a></li>\n</ul>\n<h2 id=\"prepare-an-ssh-key-on-windows\" style=\"position:relative;\"><a href=\"#prepare-an-ssh-key-on-windows\" aria-label=\"prepare an ssh key on windows permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Prepare an SSH key on Windows</h2>\n<p>Let’s get started by creating a key on the host Windows machine.</p>\n<p>Just start PowerShell and run <code class=\"language-text\">ssh-keygen.exe</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">ssh-keygen<span class=\"token punctuation\">.</span>exe\n\nGenerating public/private rsa key pair<span class=\"token punctuation\">.</span>\nEnter file in which to save the key <span class=\"token punctuation\">(</span>C:\\Users\\kash1064/<span class=\"token punctuation\">.</span>ssh/id_rsa<span class=\"token punctuation\">)</span>:\nEnter passphrase <span class=\"token punctuation\">(</span>empty <span class=\"token keyword\">for</span> no passphrase<span class=\"token punctuation\">)</span>:\nEnter same passphrase again:\nYour identification has been saved in C:\\Users\\kash1064/<span class=\"token punctuation\">.</span>ssh/id_rsa<span class=\"token punctuation\">.</span>\nYour public key has been saved in C:\\Users\\kash1064/<span class=\"token punctuation\">.</span>ssh/id_rsa<span class=\"token punctuation\">.</span>pub<span class=\"token punctuation\">.</span>\nThe key fingerprint is:\nSHA256:tE/q/DCfasd3vyVQzn7/lzgq5i79k+asip3LPNafwvWE kash1064@HEQET-01\nThe key's randomart image is:\n<span class=\"token operator\">+</span><span class=\"token operator\">--</span><span class=\"token operator\">-</span><span class=\"token namespace\">[RSA 3072]</span><span class=\"token operator\">--</span><span class=\"token operator\">--</span><span class=\"token operator\">+</span>\n<span class=\"token punctuation\">|</span>                 <span class=\"token punctuation\">|</span>\n<span class=\"token punctuation\">|</span>                 <span class=\"token punctuation\">|</span>\n<span class=\"token punctuation\">|</span>        <span class=\"token punctuation\">.</span>        <span class=\"token punctuation\">|</span>\n<span class=\"token punctuation\">|</span>       <span class=\"token punctuation\">.</span> <span class=\"token punctuation\">.</span>       <span class=\"token punctuation\">|</span>\n<span class=\"token punctuation\">|</span>        S <span class=\"token punctuation\">.</span> <span class=\"token operator\">+</span>    <span class=\"token punctuation\">|</span>\n<span class=\"token punctuation\">|</span>         <span class=\"token operator\">+</span> <span class=\"token operator\">+</span> <span class=\"token operator\">*</span> <span class=\"token punctuation\">.</span> <span class=\"token punctuation\">|</span>\n<span class=\"token punctuation\">|</span>        <span class=\"token operator\">+</span> <span class=\"token operator\">*</span> A D <span class=\"token punctuation\">.</span><span class=\"token punctuation\">|</span>\n<span class=\"token punctuation\">|</span>       <span class=\"token operator\">*</span>o*<span class=\"token operator\">+</span>M<span class=\"token punctuation\">.</span><span class=\"token operator\">*</span> <span class=\"token operator\">*</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">|</span>\n<span class=\"token punctuation\">|</span>      <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token operator\">*</span>VXA@vv+<span class=\"token operator\">*</span><span class=\"token punctuation\">|</span>\n<span class=\"token operator\">+</span><span class=\"token operator\">--</span><span class=\"token operator\">--</span><span class=\"token namespace\">[SHA256]</span><span class=\"token operator\">--</span><span class=\"token operator\">--</span><span class=\"token operator\">-</span><span class=\"token operator\">+</span></code></pre></div>\n<p>The public key you created is usually placed directly under the <code class=\"language-text\">.ssh/</code> directory in your user folder.</p>\n<h2 id=\"register-the-public-key-on-the-virtual-machine\" style=\"position:relative;\"><a href=\"#register-the-public-key-on-the-virtual-machine\" aria-label=\"register the public key on the virtual machine permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Register the public key on the virtual machine</h2>\n<p>Next, append the created public key to <code class=\"language-text\">.ssh/authorized_keys</code> on the Linux machine.</p>\n<p>You can simply copy and paste it with <code class=\"language-text\">vim</code> or similar.</p>\n<p>After registration is complete, run the following command from PowerShell to confirm that SSH using the private key works.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">ssh &lt;virtual-machine-username>@&lt;virtual-machine-address> <span class=\"token operator\">-</span>i <span class=\"token punctuation\">.</span>\\<span class=\"token punctuation\">.</span>ssh\\id_rsa</code></pre></div>\n<h2 id=\"connect-to-the-virtual-machine-from-vscode\" style=\"position:relative;\"><a href=\"#connect-to-the-virtual-machine-from-vscode\" aria-label=\"connect to the virtual machine from vscode permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Connect to the virtual machine from VSCode</h2>\n<p>Finally, set up the connection from VSCode to the virtual machine.</p>\n<p>First, install the RemoteSSH extension in VSCode.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 805px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/20d1137cdae905ce08cb19e8d83f553c/c946b/remotessh.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 25%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABJElEQVQY002QvU7DMBSF8xwkaezaSRzHTtKkkdu0hUpIDKhShw6UAYmJhTdg5RVADB14KSRmJN7j9CZFwPDpHP/cc6/tSSlhdQKjBIxWkDJGFDFwPgZj/Jd+L2KMPCmd+Vygr+0R4g9vFAZIL+9R7J/BsgZVaTHvFiirCk0zJWq0bQvnZoRDS7qiO7tcIgxDBET4Dy/ttrh9+8TN4QvLxwNsnmHeNshTibosUFPoxKRYNwlckaCqGzhqMssVsiyDUmpgmDyK4MXuGvvXD9y9f6N7eIGcLGAuNsjWW6jpkhpoWGtRGI2ysDC5gaKgVOshUJPqH885hxcGZ0jO9zC7J4xiA144iNkV4tVm8GMWQdA/jYVAnCTDJL7vIwiCgZM/rfsnHwGaEpvK09FsmQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/20d1137cdae905ce08cb19e8d83f553c/8ac56/remotessh.webp 240w,\n/static/20d1137cdae905ce08cb19e8d83f553c/d3be9/remotessh.webp 480w,\n/static/20d1137cdae905ce08cb19e8d83f553c/82ef0/remotessh.webp 805w\"\n              sizes=\"(max-width: 805px) 100vw, 805px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/20d1137cdae905ce08cb19e8d83f553c/8ff5a/remotessh.png 240w,\n/static/20d1137cdae905ce08cb19e8d83f553c/e85cb/remotessh.png 480w,\n/static/20d1137cdae905ce08cb19e8d83f553c/c946b/remotessh.png 805w\"\n            sizes=\"(max-width: 805px) 100vw, 805px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/20d1137cdae905ce08cb19e8d83f553c/c946b/remotessh.png\"\n            alt=\"remotessh\"\n            title=\"remotessh\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Next, select the RemoteSSH icon from the sidebar and set the address of the virtual machine you created as the SSH Target.</p>\n<p>At that time, configure the generated <code class=\"language-text\">config</code> file as shown in the image below.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 796px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/eac9861065796c4d17bda5bb4e11111a/d48f1/vscodessh.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 31.666666666666664%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAA7DAAAOwwHHb6hkAAABBUlEQVQY03WPTXaEIBCEvUcUFBQcTeIYUcG/yUZz/xNVGnTmZZPF9wqa7qIrmr53LMtKLDiOH+z7gXVdYa3Ftm2hbq1D1xmiCxhjwr3ve8zTjHmerxmHyI0jmuYOOzo4O4WmqqqRZSJoWZbQWkErj4YiBL2laXaRgvMTf476YcD93pLRgLZtIWUOmRekEinnuDUdvswA81mjq0vUuqBhhrc4RpwkgYRg7NTIR9O6DEZFoV4I4Q0ZiuoDrXugpU9vhcS7ylETZS6gpICmmt+MMUYfcYpMuX2snLbyRk/1hs+mlCLyzA9yCEJmacCfBSmnPnYRDcP4j6EIEU7ii/P+N2r86jn5BfrMsH1YAUFiAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/eac9861065796c4d17bda5bb4e11111a/8ac56/vscodessh.webp 240w,\n/static/eac9861065796c4d17bda5bb4e11111a/d3be9/vscodessh.webp 480w,\n/static/eac9861065796c4d17bda5bb4e11111a/7fcbc/vscodessh.webp 796w\"\n              sizes=\"(max-width: 796px) 100vw, 796px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/eac9861065796c4d17bda5bb4e11111a/8ff5a/vscodessh.png 240w,\n/static/eac9861065796c4d17bda5bb4e11111a/e85cb/vscodessh.png 480w,\n/static/eac9861065796c4d17bda5bb4e11111a/d48f1/vscodessh.png 796w\"\n            sizes=\"(max-width: 796px) 100vw, 796px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/eac9861065796c4d17bda5bb4e11111a/d48f1/vscodessh.png\"\n            alt=\"img\"\n            title=\"img\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>For <code class=\"language-text\">IdentifyFile</code>, specify the path to the private key in the key pair you created earlier.</p>\n<p>If you do not set this, you will be asked for the virtual machine’s password every time you connect, which is a bit inconvenient.</p>\n<p>Once the configuration is complete, click the <code class=\"language-text\">Connect Remote Host</code> button. A new window will open, and you will be able to operate the virtual machine’s files directly from VSCode.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/389a91763ea79e5666ed2ac9ed2fafd3/0b533/vscodessh2.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 67.91666666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAB9UlEQVQ4y4WS3ZKaQBSEeYwsy9/AMIOoqyAsCqKAprSyblWqcp/sXd7/CTpnBjTqbjYXX80PPT3nNGNstw22TYtqXWNd1+i6Hfb7r2jbDmVZou06nE6vaJpGr6uqQlnVpN8gyzIk8znSNEWe51gsFjBmkzGy2QQxZ5BCYFm3yFdrzLIC83yJJF8hLUqar2i+xDxbQrY/EL3+hiMmsMwHWJZNWBojzFtMXt4wO72BF3vMplPwUCLUCJq/JxAjBDKG6zE4tg3HcS4Y43yNuH5BVB4R5xs8kWEQhGRG8Fv4QL/mcF0X9r1h+LyDPP7E+NsvyOqoKwzUAarkX/BhdF3vYngejYSyWjUHFM0RWVEhSZK+ik8Mw88Mx3GMKIoRihjxKMZ0+gQe8Et71wS0f0atPzQM6c/2gl7EmD/k4V7hwPO8Ptcw1FqVX6+7y1AIedPi+VabhNe3+74PKQUhqaPo5odo/cA7Q08Z0ntyLPtGqCpkjOnq1Hjf6ocV6pxU6yMJX3BEo5Gu5mykqrw2YF6/r59U0MdgSDrQPwN6yFyAqXwmEt6YTEmkKnYpRxXF39wIu89Z7envQ9aGpEcc0E0+9zW2a8E0v8B8JKwHmLbCvPB4hXlDrzOy7wekhw7raYdNvEPOSqTOEgt3wPkPpFH656BCxlb4AwSMlz4PEfKFAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/389a91763ea79e5666ed2ac9ed2fafd3/8ac56/vscodessh2.webp 240w,\n/static/389a91763ea79e5666ed2ac9ed2fafd3/d3be9/vscodessh2.webp 480w,\n/static/389a91763ea79e5666ed2ac9ed2fafd3/b0a15/vscodessh2.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/389a91763ea79e5666ed2ac9ed2fafd3/8ff5a/vscodessh2.png 240w,\n/static/389a91763ea79e5666ed2ac9ed2fafd3/e85cb/vscodessh2.png 480w,\n/static/389a91763ea79e5666ed2ac9ed2fafd3/0b533/vscodessh2.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/389a91763ea79e5666ed2ac9ed2fafd3/0b533/vscodessh2.png\"\n            alt=\"img\"\n            title=\"img\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<h2 id=\"summary\" style=\"position:relative;\"><a href=\"#summary\" aria-label=\"summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summary</h2>\n<p>It is not exactly something that needs to be made into an article at this point, but even though it is convenient, surprisingly few people seem to use it, so I decided to summarize it.</p>\n<p>Please make good use of it.</p>","fields":{"slug":"/note-remote-edit-byvscode-en","tagSlugs":["/tag/notes/","/tag/vs-code/","/tag/memo/","/tag/english/"]},"frontmatter":{"date":"2021-07-18","description":"This article summarizes how to set up an environment that lets you use VSCode installed on the Windows host to work with files on Ubuntu running in a virtual machine.","tags":["Notes","VSCode","Memo","English"],"title":"How to Make It Possible to Edit Files on a Hyper-V Virtual Machine Directly from VSCode","socialImage":{"publicURL":"/static/dc4d8b7f8795f3c3d3489d9957d155f2/no-image.png"}}}},"pageContext":{"slug":"/note-remote-edit-byvscode-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}