If you’re tired of putting a password everything you login via SSH into your server via ssh root@your_server, there are ways to automatically login to your server without requiring you input a password. This is by using the built-in ssh-keygen command available in your Windows 10.
Basically, the ssh-keygen will create an authentication key pairs that you can use for Secure Shell protocol login.
How to login to SSH without Password
To start, open up a command prompt on your Windows 10. Type in your Cortana CMD.
Now, enter the command
ssh-keygen, this will asked to enter a file name for it, make sure to leave it as blank so that it will save the pair as the default filename id_rsa:
Generating public/private rsa key pair. Enter file in which to save the key (C:\Users\YOUR_USERNAME/.ssh/id_rsa):
Now, you’ll be asked to enter a passphrase. To improved security of your RSA key pair add your passphrase in it. You’ll also be asked to re-enter it again.
Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in C:\Users\YOUR_USERNAME/.ssh/id_rsa. Your public key has been saved in C:\Users\YOUR_USERNAME/.ssh/id_rsa.pub. The key fingerprint is: SHA256:3lk4xS/1udKUWtPqo1BtSFpGIufIlZYLhEHxOtiXDQI YOUR_USERNAME@YOUR_DESKTOP The key's randomart image is: +---[RSA 2048]----+ | . .+=o +=o o| | . .o.*+o= +.| | . o oo.*o+=.o| | o o o o.o+=+.| | . + o S .. o..+| | o o o. o o| | o . . . | | . | | | +----[SHA256]-----+
It will then create the id_rsa and id_rsa.pub file in your C:\Users\YOUR_USERNAME\.ssh directory and in the command screen it will show a randomart image.
ssh-copy-id is not a built-in command in Windows 10 (See explanation at the bottom), you need to manually add your public key to your server.
open up the id_rsa.pub file with a notepad and copy the whole text. The file is in C:\Users\YOUR_USERNAME\.ssh\ folder. Example id_rsa.pub file below.
ssh-rsa AAAAC3NzaC1yc2EAAAADAQABAABBAQDs4aYDW+/XeeewahNS3JO9lxxREYdEcJEccQIMHixnVcaQOzXwiNIJ5HNbHpv5lk2YgcPSffPLcX6lQruLbSt3HDjNl3Q76P81xuPUscCeP37ulZXVuQoaWeqTlW36AXWeZsqQowLxih8+ydl2FlIv/Zytv2AAJk3SKEiGuDBJciCAvVTgb0bNGn93X3tohBpM79mRWuCCWSoRbi+u8kumUpt9eeXgmte82UI9JVKb0qj/G3XJp84s0Evtk7L+HhZ+/v6VmfQCsC/lrOKwGezbVGwI/3Xz64kudCmvkfmWOEGFOG+v0MMCA91mDrKr4Tc7nj6yYTE1kIm0y3DdLS7l YOUR_USERNAME@YOUR_DESKTOP
Now, you need to login to your server via SSH with password as of now
ssh root@YOUR_SERVER. Then you need to edit or make a file authorized_keys via vim. Enter this command:
Then paste the content of your id_rsa.pub on it or if it has existing keys, just paste it on the bottom. Then don’t forget to save it :wq.
If you have problem where there is ^M showing, especially if there are existing keys, just type this command
e ++ff=dos and those ^M will be converted to normal lines.
After that, you can now login to your CMD via
ssh root@YOUR_SERVER without requiring for entering your password.
SSH-Copy-ID is not available on Windows 10
The only problem with windows 10 is there is no ssh-copy-id command available in the OS and you need to manually add the pair into your server. You’ll get an error ‘ssh-copy-id’ is not recognized as an internal or external command, operable program or batch file.’ when you try to input it.
Load Key Operation not Permitted
If you’re getting an error saying “Load key “C:\Users\YOUR_USERNAME/.ssh/id_rsa”: Operation not permitted”, this means you’re trying to create a folder in your .ssh directory named id_rsa.
Some people create these folder because they though the key was saved in that folder when they entered the ssh-keygen which says the following:
Generating public/private rsa key pair. Enter file in which to save the key (C:\Users\YOUR_USERNAME/.ssh/id_rsa): sample Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in sample. Your public key has been saved in sample.pub.
This happens, when you named the file when saving the ssh-keygen, make sure to leave it as blank to make sure the private key is save as the default id_rsa and id_rsa.pub.