To set up SSH for WSL, start by installing and starting the SSH server on WSL using the commands sudo apt install ssh, sudo systemctl start ssh, and sudo systemctl enable ssh. Next, set up port forwarding in Windows by running the command netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=22 connectaddress=127.0.0.1 in PowerShell. You can then connect to your WSL machine using the command ssh user@localhost -p 2222. To enable passwordless login, generate a new SSH key pair on Windows using the command ssh-keygen -t rsa -b 4096. Create a new SSH config file on Windows and add the necessary details, including the hostname, username, and identity file. Copy the public key to the WSL machine and add it to the authorized_keys file using the command ssh your-linux-username@your-server-ip "mkdir -p ~/.ssh && echo '$PUBKEY' >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys". After setting up the SSH connection, you can connect to WSL from Windsurf by clicking on the connect to SSH Host button and selecting the remote SSH option. Ensure that your config is set up correctly and that the necessary ports are open. Additionally, be aware of potential issues with file permissions and SSH client installation.
dev.to
dev.to
Create attached notes ...
