On the server, permit trainee to authenticate with a public key using the normal OpenSSH home-directory setup.
Which file should receive the key?
sshd reads a user's ~/.ssh/authorized_keys for permitted public keys. known_hosts stores client-side host keys.
Detailed explanation
~trainee/.ssh/known_hostsIncorrect. known_hosts records remote host keys for the client.
/etc/ssh/ssh_host_rsa_key.pubIncorrect. This is the server's own host public key.
~trainee/.ssh/configIncorrect. config is a client-side connection configuration file.
~trainee/.ssh/authorized_keysCorrect. authorized_keys lists public keys allowed for the user.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); mkdir -p "$tmp/.ssh"; touch "$tmp/.ssh/authorized_keys"; test -f "$tmp/.ssh/authorized_keys" && printf 'authorized_keys\n'; rm -rf "$tmp"Expected result
authorized_keysKey points
- authorized_keys
- known_hosts is different
- Host key is different
Notes
- Environment: OpenSSHのファイル役割 / 一時ディレクトリ
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Host key
A server identity key used by SSH clients to detect a changed endpoint.
User key
A key pair used to authenticate a user to an SSH server.
Port forwarding
An SSH tunnel that carries traffic between a local, remote, or dynamic endpoint.