guides  /  ssh.en

Adding my SSH key to your server

How to add my public SSH key to your server. The commands check the key fingerprint, add the key only once and set the correct permissions.

What you need

  • Access to the server (Linux) as the account you want to give me access to.
  • curl or wget and ssh-keygen on the server (usually part of OpenSSH).

This guide adds my public SSH key to your server. After that I log in to the server with the key, without typing a password.

My key

Public SSH key
TypeED25519
Fingerprint (SHA256)SHA256:+zmRgF8O83cBBpFxo8pGdQtMvqjqUBbT1jA79HSTn7M
Filemiroslavkral.eu/files/ssh-key.pub
⚠ Checking the fingerprint The fingerprint on this page only catches a damaged or wrong file. If someone took over the whole website, they could change the fingerprint too. Want stronger proof? Write to me and I will read the fingerprint to you by phone or send it over Signal.

Adding the key

Step 1 Log in to the server

Log in as the user you are giving me access to. The key works only for this user.

For the root account, switch first with sudo -i.

Step 2 Run the commands

Copy the whole block and paste it into the terminal:

bash
url=https://miroslavkral.eu/files/ssh-key.pub
fp=SHA256:+zmRgF8O83cBBpFxo8pGdQtMvqjqUBbT1jA79HSTn7M
key=$(curl -fsSL "$url" 2>/dev/null || wget -qO- "$url")
case "$key" in "ssh-ed25519 "*) got=$(printf '%s\n' "$key" | ssh-keygen -lf - 2>/dev/null | awk '{print $2}') ;; *) got= ;; esac
if [ "$got" = "$fp" ] && [ "$(printf '%s' "$key" | tr -d '\r\n')" = "$key" ]; then
  if mkdir -p ~/.ssh && chmod 700 ~/.ssh &&
     { [ ! -s ~/.ssh/authorized_keys ] || [ -z "$(tail -c1 ~/.ssh/authorized_keys)" ] || echo >> ~/.ssh/authorized_keys; } &&
     { grep -qxF "$key" ~/.ssh/authorized_keys 2>/dev/null || printf '%s\n' "$key" >> ~/.ssh/authorized_keys; } &&
     chmod 600 ~/.ssh/authorized_keys &&
     grep -qxF "$key" ~/.ssh/authorized_keys; then
    echo "OK: key $fp is in ~/.ssh/authorized_keys"
  else
    echo "ERROR: writing the key or setting permissions failed." >&2
  fi
else
  echo "ERROR: key not downloaded or fingerprint mismatch. Nothing changed." >&2
fi

What the commands do:

  • They download the key (curl, or wget) and check that the file holds only this one key, with the right fingerprint. Otherwise they change nothing.
  • They create ~/.ssh with mode 700.
  • If authorized_keys does not end with a newline, they add one at the end. Otherwise the keys would run together on one line.
  • They add the key only once. Running them again is safe.
  • They set authorized_keys to 600. Otherwise SSH ignores the key.
  • If any step fails, they print ERROR: and no OK:.

Step 3 Check the result and write to me

If ERROR: or another error appears, send me the complete output. After OK:, contact me; I will verify that I can log in.

✓ It works when
  • The commands printed OK: key SHA256:... is in ~/.ssh/authorized_keys.
  • You wrote to me and I tested the login.

Manual install (alternative)

You can also download the key yourself and add it as a new line to ~/.ssh/authorized_keys. Before you add it, check the fingerprint with ssh-keygen -lf ssh-key.pub. It must print the fingerprint from the table above.

Download my public key

Removing access

You can remove my access at any time. This command deletes every line with my key, regardless of its comment:

bash
sed -i '/AAAAC3NzaC1lZDI1NTE5AAAAIC1bOpOtVOxptl4QBVzLY2mWMUEuGeh2+0k\/PgoqTYjO/d' ~/.ssh/authorized_keys

Troubleshooting common problems

ERROR is printed
  • Check that the server can reach the internet.
  • The server needs curl or wget. On Debian and Ubuntu, install curl with apt install curl (as root).
  • Does traffic go through a proxy that returns its own page? Then add the key manually (see above).
  • Old OpenSSH (before version 7.2) cannot run the commands. Use the manual install.
The commands worked, but key login fails
  • The key is only set for the user who ran the commands. Tell me which user it is.
  • The home directory must not be writable by the group or others. Otherwise SSH rejects the key.
  • The SSH server settings can block key login. I will check that, write to me.

If nothing helps, write to me: which server, which user, and what the commands printed.

Need help with access?

Related guides

Need it solved, not just read?

When there's no time, remote support is here.

send a message