bash
sudo passwd root
su
apt update && apt upgrade
apt install net-tools openssh-server
vi /etc/ssh/sshd_config
:%s/#Port 22/Port 2222
:%s/#PasswordAuthentication no/PasswordAuthentication yes
su
echo "%sudo ALL=NOPASSWD: /etc/init.d/ssh" >> /etc/sudoers
/etc/init.d/ssh restart
schtasks /create /ru username /rp /sc onstart /tn wsl2_network /tr c:\wsl2_network\wsl2_network.bat /rl highest
sshd: no hostkeys available -- exiting. 발생시
sudo ssh-keygen -A
@echo off
powershell.exe -ExecutionPolicy Bypass -File C:\wsl2_network\wsl2_network.ps1
bash -c "sudo /etc/init.d/ssh restart"
exit
$remoteport = wsl hostname -I
#[Ports]
#All the ports you want to forward separated by coma
$ports=@(80,443,10000,2222,3000,5000);
#[Static ip]
#You can change the addr to your ip config to listen to a specific address
$addr='0.0.0.0';
$ports_a = $ports -join ",";
#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";
#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "netsh interface portproxy reset all";
for( $i = 0; $i -lt $ports.length; $i++ ){
$port = $ports[$i];
iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
}