曦远 (DealiAxy)一份私人的文字刊物

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

相关文章

这是演习:Win10蓝屏,随你召唤

蓝屏似乎是很多IT之家用户不希望看到的东西,虽然在Win10中你还可以扫描屏幕下方二维码参与微软互动赢取大……那个,蓝屏的好处就是为专业人员提供问题信息,比如当前的内存转储,有助于排查和解决问题。当然,可能光是默认蓝屏给出的信息不够,此时可以开启Win10蓝屏详细信息显示。 ▲这二维码居然“上位”了……VM12虚拟机测试结果 微软在Windows10中安排了手动“调取”蓝屏的方式,那就是**按住右

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

讨论

共 0 条

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

加载评论中…