Skip to content
SSH10 min read14.08.2026

SSH Public Key vs Private Key: Authentication Guide

SSH key authentication uses a mathematically related public and private key pair. This guide explains which file can be shared and which one must remain secret.

Public keyPrivate keyED25519Passphrase
Private key credential screen in Varkuna SSH

Public key vs private key

The public key is added to authorized_keys for the server account. The private key remains on your phone, computer or trusted key manager and is never uploaded to the server.

During login, the server verifies cryptographically that the client has the private key without transferring that private key over the network.

KeyWhere is it stored?Can it be shared?Purpose
Public keyOn the destination serverYesDefines which private key may authenticate
Private keyOn the client deviceNoProves possession of the matching key pair

How to generate an SSH key pair

Generate the key on a computer you trust using OpenSSH. ED25519 is a common choice for compact, modern keys on current OpenSSH systems. Ask the administrator about supported key types when legacy compatibility is required.

Choose a clear file name and consider a strong passphrase. A passphrase makes a copied private-key file harder to use directly.

Generate an ED25519 key
ssh-keygen -t ed25519 -a 64 -C "device-or-account-label"
Display the public key
cat ~/.ssh/id_ed25519.pub
Avoid online key generators

Do not trust random websites that generate or ask you to upload a private key. Generate it locally on your trusted device.

How to add the public key to a server

  1. 1
    Get the public key line

    Copy the one-line contents of the .pub file. Do not copy the private-key file.

  2. 2
    Use the intended account

    Install the key in the home directory of the user that will open the SSH session.

  3. 3
    Add it to authorized_keys

    Place the public key on its own line in ~/.ssh/authorized_keys.

  4. 4
    Review permissions

    Confirm secure ownership and permissions for .ssh and authorized_keys.

  5. 5
    Test a new session

    Keep the existing administrator session open until the new key works.

Automatic installation with OpenSSH
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server

Using the private key on Android

Create a credential in the Android SSH client, select the private-key file and enter its passphrase when required. The key passphrase does not have to match the password of the server account.

Transfer the key to the phone through a protected method you control. Remove unnecessary copies from messaging-app or download folders and keep the device screen lock enabled.

Recovery

Keep a protected backup or an alternative administrator path that lets you install a replacement public key if the device is lost.

User keys and server host keys are different

Your public/private user key pair proves your identity to the server. A server host key proves the server’s identity to your client and may be saved as a known-host record.

A host key changed warning does not mean your user private key is broken. The server may have been rebuilt or its host key replaced; verify unexpected changes with the administrator.

SSH key security checklist

Never share the private key

Support staff and server administrators do not need your private-key file.

Use a passphrase

Add another layer of protection, especially for keys stored on portable devices.

Separate keys by context

Different keys for clients, environments or critical servers make revocation and tracking easier.

Remove old keys

Delete public-key lines for lost devices and accounts that are no longer used.

Continue

Put the guide into practice.

Review the related Varkuna product or open its detailed user guide.