Module 3 · Cryptography and PKI · Lesson 30 of 42

Lab: SSH public key authentication

Hands-on in Kali Linux: start the SSH service, log in with a password, generate an RSA key pair with ssh-keygen, copy the public key to the server with ssh-copy-id, and log in again using the key instead of a password.

In this lesson · about 18 minutes

  • Start and check the SSH service with the service command
  • Generate a public/private key pair with ssh-keygen
  • Install a public key on a server with ssh-copy-id and authorized_keys
  • Explain why key-based login is stronger than a password

SSH (Secure Shell) is how you log in to and manage a Linux machine remotely. By default you sign in with a username and password, but passwords can be guessed or cracked (you saw that in the last two lessons). Public key authentication replaces the password with a key pair:

  • A private key stays on your own machine, protected by a passphrase. You never share it.
  • A matching public key is copied to the server, into a file called ~/.ssh/authorized_keys.

When you connect, the server challenges you to prove you hold the private key. Nothing crackable travels over the network, and an attacker who doesn't have your private key can't log in even if they know your username.

In this lab you'll do the whole thing on one Kali machine: you'll start SSH, connect to localhost (the machine itself) as if from across the network, generate a key pair, install the public key, and log in with the key. You're logged in to Kali as the kali user; the account password and the key passphrase are both kali in this lab.

Hands-on lab (simulated terminal)

Set up and use SSH key authentication

Starting the SSH service needs sudo, and the first time you use it sudo asks for your password (kali on the default image). Nothing appears while you type it. For the SSH steps, type each command and read the simulated output.

Step 1 of 13. Type each command and press Enter. Nothing runs on your computer.

kali@kali: ~

1. Start the SSH service so the machine will accept SSH connections.

┌──(kali㉿kali)-[~]
└─$

Check your understanding0 of 6 correct

Question 1

1.In SSH public key authentication, which key is copied to the server?

Question 2

2.Which file on the server lists the public keys allowed to log in to an account?

Question 3

3.What command generates an SSH key pair?

Question 4

4.Why is key authentication generally more secure than a password?

Question 5

5.What does the passphrase on a private key protect against?

Question 6

6.Which ssh-copy-id option names the key file to install on the server?

Quiz score: 0 of 6

Tip: answer every quiz question correctly first.

Noviq Academy is free and for learning. This course is independent and is not affiliated with or endorsed by CompTIA. CompTIA and Security+ are trademarks of CompTIA, Inc. Exam details such as price and policies change; confirm them on CompTIA's website before you book.