Introduction
Secure Shell (SSH) authenticates by key-pair. Private key on the remote server and the corresponding public key on local machine. When the key matches, user is then authenticated.
Requirements
- System running Windows 10 with OpenSSH client installed
- User account with administrative privileges
- Access to PowerShell
- WinSCP or equivalent
Check if OpenSSH client is installed
On PowerShell run the following command
# Get OpenSSH location and version
Get-Command ssh
Install OpenSSH client
To install OpenSSH, open elevated PowerShell
# Query OpenSSH, will show if OpenSSH already installed
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
# Install OpenSSH client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Generate SSH Keypair
On PowerShell, run the following command to generate SSH keypair
# Generate RSA Key pair for SSH
# Default location for the generated file C:\Users\[Username]\.ssh\id_rsa
ssh-keygen
We can skip the passphrase by hitting Enter when asked.
We will see two files (i.e. id_rsa and id_rsa.pub) in the selected or default directory. We will need to copy .pub file to destination server on the next step
Copy .pub to destination server
Launch WinSCP and login to destination server (File Protocol = SCP).
Once connected, by default the directory we’re in will be /home/[username]/. If not already there, navigate to the directory. Copy the .pub file into the folder in destination server. Next, we’ll need to SSH into the server and copy the content of the file.
Paste the content into /root/.ssh/authorized_keys , appending the file if there’s content already inside the file.
We’ll need root access for the following line
# Check if folder is available, if not create the folder with permission
# To create the folder, use mkdir -p ~/.ssh
ls -l ~/.ssh
# Copy the content of .pub file into authorized_keys file
cat /home/[user]/[filename].pub >> ~/.ssh/authorized_keys
Connecting
Now, we can open PowerShell and run the following command to connect
ssh [user]@[remoteserver]