Skip to Content

Put your key on the server and log in without a password

The server keeps allowed public keys in ~/.ssh/authorized_keys of the account you log in as — one key per line.

Copy the key — from PowerShell (one line)

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh student@203.0.113.10 "umask 077; mkdir -p ~/.ssh; cat >> ~/.ssh/authorized_keys"

You type the account password one last time. On Linux or macOS the same job is ssh-copy-id student@203.0.113.10.

Copy the key — by hand in PuTTY

mkdir -p ~/.ssh && chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys      # paste the ONE line, save
chmod 600 ~/.ssh/authorized_keys

The permissions matter: sshd ignores the file if the folder or file can be written by others.

Tell PuTTY to use the key

  1. Load the lab session.
  2. Connection → SSH → Auth → Credentials → Private key file for authentication: browse to id_ed25519.ppk.
  3. Session → Save. Open it: you are asked for the key passphrase, not the account password.

See it work

ssh -v shows each step of the login. This is a real run:

The client offers the key, the server accepts it, and the line “Authenticated … using publickey” confirms no password was used.
The client offers the key, the server accepts it, and the line “Authenticated … using publickey” confirms no password was used.

When it does not work

#SymptomUsual causeFix
1Still asks for the account passwordKey not loaded in PuTTY, or wrong userCheck Auth → Credentials path; check the user name
2Permission denied (publickey)Key line missing or broken (wrapped onto two lines)cat ~/.ssh/authorized_keys — one line per key
3Key ignored, works for root onlyPermissions too openchmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys
4“Server refused our key”Server does not allow keys, or key type not acceptedAsk the admin to check sshd -T (below)
5“REMOTE HOST IDENTIFICATION HAS CHANGED”Server rebuilt — or someone in the middleConfirm with the admin before deleting the old entry
A refused login looks like this: the server lists the methods it would accept (publickey, keyboard-interactive) and none worked.
A refused login looks like this: the server lists the methods it would accept (publickey, keyboard-interactive) and none worked.

Server side — what is allowed

sshd -T prints the effective server settings. This lab server still accepts passwords; production servers should set passwordauthentication no once every user has a key.
sshd -T prints the effective server settings. This lab server still accepts passwords; production servers should set passwordauthentication no once every user has a key.

Hardening once keys work (admin task, in /etc/ssh/sshd_config.d/10-keys.conf):

PasswordAuthentication no
PermitRootLogin prohibit-password
KbdInteractiveAuthentication no

Then sshd -t && systemctl reload ssh — and keep your current session open until a new session logs in fine.

Try it — password-free login

  1. Install your public key on the lab server.
  2. Log in with PuTTY using the .ppk — you should only be asked for the passphrase.
  3. From PowerShell run ssh -v student@<lab> true and find the line with your fingerprint.
Rating
0 0

There are no comments for now.

to be the first to leave a comment.