官网参考
打开powershell,运行:wsl --install
proxy.sh
#!/bin/sh
hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
wslip=$(hostname -I | awk '{print $1}')
port=7890
PROXY_HTTP="http://${hostip}:${port}"
set_proxy() {
export http_proxy="${PROXY_HTTP}"
export HTTP_PROXY="${PROXY_HTTP}"
export https_proxy="${PROXY_HTTP}"
export HTTPS_proxy="${PROXY_HTTP}"
}
unset_proxy(){
unset http_proxy
unset HTTP_PROXY
unset https_proxy
unset HTTPS_PROXY
}
test_setting(){
echo "Host ip:" ${hostip}
echo "WSL ip:" ${wslip}
echo "Current proxy:" $https_proxy
}
if [ "$1" = "set" ]
then
set_proxy
elif [ "$1" = "unset" ]
then
unset_proxy
elif [ "$1" = "test" ]
then
test_setting
else
echo "Unsupported arguments."
fi
.bashrc
增加:alias proxy="source /home/zihan/proxy.sh"
. /home/zihan/proxy.sh set
curl google.com
有内容返回则成功wsl list
:查看安装的系统wsl --unregister 系统名
:从wsl移除wsl --list --online or wsl -l -o
:查看可下载的发行ubuntu版本wsl --install -d <Distribution Name>
:下载对应的系统版本Windows Terminal - Microsoft Apps
wsl安装的系统默认无桌面,只能通过命令行控制。这里使用桌面xfce4和微软自带的xrdp(远程桌面)。
sudo apt-get install xrdp
sudo apt-get install xfce4
sudo apt-get install xfce4-goodies
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/max_bpp=32/#max_bpp=32\nmax_bpp=128/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/xserverbpp=24/#xserverbpp=24\nxserverbpp=128/g' /etc/xrdp/xrdp.ini
echo xfce4-session > ~/.xsession
sudo nano /etc/xrdp/startwm.sh ##这一步具体内容如下图
sudo /etc/init.d/xrdp start ##启动远程。stop停止,restart重启
尝试过的东西:
sudo systemctl enable xrdp
sudo systemctl restart xrdp
sudo systemctl status xrdp
sudo adduser xrdp ssl-cert
sudo ufw enable
sudo ufw allow 3390/tcp
sudo ufw reload
sudo ufw status
防火墙设置、等等。最后参考博客:
sudo vim /etc/xrdp/startwm.sh
##在开头添加以下内容
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR
. $HOME/.profile
然后成功连接并在windows的远程桌面中显示成功~