Skip to content

Instantly share code, notes, and snippets.

@myriaglot
Created May 27, 2026 15:28
Show Gist options
  • Select an option

  • Save myriaglot/b77052c530e603ba104eb99c672d8a7c to your computer and use it in GitHub Desktop.

Select an option

Save myriaglot/b77052c530e603ba104eb99c672d8a7c to your computer and use it in GitHub Desktop.
quick guide to generating your ssh keys on linux

Setting up SSH keys with the correct permissions is a classic "do it once, do it right" task. If the permissions are too loose, SSH will actually refuse to use the keys for security reasons.

Here is the quick, step-by-step guide to generating an Ed25519 key pair and setting the exact permissions needed for your ~/.ssh directory and files.


Step 1: Generate the Ed25519 Key Pair

Open your terminal and run the following command. The -t flag specifies the type, and -C adds a comment (usually your email) to help you identify the key.

ssh-keygen -t ed25519 -C "your_email@example.com"
  • File location: It will ask where to save the key. Press Enter to accept the default location (~/.ssh/id_ed25519).
  • Passphrase: It will ask for a passphrase. This adds an extra layer of security. Type one in, or press Enter to leave it empty (though a passphrase is highly recommended).

Step 2: Set the Correct chmod Permissions

To secure your keys, you need to restrict access so that only you (the owner) can read or modify them.

Run these commands in your terminal:

# 1. Set permissions for the .ssh directory itself
chmod 700 ~/.ssh

# 2. Set permissions for your private key (Crucial! Nobody else should see this)
chmod 600 ~/.ssh/id_ed25519

# 3. Set permissions for your public key (Can be slightly more relaxed)
chmod 644 ~/.ssh/id_ed25519.pub

If you also have an authorized_keys file in that directory (where you paste keys allowed to log into your machine), it should also be set to 600:

chmod 600 ~/.ssh/authorized_keys

Summary Table of Permissions

Here is a quick reference for exactly what the chmod permissions mean for your SSH setup:

Directory / File Recommended chmod What it means
~/.ssh/ (Directory) 700 Only the owner can read, write, and enter the directory.
id_ed25519 (Private Key) 600 Only the owner can read and write to this file.
id_ed25519.pub (Public Key) 644 Owner can read/write; others can only read it.
authorized_keys (If exists) 600 Only the owner can read and write to this file.

Quick Verification

You can double-check that you got it right by running:

ls -la ~/.ssh

You should see drwx------ for the . (current directory) and -rw------- for your private key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment