Linux and Command-Line Basics
You created a public-key authentication key pair with ssh-keygen on your own PC and want to connect to the server server1 with ssh without a password. Which of the following is the correct way to place the keys?
- AAdd the private key to ~/.ssh/authorized_keys on the server, and keep the public key only on your PC
- BPut both the public key and the private key in ~/.ssh on the server, and leave nothing on your PC
- CAdd the public key to ~/.ssh/authorized_keys on the server, and never let the private key leave your PC
Show answer and explanation
Answer: C. Add the public key to ~/.ssh/authorized_keys on the server, and never let the private key leave your PC
In SSH public-key authentication, the server uses the public key registered in authorized_keys to confirm that the connecting side holds the corresponding private key. The private key itself is never sent, so it is kept only on your own PC, with permissions such as 600 so that others cannot read it, and protected by a passphrase. The public key (a .pub file such as ~/.ssh/id_ed25519.pub) may be known to others without harm, and ssh-copy-id adds it to the server's authorized_keys. The same key is also used when transferring files with scp or rsync, which run over ssh.
- A. As its name says, the private key must not leave your hands. What is registered on the server is the public key.
- B. If the private key is placed on the server, anyone who can get into the server can use it. Also, without the private key at hand you cannot authenticate.
- C. Correct. The public key is registered on the server, and the private key is protected at hand.