OverTheWire Bandit: Level 13 → Level 14
Context
Normally, we use a username and password to log in via SSH. However, there is a more secure and automation-friendly method: Key-Based Authentication.
This system involves a “Public Key” (the lock) and a “Private Key” (the key). If your key fits the lock on the server, you enter without needing a password.
In this level, we are not given a password. Instead, we have a file named sshkey.private.
Tip: SSH keys are extremely sensitive. If you copy this file to
/tmpor create it yourself, you must set strict permissions (chmod 600 sshkey.private). Otherwise, SSH might refuse to use it, complaining that “permissions are too open”. In this level, the file is ready to use, so we can ignore this.
Solution
Important: The server sometimes blocks connections from localhost. The most reliable method is to copy the key to your own computer and connect from there.
Method 1: Connect from Your Computer (Guaranteed)
- Read the key content on the server:
cat sshkey.private - Copy the text (starting with
-----BEGIN OPENSSH PRIVATE KEY-----). - Create a file on your local computer and paste it:
nano bandit14.key # Paste and save (Ctrl+O, Enter, Ctrl+X) - Set permissions:
chmod 600 bandit14.key - Connect from your computer:
This bypasses the “localhost blocked” error completely.ssh -i bandit14.key bandit14@bandit.labs.overthewire.org -p 2220
Method 2: Force Localhost Connection
If you want to stay on the server, try this command (might be blocked):
ssh -i sshkey.private -p 2220 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no bandit14@localhost
To make future logins easier, it’s a good idea to grab the actual password for bandit14. The password for each user is stored under /etc/bandit_pass/:
cat /etc/bandit_pass/bandit14
# 4wcYUJFw0k0XLShlDzztnTBHiqxU3b3e
Key Takeaways
- SSH Private Key (
id_rsa): A digital key granting access. It must never be shared. -iFlag: Specifies which identity file (key) SSH should use.- Localhost SSH: You can use SSH to switch users on the same machine by connecting to localhost.