{"slug":"sshfs","title":"将你的Linux硬盘映射到Windows？","description":"如何像Windows一样管理Linux文件和开发？SSHFS来帮你！","coverImage":"https://b.acofork.com/img/sshfs-Linux-win.webp","coverWidth":1200,"coverHeight":900,"date":"2026-04-18","tags":["服务器"],"pinned":false,"wordCount":543,"html":"<h2 id=\"引言\">引言</h2><p>你是否有一个Linux服务器？你是否曾经使用过各大IDE的远程开发？你是否被巨大的 <code>vscode-server</code> <code>trae-server</code> ... 占用巨额储存空间？</p>\n<p>实际上，当我们进行远程开发的时候，我们只需要 <strong>在Windows上操作Linux的文件</strong> 即可</p>\n<p>那我们为什么不尝试 <strong>将Linux上的目录挂到Windows上</strong> 呢？</p>\n<h2 id=\"正式开始\">正式开始</h2><p>首先我们需要安装SSHFS，你可以前往Github下载发行版： <a href=\"https://github.com/libfuse/sshfs\" target=\"_blank\" rel=\"noopener noreferrer\">libfuse/sshfs: A network filesystem client to connect to SSH servers</a>，又或者通过Scoop安装： <code>scoop install nonportable/sshfs-np</code> </p>\n<p>接着编写一个批处理脚本，方便我们每次的挂载</p>\n<div class=\"markdown-code\" data-language=\"sql\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path></svg><span>sql</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SET</span> PATH<span class=\"hljs-operator\">=</span>C:\\Program Files\\SSHFS<span class=\"hljs-operator\">-</span>Win\\bin\n\"C:\\Program Files\\SSHFS-Win\\bin\\sshfs.exe\" <span class=\"hljs-operator\">-</span>f root<span class=\"hljs-variable\">@192</span><span class=\"hljs-number\">.168</span><span class=\"hljs-number\">.124</span><span class=\"hljs-number\">.14</span>:<span class=\"hljs-operator\">/</span> X: <span class=\"hljs-operator\">-</span>o workaround<span class=\"hljs-operator\">=</span>rename <span class=\"hljs-operator\">-</span>o idmap<span class=\"hljs-operator\">=</span><span class=\"hljs-keyword\">user</span></code></pre></div><blockquote>\n<p>第一行命令的作用详见： <a href=\"https://github.com/winfsp/sshfs-win/issues/401#issuecomment-1968129241\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/winfsp/sshfs-win/issues/401#issuecomment-1968129241</a></p>\n</blockquote>\n<ul>\n<li><code>C:\\Program Files\\SSHFS-Win\\bin</code> 你的SSHFS二进制文件所在的目录</li>\n<li><code>-f</code> 前台挂载，关闭CMD窗口后则失效</li>\n<li><code>root@192.168.124.14:/</code> 你要连接的SSH主机（192.168.124.14），登录用户（root），挂载目录（/）</li>\n<li><code>X:</code> 要挂载到的Windows盘符</li>\n<li><code>workaround=rename</code> 自动修复Unix文件名</li>\n<li><code>idmap=user</code> 以SSH登录的用户权限来访问挂载目录，这里为root，避免访问权限问题</li>\n</ul>\n<p>最后，我们就可以在Windows文件资源管理器中看到被挂载的Linux盘符了</p>\n<p><img src=\"https://b.acofork.com/img/sshfs-sshfs.webp\" alt=\"\" width=\"1125\" height=\"634\" loading=\"eager\" decoding=\"async\" /></p>\n<p><img src=\"https://b.acofork.com/img/sshfs-sshfs-1.webp\" alt=\"\" width=\"1125\" height=\"1015\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>同时，我们也可以使用任何软件来直接打开Linux上的文件来远程开发</p>\n<p><img src=\"https://b.acofork.com/img/sshfs-sshfs-2.webp\" alt=\"\" width=\"2560\" height=\"1392\" loading=\"lazy\" decoding=\"async\" /></p>\n<p>需要注意的是，和其他IDE直接通过SSH连接服务器进行远程开发不同。SSHFS仅是通过SFTP协议将Linux上的 <strong>文件系统</strong> 映射到Windows上来。并不包含整个Linux环境</p>\n<p>所以，SSHFS上的终端解释器为你的 <strong>Windows终端解释器</strong> ，而其他IDE的远程开发的终端解释器为 <strong>目标Linux上的终端解释器</strong>。</p>\n<p>如果需要调用Linux上的原生命令，则需要另开SSH</p>\n<p><img src=\"https://b.acofork.com/img/sshfs-sshfs-4.webp\" alt=\"\" width=\"1614\" height=\"716\" loading=\"lazy\" decoding=\"async\" /></p>\n","toc":[{"id":"引言","text":"引言","depth":2},{"id":"正式开始","text":"正式开始","depth":2}]}