Setting up SSH server on WSL
WSL is a exciting offer for windows obsessed programmers . It gives all linux flavors within and helps to deliver cross platform applications.
I am currently working on a program which logs in to a remote linux machine via ssh ,execute some commands within it and get back result.
Instead of trying an actual linux machine, WSL comes handy.
Open WSL terminal
Obviously you have to open the terminal,if you want to do anything with it. Open the bash from start menu or through your desktop shortcut.
Reinstall open-ssh server
The existing openssh-server will not be effective , re install by using the following command
sudo apt remove openssh-serversudo apt-get updatesudo apt install openssh-server
Update SSH config to use username/password authentication
Edit the file sshd_config , set PasswordAuthentication to Yes and add a property AllowUsers to your username
sudo vi /etc/ssh/sshd_config
- It will open the vi editor, modify it accordingly
#...... existing entries, leave as it is# modify PasswordAuthentication to yes
PasswordAuthentication yes###...... existing entries
AllowUsers <yourusername>
save it by going to command mode by typing :wq
start the ssh service
sudo service ssh start# If you see the below error , you can ignore it
# initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
#do a full restart
sudo service ssh --full-restart
Connect to ssh
- Use Winscp/putty
- Use the below to connect to it
- host: localhost
- port: 22
- user: <YOUR_USER_NAME>
- pass: <YOUR_WSL_PASSWORD>
Now the SSH server is ready to be connected from anywhere :)