EN · $ USD
Security, Backups and Cloud Storage

How to Create an SSH Key and Disable Password Login

7 min read Updated: Sunucu Atlas technical team

In short

To create an SSH key, run ssh-keygen -t ed25519 on your own computer; it generates a private key (id_ed25519) and a public key (id_ed25519.pub). Add the public key to ~/.ssh/authorized_keys on the server with ssh-copy-id, test key-based login, then set PasswordAuthentication no in the sshd configuration to disable password login.

In this guide
  1. What Is an SSH Key, and Why Is It Safer Than a Password?
  2. 1. Generate the Key Pair
  3. 2. Copy the Public Key to the Server
  4. 3. Test Key-Based Login
  5. 4. Disable Password Login
  6. 5. Checklist So You Do Not Lock Yourself Out
  7. Troubleshooting: Permission denied (publickey)
  8. Working with Multiple Servers and Keys
  9. Good Habits for Key Management
  10. Next Step

Creating an SSH key takes a single command: run ssh-keygen -t ed25519 on your own computer and you get a key pair. After uploading the public key to the server and testing key-based login, you disable password login. From then on, password-guessing attacks against your server go nowhere. This guide shows every step for Windows, macOS and Linux and covers the most important part: not locking yourself out of the server when you turn passwords off.

What Is an SSH Key, and Why Is It Safer Than a Password?

An SSH key is an authentication method made of two mathematically linked files:

  • Private key: Stays only on your computer and is never shared. Its default name is id_ed25519.
  • Public key: Uploaded to the server and safe to share. Its default name is id_ed25519.pub.

When you connect, the server asks you to prove that you hold the private key; the private key itself is never sent over the network. Unlike a password, it cannot be guessed, cannot be tried in a dictionary attack and will not show up in a leaked password list.

Why ed25519? Ed25519 is a modern elliptic-curve algorithm. It delivers strong security with a short key size, it is fast and it is supported by every current OpenSSH release. Unless you need to connect to a very old system, choose ed25519 over RSA.

1. Generate the Key Pair

Run this command on your own computer, not on the server. Use PowerShell or Windows Terminal on Windows 10/11 and Terminal on macOS and Linux; the command is the same:

ssh-keygen -t ed25519 -C "dizustu-2026"
  1. When asked where to save the key, press Enter to accept the default (~/.ssh/id_ed25519, or C:\Users\<username>\.ssh\id_ed25519 on Windows).
  2. Set a passphrase (a password for the key). It keeps the private key file from being used on its own even if it is stolen. You can leave it empty, but that is not recommended.
  3. The comment you set with -C helps you tell which key belongs to which device on the server.

Skip Typing the Passphrase Every Time: ssh-agent

ssh-agent keeps your unlocked key in memory for the session. On Windows, in PowerShell opened as administrator:

Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519

On macOS, to save the passphrase in your Keychain:

ssh-add --apple-use-keychain ~/.ssh/id_ed25519

2. Copy the Public Key to the Server

macOS and Linux: ssh-copy-id

ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@203.0.113.10

The command asks for the server password once, appends the public key to ~/.ssh/authorized_keys and sets the correct file permissions.

Windows: A PowerShell One-Liner

The Windows OpenSSH client does not include ssh-copy-id. This command does the same job:

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh deploy@203.0.113.10 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

If You Use PuTTY

  1. Open PuTTYgen, choose EdDSA (Ed25519) as the key type and click Generate.
  2. Enter a passphrase and save the private key as a .ppk file.
  3. Copy the single line in the Public key for pasting into OpenSSH authorized_keys file box at the top and add it as a new line to ~/.ssh/authorized_keys on the server.
  4. In PuTTY, select the .ppk file under Connection > SSH > Auth > Credentials.

3. Test Key-Based Login

Before turning passwords off, prove that the key actually works. Open a new terminal and try to connect with password authentication disabled:

ssh -o PasswordAuthentication=no deploy@203.0.113.10

If you get in without being asked for the server password (only your passphrase), the key is installed correctly. If you get Permission denied (publickey), do not move on to the next section; work through the troubleshooting steps below first.

4. Disable Password Login

