Logging in with SSH can be a pain, and remembering multiple passwords for different computer can drive anyone insane. Luckily there’s a way to make things easier and more secure at the same time, by using a authentication pair keys. This can work in both Windows and Linux and is easy to do.
Generate The Key
Firstly open a terminal or command prompt. On Linux it could be One of the following
ALT+F2. To Open command prompt on windows use
Win+R hotkey then type ‘
cmd‘ then hit ok.
Now its time to generate a key, to do so type
ssh-keygen. By default It will ask for a name for the generated key and where to storage it. Leaving it blank and push enter. Be careful if you run ssh-keygen again it will overwrite the original key and you won’t be able to authenticate with any servers that have used that key.
Its optional to use a passphrase, as it another layer of security. Using it will cause it to ask for the passphrase each time the key is used. This is working against what we trying to do, but its a good idea especially if this is a work computer or a mobile computer.
ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (C:\Users\User/.ssh/id_rsa): *See Note Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in 2. Your public key has been saved in id_rsa.pub. The key fingerprint is: SHA256:Aclu/7/a/E7ZxENwoJPx23/k+Ur7/ITFKQYehnz4QgY User@Computer The key's randomart image is: +---[RSA 3072]----+ | ..E . o.. | | o.o o = o | | . .* O . . | | o o.= + +o.| | . .S. o + +*| | . . . .O+| | . =.*| | .o o +o| | .o=+=o*| +----[SHA256]-----+
Note: if you change the filename you save it as you need to have ssh client point to that file to use it. example “
ssh UserName@ComputerAddress -i .ssh/YourKeyFile“
Getting the Key To The Computer
Now the Key needs to be copy over to the user profile on the SSH server on the other side.
Go to your home directory
"cd %homepath%” and type “
type .ssh/id_rsa.pub | ssh ” replace all user names and file names with yours. it should ask for your user password for that server and then copy.
UserName@ComputerAddress "cat >> .ssh/authorized_keys"
Go to your home directory “
cd ~“) and type “
cat .ssh/id_rsa.pub | ssh UserName@ComputerAddress "cat >> .ssh/authorized_keys"” replace all username and with yours. it should ask for your user password for that server and then copy.
That’s all there’s to it, now just ssh into the computer. You should be able to login without a password.
Read More about SSH at the official site manual