Sunday, November 9, 2025

Install , configure, anable ssh server on wsl windows 11 ubuntu

 
search terms:
https://www.google.com/search?q=install+ssh+ubuntu22.04+wsl&rlz=1C1PNKB_enUS1187US1187&oq=install+ssh+ubuntu22.04+wsl&gs_lcrp=EgZjaHJvbWUyBggAEEUYOdIBCDc0NTdqMGo3qAIAsAIA&sourceid=chrome&ie=UTF-8&zx=1762747609120&no_sw_cr=1

1. Update and Install OpenSSH Server in WSL:
Open your Ubuntu 22.04 WSL distribution and Update the package lists.
Code
  sudo apt update
Install the OpenSSH server.
Code
  sudo apt install openssh-server
enable and start the ssh service.
Code
  sudo systemctl enable ssh --now
2. Configure SSH in WSL (Optional but Recommended):
  • Edit the SSH configuration file to enhance security (e.g., change the default port, disable password authentication for key-based authentication):
Code
  sudo nano /etc/ssh/sshd_config
  • Modify or add lines as needed (e.g., Port 2222PasswordAuthentication noPubkeyAuthentication yes).
  • Save and exit the file.
  • Restart the SSH service for changes to take effect:
Code
  sudo service ssh restart
3. Set Up Port Forwarding on Windows:
  • Open PowerShell as Administrator on your Windows host.
  • Get the IP address of your WSL instance and set up port forwarding. Replace 2222 with your chosen SSH port if you changed it in sshd_config:
Code
  $wsl_ip = (wsl hostname -I).trim()  netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=2222 connectaddress=$wsl_ip
4. Configure Windows Firewall:
  • Open Windows Defender Firewall with Advanced Security.
  • Create a new Inbound Rule:
    • Select "Port" and click Next.
    • Choose "TCP" and enter the port number you are using for SSH (e.g., 2222).
    • Allow the connection and apply the rule to all profiles. 
    • Name the rule (e.g., "WSL SSH") and finish the wizard. 
5. Generate and Copy SSH Key (for key-based authentication):
  • Generate Key on Client (e.g., your Windows machine or another remote machine):
Oops, something we

--30--

No comments:

Post a Comment