修改apt镜像

1
2
3
4
5
6
7
8
9
# 因为默认是最新版本,这里是 debian 12 的 镜像地址
echo "deb http://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free non-free-firmware contrib
deb http://mirrors.aliyun.com/debian-security/ bookworm-security main
deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main
deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main non-free non-free-firmware contrib
deb http://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib
deb-src http://mirrors.aliyun.com/debian/ bookworm-backports main non-free non-free-firmware contrib" > /etc/apt/soruces.list

更多地址可查看阿里云Debian镜像

修改 root 密码

1
2
wsl --user root # 使用 root 进入 wsl
passwd # 修改 root 密码

相关设置

设置以官方文档为准,可能因为版本存在部分差异

局域网访问 WSL, 使用系统代理等

1
2
3
4
5
6
7
# 用户目录下 .wslconfig
[wsl2]
networkingMode=mirrored # 镜像模式,会使用跟 windows 相同的ip
dnsTunneling=true
autoProxy=true # 使用 windows 系统代理
[experimental]
hostAddressLoopback=true # 使 windows 可以通过 ip 正常访问 wsl

修改系统默认使用 root 登录

1
2
3
4
5
# WSL 系统中 /etc/wsl.conf
[boot]
systemd=true # 开启 systemd
[user]
default="root" # 默认启动用户

有什么进入系统需要执行的命令,可以加到~/.bashrc

1
2
3
4
5
6
# ~/.bashrc 文件
# 例如:如果mysql数据库没启动,启动mysql
if [ -n "`service mysql status | grep not`" ]
then
service mysql start
fi