Setting Up Windows SSH Server With Public Key Authentication
In this guide, we will walk you through the steps to set up an SSH server on a Windows system and configure it to use public key authentication instead of a password. This enhances security by eliminating the need for password-based access and relying on cryptographic keys for authentication.
Prerequisites
Before you start, ensure you have the following:
- A Windows machine with the SSH server (sshd) installed.
- An SSH client from which you will connect to the Windows server.
Steps to Set Up SSH Server With Public Key Authentication
1. Generate SSH Key Pair on the Client
If you haven’t already, generate an SSH key pair on your client machine. You can use the ssh-keygen
command to do this. Replace [[email protected]]
with your email address.
|
|
This will generate a public key (id_rsa.pub
) and a private key (id_rsa
) in your ~/.ssh
directory.
2. Copy the Public Key to the Server
Now, you need to copy the public key from your client machine to the Windows SSH server. You can use ssh-copy-id
if available, or manually add the public key to the authorized_keys
file on the server.
|
|
Alternatively, manually add the public key to ~/.ssh/authorized_keys
on the Windows server. You can use any text editor to do this, such as Notepad.
|
|
Paste your public key (id_rsa.pub
) content into the authorized_keys
file.
3. Configure SSH Server
Edit the SSH server configuration file located at C:\ProgramData\ssh\sshd_config
. You can use a text editor like Notepad to make the changes.
|
|
Make sure you uncomment (remove the #
at the beginning of) the PubkeyAuthentication
and PasswordAuthentication
lines as shown above. This enforces public key authentication and disables password-based authentication.
4. Restart the SSH Service
To apply the changes, restart the SSH service. You can do this via PowerShell:
|
|
Conclusion
You have successfully set up your Windows SSH server to use public key authentication instead of passwords, which improves the security of your SSH access. Now, you can log in to your Windows server using your private key from the SSH client. Remember to keep your private key secure, and never share it with anyone.