SSH keys are commonly used to securely authenticate when connecting to remote servers via SSH and SFTP (Secure File Transfer Protocol). By creating an SSH key pair, you ensure a safer, password-free way to access your server or transfer files using SFTP. In this guide, we’ll walk you through the steps to generate SSH key pairs on macOS, Linux, and Windows, allowing you to securely manage server access and file transfers.


Creating SSH Key Pair on macOS or Linux
To generate an SSH key pair on macOS or Linux, follow these steps:
- Open Terminal: On macOS, launch the Terminal utility. You can find it by searching for “Terminal” in Spotlight.
- Run the
ssh-keygen
Command: In the Terminal, type the following command and press Enter:ssh-keygen
- Choose a Location for the Keys: You’ll be prompted to specify the location where you want to save the public and private keys. Press Enter to accept the default location:
/Users/your-username/.ssh/id_rsa.pub
- Set a Passphrase (Optional, Recommended): You’ll be asked to enter a passphrase for an extra layer of security. You can either set one or leave it blank by pressing Enter. If you set a passphrase, remember it, as it will be required later.
Note: Don’t confuse the key passphrase with the SSH access password sometimes used in place of a key pair. The key passphrase is used to encrypt your Private Key stored on your system, protecting it from unauthorised access in case someone tinkers with your machine. - Confirm Passphrase: If you’ve set a passphrase, you’ll need to confirm it by entering it again. Otherwise, press Enter to skip.
- Key Generation Complete: Your public and private keys are now created. The public key can be found in the specified directory, typically:
/Users/your-username/.ssh/id_rsa.pub
NOTE: Don’t confuse the key passphrase with SSH access passphrase which is sometimes used instead of the key pair. The key passphrase is used to encrypt your Private Key which will be stored on your system, to protect it from unauthorised access should someone access your machine.
Next, add the public key to the server you want to access, either by following the specific server instructions or by sending it to the server administrator.

Creating SSH Key Pair on Windows
(Source: Microsoft.com https://learn.microsoft.com/en-us/viva/glint/setup/sftp-ssh-key-gen)
If you are using Windows, you’ll need to install an SSH client like PuTTY to generate your SSH key pair.
Here’s how:
- Download PuTTYgen: Download the PuTTY Key Generator (PuTTYgen.exe) from the official site and open the application.
- Select Key Type: In the “Key” section, select
SSH-2 RSA
. - Choose Key Strength: Set the “Number of bits” to at least 2048, but 4096 is recommended for better security.
- Generate the Key: Click the “Generate” button and move your mouse randomly in the blank space to help create the key pair.
- Copy the Public Key: Once the key is generated, copy the full public key from the “Public key for pasting into OpenSSH authorized_keys file” field.
- Save the Key Files: Save the public key as
yourkey-yyyymmdd.pub
, and save the private key by clicking “Save private key”.
Finally, follow your server’s specific instructions to add the public key or send it to the server administrator.
Conclusion
Generating SSH keys is a straightforward process, enhancing the security of your server access. Whether you’re using macOS, Linux, or Windows, this guide helps you set up secure SSH authentication in a few easy steps.
For video tutorials on these processes, check out these links:
Add a comment