Free site migration on web hosting plans

ADVEYER
USD / TRYToday's rate (12 November 2026). TRY prices are worked out with it. 50.21 ₺

How to Generate an SSH Key on Your Computer

Generate an SSH key on Windows, macOS or Linux, add it to your server and connect without a password.

Estimated Time
6 minutes
Difficulty
Easy
Steps
5 steps
Last Updated
Terminal running ssh-keygen, a private and a public SSH key, and a server
On This Page

SSH keys let you connect to servers securely without typing a password. This guide shows how to generate an SSH key on Windows, macOS and Linux, add it to a server and connect.

What Is an SSH Key?

The private key stays on the computer, the public key goes into authorized_keys on the server, and no password is asked when connecting
The private key stays with you, the public key goes to the server

SSH keys use asymmetric encryption and come in two parts:

  • Private key: Stays on your computer. Never share it.
  • Public key: Uploaded to the server you want to connect to.

Generating the Key

0 of 5 steps done

  1. Step 1: Open the Terminal

    On macOS and Linux, open the Terminal app. On Windows, you can use "PowerShell" or "Git Bash".

  2. Step 2: Run the Key Generation Command

    Run the following command:

    bash
    ssh-keygen -t rsa -b 4096 -C "email@example.com"
    • -t rsa: Creates an RSA key.
    • -b 4096: Sets the key length to 4096 bits.
    • -C "email@example.com": Adds a comment to the key, usually your email address.
  3. Step 3: Choose Where to Save the Key

    The command asks where to save the key. The default is ~/.ssh/id_rsa; press Enter to accept it. If you already have a key with the same name and don't want to overwrite it, choose a different name.

  4. Step 4: Set a Passphrase (Optional)

    You can protect the key with a passphrase. To create a key without one, leave it blank and press Enter.

  5. Step 5: Check the Generated Files

    Two files are created:

    • id_rsa: Private key. Do not share it.
    • id_rsa.pub: Public key. This is what you add to servers.

    To list them:

    bash
    ls ~/.ssh/

    On Windows, the files are in C:\Users\YourUsername\.ssh\.

Adding the Key to a Server

You can add your public key to a server with one command:

bash
cat ~/.ssh/id_rsa.pub | ssh username@server_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Or copy the public key manually:

bash
cat ~/.ssh/id_rsa.pub

Copy the output, log in to your server and paste it into the ~/.ssh/authorized_keys file.

Connecting with SSH

Once the key is added, you can connect without a password prompt:

bash
ssh username@server_ip

If your private key has a different name:

bash
ssh -i ~/.ssh/your_private_key username@server_ip

Cloud VPS

Flexible virtual servers located in Türkiye

Starting Price

$4.99/mo

View Plans

Frequently Asked Questions

Which key do I upload to the server?

Only the public key (the .pub file). The private key stays on your computer and must never be shared.

Do I need a passphrase?

No, it is optional. A passphrase adds an extra layer of protection to your private key.

Where are the key files on Windows?

In the C:\Users\YourUsername\.ssh\ folder.

Was This Guide Helpful?

Related Guides