enable sshd in WSL

ldd.cool / 2023-08-07 / 原文

正常安装 openssh-server:

sudo yum install -y openssh-server

WSL 中的特殊配置:

mv /usr/bin/systemctl /usr/bin/systemctl.old
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
chmod +x /usr/bin/systemctl
systemctl enable sshd
# 很可能显示失败
systemctl status sshd

# 手动执行 sshd 服务会报错
/sbin/sshd -f /etc/ssh/sshd_config

会报这种错:

Could not load host key: /etc/ssh/ssh_host_rsa_key

解决方法是手动生成:

ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key

最后,重启:

service sshd restart