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?

  1. AAdd the private key to ~/.ssh/authorized_keys on the server, and keep the public key only on your PC
  2. BPut both the public key and the private key in ~/.ssh on the server, and leave nothing on your PC
  3. 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.
Practice this topic Back to topic

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Linux and Command-Line Basics questions

  1. Which of the following is what happens when "tar -czf proj.tar.gz proj/" is run?
  2. After editing main.c, a file managed with Git, only git commit -m "fix" was run, and "no changes added to commit" was shown and nothing was committed. Which of the following is the reason?
  3. You ran git commit in Git, but the commit does not yet appear in the GitHub repository shared by the team. Which of the following is the reason?
  4. "build/" was written in the .gitignore of a project managed with Git, but changes to build/out.log, which was committed earlier, keep appearing in git status. Which of the following is the reason?
  5. Which of the following correctly pairs standard Linux directories with what is placed in them?