How to Generate a Public SSH Key for Windows and Linux

SSH keys are used as login credentials, often in place of simple clear text passwords. They work in pairs: we always have a public and a private key. The private key must remain on the local computer which acts as the client: it is used to decrypt information and it must never be shared. The public key, on the other hand, is used to encrypt data and must be copied on the remote server.


To generate an SSH key on Windows 10 or Windows 11, open Command Prompt, PowerShell, or Windows Terminal and type ssh-keygen into the window and then enter a passphrase. The generated SSH key will be stored in the C:\Users\username\.ssh\ folder by default.

Here are the steps to generate an SSH key in the Command Line:

  1. Open the Windows Command Prompt by hitting the Windows key and typing cmd.
  2. Type ssh-keygen and hit Enter. This will automatically generate the SSH keys.
  3. You’ll be prompted to give your key a name and save it in a specific location. If you use the defaults then it will save your keys in C:\Users\[YourUserName]\.ssh.
  4. Next, youlll be asked to enter a passphrase. Entering a password is optional, but it is highly recommended to keep your key secure.


In Linux, creating a public/private SSH key is easy. Open a terminal and type: ssh-keygen -t rsa. Alternatively, you can also use the DSA (Digital Signing Algorithm) technology to create the public/private key by typing ssh-keygen -t dsa.

Here are the steps to generate an SSH key in Linux:

  1. Open a terminal.
  2. Type: ssh-keygen -t rsa.
  3. In the next screen, you should see a prompt that asks for the location to save the key. The default location is the .ssh folder in your Home directory. Press Enter to accept the default setting.
  4. You will be prompted to enter a passphrase – NOT the passphrase to connect to your remote host, but the passphrase to unlock the private key so that no one can access your remote server even if they got a hold of your private key. The passphrase is optional. To leave it blank, just press Enter2.

That’s it! You now know how to generate a public SSH key for both Windows and Linux.

To contact me, send an email anytime or leave a comment below.