Access wsl with ssh.(WSL的SSH访问,SSH,Windows,LAN,WSL,Linux,Frp)

Symbols annotation

$WindowsLocaIP        # Windows local ip
$ForwardLocalPort     # Windows forworad port for ssh access
$LinuxUsername        # Linux user name
$LinuxSubnetIP        # Linux subnet ip
$LinuxListeningPort   # Linux listening port  for ssh access
$LinuxPassword        # Linux login password
$FrpServerSite        # Frp server site
$FrpIP                # Frp server ip
$FrpPort              # Frp server forward port

Windows commands

netsh advfirewall firewall add rule name="Open Port $ForwardLocalPort for WSL Linux" dir=in action=allow protocol=TCP localport=$ForwardLocalPort

netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=$ForwardLocalPort connectaddress=$LinuxSubnetIP connectport=$LinuxListeningPort

netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=$ForwardLocalPort

netsh interface portproxy show all

netsh int portproxy reset all

wsl -u username

Linux commands

passwd #password
exit

Actions for sshd configuration on linux

Check ip:

hostname
hostname -i
hostname -I
ifconfig

Open sshd_config:

sudo apt install openssh-server
cd /etc/ssh/
sudo vim sshd_config
$LinuxPassword

Add:

ListenAddress 0.0.0.0

Uncomment and modify:

Port $LinuxListeningPort

Start server and check status:

sudo service ssh start
service ssh status

Enable autostart for ssh server:

sudo systemctl enable ssh

Actions for sshd access on LAN remote windows terminal

Port forward configuration

netsh advfirewall firewall add rule name="Open Port $ForwardLocalPort for WSL Linux" dir=in action=allow protocol=TCP localport=$ForwardLocalPort

netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=$ForwardLocalPort connectaddress=$LinuxSubnetIP connectport=$LinuxListeningPort

SSH access (Linux username: $LinuxUsername, windows ip: $WindowsLocaIP):

ssh -p $ForwardLocalPort $LinuxUsername@$WindowsLocaIP
yes
$LinuxPassword #WSL passwords

Actions for sshd access on local windows terminal

SSH access with Linux subnet ip (Linux username: $LinuxUsername, Linux ip: $LinuxSubnetIP):

ssh $LinuxUsername@$LinuxSubnetIP
yes
$LinuxPassword #WSL passwords

Actions for sshd access on frp server remote windows terminal

SakuraFrp

Create frp Tunnel using sakura frp (local ip: $WindowsLocaIP, forward local port: $ForwardLocalPort):

2024/07/28 15:06:31 I Tunnel/MyTunnel [53/455749/0c9c] 限速已更新: 10 Mibit/s
  Tunnel/MyTunnel TCP 类型隧道启动成功
  Tunnel/MyTunnel 使用 [$FrpServerSite:$FrpPort] 来连接到你的隧道
  Tunnel/MyTunnel 或使用 IP 地址连接(不推荐): [$FrpIP:$FrpPort]

SSH access with frp ip (Linux username: $LinuxUsername, frp server ip: $FrpIP):

ssh -p $FrpPort $LinuxUsername@$FrpIP
yes
$LinuxPassword #WSL passwords

About sshd server configuration

For windows system, the configuration of sshd_config file is restricted according to documentation at sshd_config · PowerShell.

Specifically for AuthenticationMethods option, the options have a large scale reduction compared with Linux Man Pages.

Available authentication methods are password and publickey.

So one can’t set AuthenticationMethods to none for windows hosts which has no passwords to log in, thus making it a necessity to create a password for the system.

To establish a password-less ssh connection, key-based authentication with windows hosts, one must put the publick-key file content into the administrators_authorized_keys under C:\ProgramData\ssh.

References

  1. Windows Server Management

  2. Windows Commands

  3. Windows Powershell Language

  4. WSL OpenSSH Q&A

  5. SSH to WSL Blog

  6. Powershell sshd_confg)

  7. Linux sshd_config Man Pages

  8. Sakura Frp Documentation

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rabxs

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值