0
0
Linux CLIscripting~20 mins

Key-based authentication in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
SSH Key Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this ssh-keygen command?
You run the command ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa_test -N "". What is the expected output?
Linux CLI
ssh-keygen -t rsa -b 2048 -f ~/.ssh/id_rsa_test -N ""
A
Generating public/private rsa key pair.
Your identification has been saved in /home/user/.ssh/id_rsa_test.
Your public key has been saved in /home/user/.ssh/id_rsa_test.pub.
The key fingerprint is:
SHA256:... user@hostname
The key's randomart image is:
+---[RSA 2048]----+
|    .o+*o.       |
|   .+o=+o.       |
|  . +o+o.        |
|   . +o.         |
|    . S          |
|                 |
|                 |
|                 |
|                 |
+----[SHA256]-----+
Bssh: Could not resolve hostname ~/.ssh/id_rsa_test: Name or service not known
CPermission denied (publickey).
DError: invalid option -- 't'
Attempts:
2 left
💡 Hint
Think about what ssh-keygen does when creating a key pair with no passphrase.
💻 Command Output
intermediate
2:00remaining
What is the output of this ssh-copy-id command?
You run ssh-copy-id -i ~/.ssh/id_rsa_test.pub user@remotehost. What output do you expect if the key is successfully copied?
Linux CLI
ssh-copy-id -i ~/.ssh/id_rsa_test.pub user@remotehost
A
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh 'user@remotehost'"
and check to make sure that only the key(s) you wanted were added.
Bssh-copy-id: command not found
CPermission denied (publickey,password).
DError: Could not open file ~/.ssh/id_rsa_test.pub
Attempts:
2 left
💡 Hint
This command copies your public key to the remote server's authorized keys.
🔧 Debug
advanced
2:30remaining
Why does this SSH login fail with 'Permission denied (publickey)'?
You try to ssh into a server using key-based authentication but get this error: Permission denied (publickey). The public key is correctly in ~/.ssh/authorized_keys. What is the most likely cause?
Linux CLI
ssh user@remotehost
AThe private key file on the client is missing the execute permission.
BThe permissions on ~/.ssh or ~/.ssh/authorized_keys on the server are too open (e.g., 777).
CThe sshd service on the server is not running.
DThe remote server's IP address is blocked by a firewall.
Attempts:
2 left
💡 Hint
Check file and directory permissions on the server for SSH keys.
🚀 Application
advanced
2:30remaining
Which command sets up an SSH agent and adds your private key for authentication?
You want to avoid typing your SSH key passphrase repeatedly. Which command sequence correctly starts the SSH agent and adds your private key?
Assh-agent & ssh-add ~/.ssh/id_rsa
B
ssh-agent start
ssh-add ~/.ssh/id_rsa
C
start ssh-agent
ssh-add ~/.ssh/id_rsa
D
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
Attempts:
2 left
💡 Hint
The ssh-agent must be started in the current shell environment.
🧠 Conceptual
expert
3:00remaining
What is the main security advantage of using SSH key-based authentication over password authentication?
Choose the best explanation for why SSH key-based authentication is more secure than password authentication.
ASSH keys are longer and more complex than passwords, making them impossible to guess or crack.
BPasswords can be reused on multiple sites, but SSH keys are unique to each server.
CSSH key authentication uses asymmetric cryptography, so the private key never leaves the client, preventing interception and replay attacks.
DSSH keys automatically expire after a short time, reducing risk of compromise.
Attempts:
2 left
💡 Hint
Think about how the private key is used during authentication.