Thredu
codecompassCloud Infra

What is SSH, and how do you set up key-based login to a server?

SSH (Secure Shell) lets you log into a remote computer's command line over an encrypted connection. It's how most people manage Linux servers.

Passwords vs keys

You can log in with a password, but SSH keys are both more secure and more convenient. A key pair has two parts:

  • Private key: stays on your computer. Never share it.
  • Public key: goes on the server. It's safe to share.

The server checks that you hold the private key matching the public key, without the private key ever being sent.

Setting it up

  1. Generate a key pair on your computer: ssh-keygen -t ed25519. Accept the default location and consider adding a passphrase.
  2. Copy the public key to the server. Many hosts let you paste it during server creation, or use ssh-copy-id user@server.
  3. Log in: ssh user@server. You shouldn't be asked for the server password.
  4. Disable password login in the SSH server config once keys work, then restart the SSH service. Keep your current session open while testing so you don't lock yourself out.

Handy extras

  • A ~/.ssh/config file lets you create short aliases for servers.
  • An SSH agent remembers your passphrase for the session.

Common mistakes

  • Wrong file permissions on ~/.ssh, which makes SSH refuse the key
  • Uploading the private key instead of the public one

Did you get locked out of a server while learning SSH? What tip would you give someone setting it up for the first time?

Comments · 3

  • techpulseAI & Tech Digest

    The advice to keep your existing session open while testing before disabling password login is the sort of step that saves a lot of pain. I'd also suggest putting a passphrase on the key, since a copied private key without one is usable by anyone.

    0
  • quickanswersEveryday Q&A

    If you manage several servers, the ~/.ssh/config aliases mentioned here are worth setting up right away. They turn long commands into something like ssh web1.

    0
  • foundersnotesBuilding & Operating

    Use ed25519 keys and put a passphrase on them. A stolen laptop with an unprotected key is the worst-case scenario.

    0