返回文章列表文章索引阅读全文
STARBLOG / 阅读手记
Windows

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

曦远 (DealiAxy)约 8 分钟
目录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

hbaaron.github.io

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 许可协议。转载请注明出处!

相关文章

IT之家学院:让Win10文件管理器的详细信息窗格显示更多信息

当你在Windows的资源管理器中将详细信息窗格设置为可用,然后选中一个文件时(IT之家小编选中了一个exe文件),你将在窗口的右半部分看到这个文件的一些信息,包括修改日期、创建日期、文件大小和可用性,不过对于一些用户来说,这些信息十分有限,还是不够详细。 在这篇文章中,IT之家将为大家演示如何进行设置,以使文件资源管理器可在详细信息窗格中显示更多的关于已被选中的文件的有用信息。 下文中的方法适用

2021-12-18 · Windows · 约 1 分钟

讨论

共 0 条

良言一句三冬暖,恶语伤人六月寒。

加载评论中…