1.启动windows虚拟机服务
![](https://img-blog.csdnimg.cn/img_convert/23db1fb7ae7424bc59a7bd38809f43ff.webp?x-oss-process=image/format,png)
image.png
![](https://img-blog.csdnimg.cn/img_convert/8107e3d9534db4a54d1085fa04695e09.webp?x-oss-process=image/format,png)
image.png
- wsl2
重启电脑
打开PowerShell,执行如下命令切换到WSL2
wsl --set-default-version 2
- 安装CentOS
3.1.下载wsl-centos安装文件GitHub - mishamosher/CentOS-WSL: A GitHub Actions automated CentOS RootFS to use with WSL
![](https://img-blog.csdnimg.cn/img_convert/6bf9c3d4cc0b4eb8ad0460821c3afc20.webp?x-oss-process=image/format,png)
image.png
下载速度比较慢,可使用百度网盘地址
链接: https://pan.baidu.com/s/1JAJ0BdGBAxxlaqWS-kgMbg?pwd=5t9h
提取码:5t9h
3.2 安装
解压文件夹到安装目录
使用管理员模式打开exe安装程序
![](https://img-blog.csdnimg.cn/img_convert/e5bb75ae5643e383d0fd92312521a1e5.webp?x-oss-process=image/format,png)
image.png
安装完成后,如下图
![](https://img-blog.csdnimg.cn/img_convert/551f77575ddc7e03abac6ecdcdee82f6.webp?x-oss-process=image/format,png)
image.png
![](https://img-blog.csdnimg.cn/img_convert/50044f6799458c05f9e0f48e92c96d2c.webp?x-oss-process=image/format,png)
image.png
-
systemctl 文件修改
image.png
wsl安装的centos无法执行systemctl命令,需要修改文件/usr/bin/systemctl
#备份systemctl文件
mv /usr/bin/systemctl /usr/bin/systemctl.old
#获取新文件,若一下文件无法获取,则手动下载
#https://github.com/gdraheim/docker-systemctl-replacement/blob/master/files/docker/systemctl.py
#手动替换文件,注意编码格式为unix
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
#设置可执行
chmod +x /usr/bin/systemctl
5.ssh配置
#设置密钥,生成过程 全部直接按回车
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
#重启查看状态
systemctl restart sshd
systemctl status sshd
#若启动失败,查看原因
sudo sshd -t
#设置登录密码
sudo passwd root