Skip to content

Instantly share code, notes, and snippets.

@SomajitDey
Created July 5, 2021 18:56
Show Gist options
  • Save SomajitDey/ec8257ae781234e2a63f3eb731864765 to your computer and use it in GitHub Desktop.
Save SomajitDey/ec8257ae781234e2a63f3eb731864765 to your computer and use it in GitHub Desktop.
Making SSH server work in WSL2

Making SSH server work in WSL2

Ref:

  1. https://gist.github.com/dentechy/de2be62b55cfd234681921d5a8b6be11
  2. https://gist.github.com/zentralwerkstatt/9e6c83e757cdfe430d6710585b2275c7

Steps:

  1. Edit /etc/ssh/sshd_config as follows. Simply uncomment (remove #) the below lines and edit as needed.

    1. Port 2222 # Or any port above 1000
    2. AddressFamily any
    3. ListenAddress 0.0.0.0
    4. ListenAddress ::
    5. PasswordAuthentication yes
  2. Restart sshd as: sudo service ssh --full-restart

  3. If the above step shows error, such as error: sshd: no hostkeys available -- exiting, then generate the keys as follows: sudo ssh-keygen -A. Then restart sshd again (Step 2).

  4. ssh localhost -p 2222 should work now. Enjoy.

Bonus Tip: Use tunnel if you need to make your ssh server (securely) accessible from the internet (across any NAT/Firewall).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment