To use SSH keys on Windows for secure authentication, you can follow these steps:
- OpenSSH Installation:
Ensure that you have the OpenSSH feature installed on your Windows machine. If you’re using Windows 10 or later, it comes with an OpenSSH client and server feature built-in.
To check if it’s installed, you can go to “Settings” > “Apps” > “Optional Features” and look for “OpenSSH Client” and “OpenSSH Server.” If they’re not installed, you can install them from the “Optional Features” section.
- Generate an SSH Key Pair:
To generate an SSH key pair, you can use the
ssh-keygencommand in PowerShell or Command Prompt. Open PowerShell or Command Prompt and run:shell
ssh-keygen -t rsa -b 4096
This command generates a 4096-bit RSA key pair. You can specify a different key type or size if you prefer. It will also prompt you to choose a location to save the key files (usually in your user directory, under
- Copy the Public Key:
After generating the key pair, you’ll have two files in your
id_rsa(private key) and
id_rsa.pub(public key). You need to copy the content of the public key file (
id_rsa.pub) to the remote server where you want to authenticate.
You can use a tool like
catto display the public key and then copy it:shell
- Configure SSH on the Remote Server:
On the remote server, you need to add your public key to the
~/.ssh/authorized_keysfile in your user’s home directory. You can do this manually by pasting the public key or by using the
ssh-copy-idcommand (if available):shell
usernamewith your username on the remote server and
remote-serverwith the server’s hostname or IP address.
- Test SSH Connection:
Once your public key is added to the
authorized_keysfile on the remote server, you should be able to SSH into the server without a password:shell
It should log you in without prompting for a password because the SSH key is used for authentication.
That’s it! You’ve successfully set up SSH key authentication on Windows for connecting to a remote server. Make sure to keep your private key (
id_rsa) secure and never share it with anyone.