On Ubuntu and Debian, the main configuration file /etc/ssh/sshd_config includes the /etc/ssh/sshd_config.d/*.conf files at the very top. OpenSSH uses the first value it reads for each setting and reads these files in alphabetical order. On some installs, a 50-cloud-init.conf file added by cloud setup tools may contain PasswordAuthentication yes; to make sure your setting wins, start your file name with a lower number:

sudo nano /etc/ssh/sshd_config.d/01-anahtar-zorunlu.conf
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
PermitRootLogin prohibit-password

PermitRootLogin prohibit-password allows root to log in with a key only. If you work with a separate sudo user, set it to no to disable root login entirely.

sudo sshd -t                     # syntax check, prints nothing if there are no errors
sudo sshd -T | grep -E 'passwordauthentication|permitrootlogin|kbdinteractive'
sudo systemctl reload ssh

If you do not see passwordauthentication no in the sshd -T output, another file is overriding your setting; find it with grep -ri passwordauthentication /etc/ssh/.

5. Checklist So You Do Not Lock Yourself Out

  • Keep your current session open. The reload command does not drop open connections; the new setting applies only to new connections. If something goes wrong, you can fix it from the open session.
  • Test from a new terminal: ssh deploy@203.0.113.10 should succeed.
  • Confirm that passwords are really off: ssh -o PubkeyAuthentication=no deploy@203.0.113.10 should be rejected with Permission denied (publickey).
  • Verify sudo: If you disabled root login, check that sudo whoami returns root for the user you log in with by key.
  • Prepare a backup way in: Add a second device's public key to the authorized_keys file too, and keep an encrypted backup of your private key somewhere safe.

Troubleshooting: Permission denied (publickey)

The most common cause is wrong file permissions or ownership. For security, the SSH server ignores key files that other users can write to:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R deploy:deploy ~/.ssh

Other possible causes:

  • The public key line got split when copied, or extra characters were added at the start or end.
  • The key was added to the wrong user's authorized_keys file (for example, root instead of deploy).
  • The client is offering a different key; check the verbose output with ssh -i ~/.ssh/id_ed25519 -v deploy@203.0.113.10.

To see the cause on the server side, check the logs:

sudo journalctl -u ssh -n 50
# or
sudo tail -n 50 /var/log/auth.log

If you have lost all access, you can open a support ticket with Sunucu Atlas for help or, as a last resort, reinstall the server; because a reinstall wipes the data on the disk, regular backups matter.

Working with Multiple Servers and Keys

Over time you will have several keys for different servers, different users and services like GitHub. To make sure the client uses the right key for each connection, add entries to the ~/.ssh/config file on your computer:

Host atlas-web
    HostName 203.0.113.10
    User deploy
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes

Host atlas-db
    HostName 203.0.113.11
    User deploy
    IdentityFile ~/.ssh/id_ed25519_db
    IdentitiesOnly yes

Now all you need to type is ssh atlas-web. The IdentitiesOnly yes line matters: if ssh-agent holds many keys, the client tries them one by one and can hit the server's MaxAuthTries limit before reaching the right key, giving you a Too many authentication failures error. This line makes the client try only the key you specify.

To generate a separate key for a specific purpose, set the file name with -f:

ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_db -C "db-sunucusu"

If a CI/CD system needs to connect to the server, do not use your personal key; generate a separate key for that job and grant access only to the user it needs. That way, when you want to shut off the automation, deleting a single line is enough.

Good Habits for Key Management

  • Generate a separate key for each device; if a device is lost, you only delete its line from the authorized_keys file.
  • Never send a private key by email, through a messaging app or to a repository.
  • Remove the keys of people who leave the team on the same day.
  • Review the authorized_keys file on the server from time to time; a line you do not recognize can be a sign that the server has been compromised. The comment field (-C) makes this check easier.
  • To see a key's fingerprint, use ssh-keygen -lf ~/.ssh/id_ed25519.pub; compare it with the fingerprint in the server logs to tell which key was used to log in.
  • You do not need to regenerate a key to change its passphrase: ssh-keygen -p -f ~/.ssh/id_ed25519 is enough.
  • Even with passwords disabled, blocking brute-force attempts with Fail2ban keeps your logs clean.

Next Step

Key-based login is the cornerstone of server security, but it is not the only step. If you have not made your first connection yet, start with How to SSH Into a Server; to finish basic hardening, continue with the First 10 Security Steps for a New Ubuntu Server checklist.

If you are looking for a server to apply these steps on, Sunucu Atlas's Intel Premium VDS plans and the high single-core performance Ryzen Premium VDS plans in our Istanbul data center come with KVM virtualization, NVMe storage and full root access. If you are starting with a small project, SA-XEON-1, with 2 vCPUs and 2 GB of RAM, is plenty for practicing SSH keys and hardening.

Frequently asked questions

What is the command to create an SSH key?

Run ssh-keygen -t ed25519 on your own computer. The command creates id_ed25519 (private) and id_ed25519.pub (public) in the ~/.ssh folder.

Should I use RSA or ed25519?

On current systems, prefer ed25519; it provides strong security with a shorter key and is fast. RSA is only needed if you must connect to very old systems that do not support ed25519.

How do I copy my public key to the server on Windows without ssh-copy-id?

In PowerShell, read the public key file with the type command and pipe it over ssh into ~/.ssh/authorized_keys on the server. Alternatively, copy the key line and paste it into that file on the server by hand.

I set PasswordAuthentication no, but password login still works. Why?

Most likely another file under /etc/ssh/sshd_config.d, such as 50-cloud-init.conf, is read first and sets the value to yes. Name your own file with a low number such as 01- and confirm the effective value with the sshd -T output.

What happens if I lose my private key?

You can no longer log in with that key. That is why you should also add a second device's key to the server and keep an encrypted backup of your private key somewhere safe.

For this guide

Recommended plans

Intel and Ryzen Premium VDS plans come with full root access, so you control every sshd setting from day one, including uploading your SSH key and disabling password login.

SA-XEON-1

XEON
Recommended

2 GB RAM

$2.95/mo

+VAT

  • Processor2 vCPU
  • ModelIntel Xeon
  • Disk30 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

SA-XEON-2

XEON

4 GB RAM

$3.93/mo

+VAT

  • Processor2 vCPU
  • ModelIntel Xeon
  • Disk40 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

SA-XEON-3

XEON

6 GB RAM

$4.91/mo

+VAT

  • Processor2 vCPU
  • ModelIntel Xeon
  • Disk50 GB NVMe
  • LocationIstanbul
  • Port: 1G Port
  • Traffic: Fair use
  • Virtualization: KVM
  • Multi-layer DDoS protection

Intel Premium VDS — tüm paketler Ryzen Premium VDS — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.