OpenSSH server is the most commonly used SSH server on Linux systems.
sudo apt install ssh -y
sudo apt install openssh-server
sudo systemctl status ssh
Expected status: inactive (dead)
By default, WSL2 does not support systemd. Alternative is the service command
sudo service ssh status
sudo service ssh start
sudo service ssh enable
Start, restart and enable SSH to start on boot
sudo systemctl start ssh
sudo systemctl restart ssh
sudo systemctl enable ssh
This establishes a remote connection to the SSH server running inside WSL2, which requires that the WSL2 instance is already running and that the SSH server is active.
dpkg -l | grep openssh-server
Check if the SSH daemon (sshd) is present on the system
which sshd
sudo ss -tulpn | grep ssh
Check if ssh installed in PS
ssh -V
Connect from PowerShell
ssh barry75@172.25.185.251
Setting up SSH key-based authentication is a secure and convenient way to connect to your WSL instance without entering your password every time. This is useful for task automation by running scripts.
ssh-keygen -t rsa -b 4096
Accepting defaults in home dir (~/.ssh/) 2 files wwill be created:
mkdir .ssh
Include hidden files
ls -la
Create file authorized_keys
touch authorized_keys
Unix-like systems (including WSL) use LF for line endings, and using CRLF might cause issues. Ensure LF instead of CRLF (VSCode) and check line endings on Linux (no CRLF displayed)
file authorized_keys
Set permissions
chmod 600 ~/.ssh/authorized_keys
ssh barry75@172.25.185.251 -p 22
scp -r -P 22 C:/source barry75@barryonweb.com:/home/barry75