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 许可协议。转载请注明出处!
相关文章
2024年,提升Windows开发和使用体验实践 - 小工具篇
本来是一篇文章的,不知不觉写成了系列。 其实开工那几天就已经写好了长文,这几天一忙就没连着发了。 本文介绍一些 Windows 上用的小工具。
2024-02-29 · Windows · 约 1 分钟
从SSH远程到Git Push:在Windows上一步到位实现免密码登录
我一直希望在Windows上能像在Linux系统中那样,通过SSH密钥实现免密码远程连接。每次远程连接到服务器时,手动输入密码既麻烦又不太安全,尤其是在我需要频繁操作的情况下。
2025-02-10 · Windows · 约 1 分钟
IT之家学院:让Win10文件管理器的详细信息窗格显示更多信息
当你在Windows的资源管理器中将详细信息窗格设置为可用,然后选中一个文件时(IT之家小编选中了一个exe文件),你将在窗口的右半部分看到这个文件的一些信息,包括修改日期、创建日期、文件大小和可用性,不过对于一些用户来说,这些信息十分有限,还是不够详细。 在这篇文章中,IT之家将为大家演示如何进行设置,以使文件资源管理器可在详细信息窗格中显示更多的关于已被选中的文件的有用信息。 下文中的方法适用
2021-12-18 · Windows · 约 1 分钟
在Windows上部署OpenSSH服务
Windows终于学会了没羞没臊地用命令行装OpenSSH,结果设置界面还是卡得像屎,算了,至少比以前强点。不过这SSH连上去还是CMD,是哪个脑回路觉得这操作体验没问题啊?
2025-06-12 · Windows · 约 1 分钟
讨论
共 0 条加载评论中…
