Configuring an SSH Server on the Windows Subsystem for Linux
Install openssh No need to go on too much about this; first you need to install openssh-server and openssh-client. Modify the sshd-config configuration The three lines you need to pay attention to are these. UsePrivilegeSeparation no #because WSL has not implemented chroot PasswordAuthentication yes ListenAddress 0.0.0.0
目录9 个章节
Install openssh
No need to go on too much about this; first you need to install openssh-server and openssh-client.
Modify the sshd-config configuration
The three lines you need to pay attention to are these.
UsePrivilegeSeparation no #因为wsl没有实现chroot
PasswordAuthentication yes
ListenAddress 0.0.0.0 #这一项在我的发行版里缺省为注释行。
The rest can be modified according to your needs.
ListenAddress 0.0.0.0 # 要让其他计算机能连接上需要加上这一行,或者把经常需要连接的计算机IP加入
PermitRootLogin yes # 允许root用户登录。
Disable Windows built-in SSH
I didn't know this originally; only after looking it up did I learn that newer versions of Windows come with an SSH service, though I haven't yet figured out how to use it. You can use PowerShell to check this service.
PS C:\Users\user> Get-Service -Name ssh*
Status Name DisplayName
------ ---- -----------
Stopped SshBroker SSH Server Broker
Stopped SshProxy SSH Server Proxy
Just find these two services in the Services console and stop them.
Note that you need to stop sshproxy first before you can turn off sshbroker.

Start SSH in debug mode
/usr/sbin/sshd -d
-d indicates that the service is started in debug mode; in this case, errors will be displayed on the console.
Note that even if you start the ssh server this way, it is still only a child service that exists while a bash window is open. Once the last bash window is closed, this ssh server shuts down as well, which is clearly not what we want. Next, let's see how to run the ssh server as a Windows service or a background process.
Start SSH normally
service ssh start
Automatically start the SSH service
Currently WSL does not support running the ssh server as a service. We need to use Windows scheduled tasks and a script so that this service runs automatically when Windows starts.
set ws=wscript.createobject("wscript.shell")
ws.run "C:\Windows\System32\bash.exe -c '/usr/sbin/sshd -D'",0
Save this file as vbs, and add a startup task in Task Scheduler with the trigger set to at system startup. However, a prerequisite for using this method is that your WSL default user is root; if the default user is not root, you must start it using sudo. But! When executing sudo, it will prompt for a password, and at that point there is no way to receive user input. To solve this problem, you need to allow sudo to execute commands without a password.
Enter the following command in bash:
sudo visudo
#includedir /etc/sudoers.d
username ALL=(ALL) NOPASSWD: /usr/sbin/sshd -D
Just change username to your own username.
References
About
To learn more interesting operations, please follow my WeChat official account: DealiAxy Every article is collected on my blog: blog.deali.cn
_EOF_
Configuring an SSH Server on the Windows Subsystem for Linux
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
这是演习:Win10蓝屏,随你召唤
蓝屏似乎是很多IT之家用户不希望看到的东西,虽然在Win10中你还可以扫描屏幕下方二维码参与微软互动赢取大……那个,蓝屏的好处就是为专业人员提供问题信息,比如当前的内存转储,有助于排查和解决问题。当然,可能光是默认蓝屏给出的信息不够,此时可以开启Win10蓝屏详细信息显示。 ▲这二维码居然“上位”了……VM12虚拟机测试结果 微软在Windows10中安排了手动“调取”蓝屏的方式,那就是**按住右
2021-12-18 · Windows · 约 1 分钟
修复winget命令找不到的问题
微软官方包管理器winget在Windows 10 1809以上版本中,用于快速安装、更新和管理应用程序。本文介绍了因系统环境变化导致winget命令失效的问题,分析了可能原因,并提供了解决方案及预防措施,包括修复命令、定期更新检查、备份环境变量等。
2025-04-04 · Windows · 约 1 分钟
2024年,提升Windows开发和使用体验实践 - 小工具篇
本来是一篇文章的,不知不觉写成了系列。 其实开工那几天就已经写好了长文,这几天一忙就没连着发了。 本文介绍一些 Windows 上用的小工具。
2024-02-29 · Windows · 约 1 分钟
解决Windows蓝牙耳机音质差的问题
Windows 把蓝牙耳机麦克风一调用就切 HFP,全损音质,真当用户听不出来?mmsys.cpl 里把录制设备禁掉,世界清净。这破系统还得手动治。
2026-11-12 · Windows · 约 1 分钟
讨论
共 0 条加载评论中…
