- Before starting:
- I have tried the
New-ItemProperty
method myself but it keep asking me to type my password and show that my password is wrong, so I tried some other methods and this is working best for me. - This markdown will contain each step from how to set up SSH to service to finally use VSCode to remotely connected to my remote PC. There is a minor bug that when using
nvidia-smi
in terminal, it is not correctly shown. However, you can still use you GPU without any problem in your program. - This walkthrough is novice-friendly, since I am a novice myself, and please leave a comment if anything is confusing or no need to do.
- Thank you for reading, hope you enjoy the journey and have fun using WSL2 remotely!
- I have tried the
- One remote Windows computer and one local computer(any OS you like)
- Public IP address (If not, some technique like NAT traversal is needed)
- VSCode installed in your local machine
-
Installation of SSH on Windows: please refer to Get started with OpenSSH for Windows
-
Installation of SSH on WSL2:
# Run this on WSL2 terminal sudo apt remove openssh-server # To ensure the latest version sudo apt install openssh-server
# Run in powershell/cmd/terminal
ping <windows_ip> # You can obtain <windows_ip> from running ipconfig on windows powershell
# If the connection is OK, please continue to next step
extra step: If not, please follow this to allow ICMP and test connection
- Enter
Control Panel -> System and Security -> Windows Defender Firewall
- Click into
Advanced settings
- Enter
Inbound Rules -> New Rule
- Choose
Custom -> Protocol type: ICMPv4 -> Scope: *Both* Any IP address -> Action: Allow the connection -> Profile: Apply all -> Name: *Any name will work*
extra extra step: If still not working, please check your Internet connection (IP setup or ...)
ssh <WSL2_id>@localhost
# If not working try to re-install SSH service on WSL2
# Run this on windows powershell
# wsl --shutdown
# wsl
# Run this on WSL2
# sudo service ssh restart
# Run this on WSL2
ping google.com
#Run this in WSL2
sudo systemctl enable --now ssh
#In your local machine
ssh -J windows_user@windows_ip wsl_usrs@localhost
Host wsl
HostName localhost
User wsl_user
ProxyJump windows_user@windows_ip
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
- If you want to SSH into your remote machine more easily without typing password every time, you can use
ssh-keygen
in both your local machine and remote Windows. Then copy your content inid_rsa.pub
into~/.ssh/authorized_keys
local_key -> remote Windows
&remote_Windows_key -> remote WSL2
- If in come cases, your port 22 is blocked as due to the control of your Internet provider, you need to change the
sshd_config
with new<port>
and always remember to restartOpenSSH
when you change the config. Try to follow these steps:- Change the
C:\ProgramData\ssh\sshd_config
- Change firewall settings:
- Enter
Control Panel -> System and Security -> Windows Defender Firewall
- Click into
Advanced settings
- Enter
Inbound Rules -> New Rule
- Choose
Port -> TCP and <port> -> Allow -> all the way Next -> set the Name of the rule
- Enter
- Change the
[2] https://blog.csdn.net/Hydius/article/details/130138387
[3] https://blog.csdn.net/qq_34965596/article/details/119176798