默认用户

管理员权限打开powershell,关掉子系统

wsl --shutdown

设置默认用户

<wsl> config --default-user <username>

ubuntu 2204版本设置root为默认

ubuntu2204 config --default-user root

换源中科大

sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list && apt update

开启ssh

安装

sudo apt update
sudo apt install openssh-server

配置

默认密码wslrootpwd,可以修改

echo 'root:wslrootpwd' | sudo chpasswd
echo -e "# This is the sshd server system-wide configuration file. See\n# sshd_config(5) for more information.\n\n# What ports, IPs and protocols we listen for\nPort 22\n# Use these options to restrict which interfaces/protocols sshd will bind to\nListenAddress 0.0.0.0\nProtocol 2\n\n# Authentication:\nPermitRootLogin yes\n# Change to yes to enable challenge-response passwords (beware issues with\n# some PAM modules and threads)\nChallengeResponseAuthentication yes\nPasswordAuthentication yes\n\n# AcceptEnv LANG LC_*\n# Allow client to pass locale environment variables\n\n# Subsystem sftp /usr/lib/openssh/sftp-server" > /etc/ssh/sshd_config
sudo service ssh restart

获取wsl的ip

ip addr

比如

eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:05:40:ad brd ff:ff:ff:ff:ff:ff
    inet 172.24.178.150/20 brd 172.24.191.255 scope global eth0

ip就是172.24.178.150
ssh链接即可

禁用windows环境变量

防止本地的部分变量污染wsl内部

在wsl 的 ubuntu中编辑/etc/wsl.conf,输入:

[interop]
enabled = false
appendWindowsPath = false

退出保存之后,需要重启wsl。

修改host模式

便于使用win的科学工具

%USERPROFILE%目录下的.wslconfig文件中添加如下配置

[experimental]
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true

重启wsl2即可

后台运行

可以写成脚本更方便

wsl --exec dbus-launch true

Last modification:March 7, 2024
如果觉得我的文章对你有用,请随意赞赏