All guides
Containers · 6 min · Beginner

Set Up SSH Keys for a Container

Replace the auto-generated password with public-key auth, then disable password login entirely.

Container creation gives you a temporary password so you can log in immediately. Replace it with key-based auth as your first step — it's faster, doesn't leak, and survives password rotation.

Generate a key locally (if you don't have one)

bash
ssh-keygen -t ed25519 -C "you@example.com"
# accept defaults; this produces ~/.ssh/id_ed25519 and ~/.ssh/id_ed25519.pub

Copy your public key into the container

bash
ssh-copy-id -p <PORT> root@<HOST>
# enter the temporary password once

Verify you can now log in without a password:

bash
ssh -p <PORT> root@<HOST>

Disable password auth

Once key auth works, edit the SSH config inside the container and disable password login:

bash
sed -i 's/^#*PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart ssh   # or: service ssh restart