Inhaltsverzeichnis
Password-based SSH logins are the primary attack vector for brute-force attacks on Linux servers. Once port 22 is open, bots relentlessly target authentication. The only sustainable architectural decision is to disable passwords in favor of asymmetric cryptography (public-key methods).
In this guide, we configure a Debian server to allow logins exclusively via a cryptographic key pair. We use the workflow of server-side key generation and import into the Windows client (PuTTY).
Generate key pair
We start directly on the server. Here we generate an RSA key pair with a bit length of 4096. This length is necessary to remain resistant to factorization attacks in the long term (the 2048-bit standard is now considered the minimum, while 4096 is future-proof).
Log in as the user you want to secure (in this case: root) and run the following command:
ssh-keygen -t rsa -b 4096📋The tool prompts for a storage location and a passphrase.
- Storage location: Confirm the default (
/home/user/.ssh/id_rsa). - Passphrase: Here you define a password that encrypts the private key locally. If your private key is stolen, it is useless without this passphrase. You must set a strong password here.
The output confirms the creation of the fingerprint and the Randomart image.

Verify the creation of the files:
ls -l ~/.ssh/📋id_rsa: Private Key. This is your identity proof. It must never fall into the wrong hands.id_rsa.pub: Public Key. This is stored on the server and may be publicly known.

Authorize Public Key
For the SSH daemon (`sshd`) to accept the key, the public key's content must be written to the `authorized_keys` file. During login, the daemon checks whether the client possesses the corresponding private key for any of the public keys listed there.
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys📋Important: SSH is extremely strict with file permissions. If the authorized_keys file or the .ssh directory is writable by other users, the daemon will refuse the service for security reasons (Strict Modes). We therefore set the permissions restrictively:
chmod 700 ~/.sshchmod 600 ~/.ssh/authorized_keys📋700: Only the owner can open the directory.600: Only the owner can read/write the file.

Transfer the private key to the client
Since we generated the key pair on the server (Server-Side Generation), we now need to securely transfer the private key (`id_rsa`) to the Windows client.
Use WinSCP or a similar SCP client for this.
- Connect to your server.
- Navigate to
/home/[USER]/.ssh/. (If the folder is hidden:CTRL + ALT + Hin WinSCP). - Download the
id_rsafile to your local Windows PC.
Architect-Note: Treat the id_rsa file like your credit card data. Ideally, delete it from the server after the transfer so that only the public key remains there.

Hardening the SSH daemon (disable passwords)
As long as password authentication is enabled, the key does not provide any security benefit against brute-force attacks. We will now configure the daemon to accept only keys.
Open the configuration:
sudo nano /etc/ssh/sshd_config📋Search for and modify (or uncomment) the following parameters. Disabling root login is an additional "defense-in-depth" measure, as the user "root" exists on every system and is therefore a common target.
PubkeyAuthentication yesPasswordAuthentication noPermitRootLogin no📋Save the file (CTRL+O, Enter) and close it (CTRL+X).
To apply the changes, the service must reload the configuration. Existing connections will not be terminated, but test access in a new terminal window before closing the current one.
sudo systemctl restart ssh.service📋

Client Configuration with PuTTY
If you use PuTTY to establish the connection, note that this tool requires its own key formats. The generated OpenSSH key (id_rsa) is not compatible and must first be converted to PuTTY format (.ppk).
If you use PowerShell, however, you can use the private key directly in its original format, just as it was created.
- Conversion with PuTTYgen




- Start the PuTTY Key Generator (PuTTYgen).
- Click Load and select "All Files (*)" in the file filter.
- Select your downloaded
id_rsafile. - Enter your passphrase (if set in step 1).
The tool has now imported the key. Save it in PuTTY format.
- Save the file as
private_key.ppk. - Click on Save private key.
- Establishing a connection with PuTTY



Now we configure the session in PuTTY.
- Open PuTTY.
- In the left tree menu, navigate to:
Connection → SSH → Auth → Credentials. - Under "Private key file for authentication", select the
.ppkfile you just created.
- Go back to Session, enter IP and port, and optionally save the session.
- Click Open and, if this is the first connection, confirm the fingerprint with yes.
Connection Setup | The server no longer prompts for a password; instead, the SSH key is used.
For protected keys, you now need to enter their passphrase (local decryption).
- Establishing a connection with PowerShell

Instead of installing PuTTY, you can use the built-in SSH client on current Windows systems. The major advantage: your id_rsa key works immediately here, eliminating the need for conversion.
Simply use the following command in PowerShell:
ssh -i .\id_rsa USERNAME@IP des SERVERS📋Troubleshooting: File Permissions
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "id_rsa": bad permissions
USERNAME@xxx.xxx.xxx.xxx: Permission denied (publickey).📋If this error message appears, the permissions on your private key file are not restrictive enough. You have two options to fix this:
- Option A (Simple): Move the key file to your Documents folder. Due to Windows permission inheritance, the file will automatically receive the correct permissions there.
- Option B (Manual): Manually change the file’s security settings. Ensure your current Windows user is listed as the owner and has full control. All other users should be removed.
Conclusion & Security Assessment
This change has drastically reduced the attack surface of your Debian server. Automated scripts that test password lists against your port 22 now hit a dead end ("Permission denied").
Important Security Notes:
- Backup: Never lose your private key. Since
PasswordAuthenticationis set tono, you will permanently lock yourself out of the system without the key (unless you have console access via the hoster). - Key Management: Ideally, generate a separate key for each device. If a laptop is stolen, you only need to remove its specific public key from the server’s
authorized_keysfile without having to reconfigure all other access points.