WSL
- 配置网络代理
windows 下 user目录创建.wslconfig文件
- 配置wsl远程访问(关闭上述网络代理实验功能)
# WSL2 22 Windows 2222
# Windows
$wsl_ip = (wsl -e hostname -I).Split()[0]
Write-Host "WSL2 IP: $wsl_ip"
# 检查防火墙规则
Get-NetFirewallRule | Where-Object { $_.DisplayName -like "*WSL*" -or $_.DisplayName -like "*SSH*" }
# 如果没有相关规则,添加一条
New-NetFirewallRule -DisplayName "WSL SSH" -Direction Inbound -LocalPort 2222 -Protocol TCP -Action Allow
# 删除旧规则
netsh interface portproxy delete v4tov4 listenport=2222 2>$null
# 添加新规则(Windows 2222 → WSL2 22)
netsh interface portproxy add v4tov4 listenport=2222 connectport=22 connectaddress=$wsl_ip
# 验证规则
netsh interface portproxy show all
Test-NetConnection -Port 2222 -ComputerName 127.0.0.1
Test-NetConnection -Port 22 -ComputerName $wsl_ip
# Linux
# 配置ssh
sudo apt install openssh-server
sudo vi /etc/ssh/sshd_config
Port 22
ListenAddress 0.0.0.0 # 关键修改!允许所有网络接口
PasswordAuthentication yes
PermitRootLogin yes