系统前置设置
应用后重启系统。
更新 WSL 2 Linux 内核,跳过前面细节直接下载安装补丁
wsl --set-default-version 2
上面将 WSL 2 设置为默认版本,对于已安装的WSL可以行执行wsl --set-version Debian 2
即可将Debian
升级到WSL2版。建议全新安装。
安装Debian
下载Debian
下载完的*.AppxBundle
文件用压缩工具打开,如下图:
解压后的
*.appx
依旧用压缩工具打开,正常解压到单独文件夹即可:解压后双击
debian.exe
安装。
配置软件源
清华源参考, 中科大源参考, 其它源参考
这一步需要用到一些vi
的快捷操作方式: a i o
, dd d0 y0 p
, :wq :q!
sudo cat > /etc/apt/sources.list << EOF
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
deb http://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main contrib non-free
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main contrib non-free
EOF
apt-get update:更新安装列表
apt-get upgrade:升级软件
apt-get install software_name :安装软件
apt-get --purge remove software_name :卸载软件及其配置
apt-get autoremove software_name:卸载软件及其依赖的安装包
dpkg --list:罗列已安装软件
启用 systemd
#cmd命令下:
wsl --update #先更新wsl
wsl --version #查看版本 >0.67.6
# wsl命令下:
sudo echo -e "[boot]\nsystemd=true" | sudo tee -a /etc/wsl.conf
# 重启wsl后生效
# 验证生效否
ps --no-headers -o comm 1
旧版wsl启用systemd
sudo apt install apt-transport-https
sudo wget -O /etc/apt/trusted.gpg.d/wsl-transdebian.gpg https://arkane-systems.github.io/wsl-transdebian/apt/wsl-transdebian.gpg
sudo chmod a+r /etc/apt/trusted.gpg.d/wsl-transdebian.gpg
sudo cat << EOF > /etc/apt/sources.list.d/wsl-transdebian.list
deb https://arkane-systems.github.io/wsl-transdebian/apt/ bullseye main
deb-src https://arkane-systems.github.io/wsl-transdebian/apt/ bullseye main
EOF
sudo apt update
sudo apt -y install systemd-genie
# 启动
wsl genie -s
命令行连接WiFi
# 普通wifi 用nutui图形化操作,或者用如下命令
nmcli dev wifi connect "WiFi的名字" password "WiFi的密码"
# 隐藏wifi
nmcli c add type wifi con-name "自定义连接名称" ifname "无线网卡名称" ssid "WiFi的名字"
nmcli con modify "自定义连接名称" wifi-sec.key-mgmt wpa-psk
nmcli con modify "自定义连接名称" wifi-sec.psk "WiFi的密码"
nmcli con up "自定义连接名称"
Debian in WSL 安装python
apt安装方式
sudo apt-get install python3
python3 -V # check version of python3
sudo apt-get install python3-pip
sudo bash Miniconda3-latest-Linux-x86_64.sh
#一路Enter,一路yes...
#最后选择路径时注意,默认的/root/anaconda3可能权限问题,装完了无法使用
Miniconda3 will now be installed into this location:
/root/miniconda3
- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below
[/root/miniconda3] >>>/home/$USER/anaconda3 #自定义安装路径
#装完后编辑/home/$USER/.bashrc,追加一行
echo 'export PATH="$PATH:/home/$USER/anaconda3/bin"' >> /home/$USER/.bashrc
#软连接
sudo ln -s /opt/anaconda3/bin/python /usr/bin/python
sudo ln -s /opt/anaconda3/bin/pip /usr/bin/pip
sudo ln -s /opt/anaconda3/bin/conda /usr/bin/conda
重新启动shell,设置conda源;批量更新 conda update conda
软连接的操作是为了解决sudo python
提示找不到命令的错误
补足WSL中的ps命令
- 执行完
dpkg
命令后,执行sudo apt-get -f install
- 安装
gdebi
,之后执行sudo gdebi package.deb
会自动安装上依赖文件
直接运行sudo apt-get install procps
会遇到各种依赖版本不适用的问题,所以采用安装deb包的方式补足:procps_3.3.15-2_amd64.deb,依赖libprocps7_3.3.15-2_amd64.deb
使用sudo gdebi package.deb
依次安装libprocps7
和procps
即可补足。
补足后测试效果:ps aux|grep python
安装SSH
方便使用WinSCP连接管理Debian系统的文件
# 查找已装
sudo whereis openssh-server
# 安装
sudo apt-get install openssh-server
# - 修改SSH Server的监听端口,这里修改为33
sudo sed -i '/Port /c Port 33' /etc/ssh/sshd_config
# - 修改SSH Server的监听地址
sudo sed -i '/ListenAddress 0.0.0.0/c ListenAddress 0.0.0.0' /etc/ssh/sshd_config
# - 修改SSH Server允许使用用户名密码的方式登录
sudo sed -i '/PasswordAuthentication /c PasswordAuthentication yes' /etc/ssh/sshd_config
# - 修改SSH Server允许远程root用户登录
sudo sed -i '/PermitRootLogin /c PermitRootLogin yes' /etc/ssh/sshd_config
# - 重启ssh服务
sudo service ssh restart
SSH自动启动
在文件~/.profile
末尾追加一行:sudo service ssh start
sudo sed -i '$a sudo service ssh start' ~/.profile
免密sudo
username自行修改
sudo vi /etc/sudoers.d/passwordless
# 文件内容
username ALL=(ALL) NOPASSWD:ALL
WinSCP提权
# 查看sftp-server执行文件目录:
cat /etc/ssh/sshd_config|grep sftp
Subsystem sftp /usr/lib/openssh/sftp-server
# 编辑/etc/sudoers为特定用户添加执行sftp sudo权限:
# 修改为可写
chmod +w /etc/sudoers
vi /etc/sudoers
# 添加如下字段
username ALL=NOPASSWD: /usr/lib/openssh/sftp-server
# 再次修改为只读
chmod -w /etc/sudoers
静态IP
Windows下修改虚拟网卡vEthernet (WSL)
地址:
netsh interface ipv4 set address "vEthernet (WSL)" static 172.20.176.1 255.255.240.0
wsl中修改~/.bashrc
:
# static ip
if [ "$(ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | head -n 1)" != "172.20.176.29/20" ]; then
sudo ip addr del $(ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | head -n 1) dev eth0
sudo ip addr add 172.20.176.29/20 broadcast 172.20.176.255 dev eth0
sudo ip route add 0.0.0.0/0 via 172.20.176.1 dev eth0
fi