windows11通過(guò)WSL安裝虛擬機(jī)

安裝 WSL | Microsoft Learn

1.啟動(dòng)windows虛擬機(jī)服務(wù)

image.png
image.png
  1. wsl2

重啟電腦
打開(kāi)PowerShell,執(zhí)行如下命令切換到WSL2

wsl --set-default-version 2
  1. 安裝CentOS

3.1.下載wsl-centos安裝文件
GitHub - mishamosher/CentOS-WSL: A GitHub Actions automated CentOS RootFS to use with WSL

image.png

下載速度比較慢,可使用百度網(wǎng)盤(pán)地址
鏈接:https://pan.baidu.com/s/1JAJ0BdGBAxxlaqWS-kgMbg?pwd=5t9h
提取碼:5t9h

3.2 安裝

解壓文件夾到安裝目錄
使用管理員模式打開(kāi)exe安裝程序


image.png

安裝完成后,如下圖


image.png

image.png
  1. systemctl 文件修改


    image.png

wsl安裝的centos無(wú)法執(zhí)行systemctl命令,需要修改文件/usr/bin/systemctl

#備份systemctl文件
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
#若文件無(wú)法獲取,則手動(dòng)替換文件,注意編碼格式為unix 
https://github.com/gdraheim/docker-systemctl-replacement/blob/master/files/docker/systemctl.py
#設(shè)置可執(zhí)行
chmod +x /usr/bin/systemctl

5.ssh配置

#設(shè)置密鑰,生成過(guò)程 全部直接按回車(chē)
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
#重啟查看狀態(tài)
systemctl restart sshd
systemctl status sshd
#若啟動(dòng)失敗,查看原因
sudo sshd -t
#設(shè)置登錄密碼
sudo  passwd root
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容