Using private keys is standard for Linux users in cloud environments such as Amazon Web Services. This procedure creates new users with key authentication already configured—with the pair generated on the server itself, without needing to paste any public key.
There are two key options, and you choose based on the tool you will use on the other end:
| Option | File format | Used for | How it is delivered |
|---|---|---|---|
1 — .ppk
| PuTTY-User-Key-File-3: ssh-rsa | PuTTY, WinSCP, FileZilla, Pageant | file via scp (double-click on Windows) |
| 2 — OpenSSH private key | -----BEGIN OPENSSH PRIVATE KEY----- |
n8n SSH credential, ssh -i, scp, Git, automation in general | paste the entire text into the field |
The key is 4096-bit RSA (ssh-rsa) in both cases, and it is the same pair: if you need both ends (OpenSSH + PuTTY), item 4 generates a single key and converts it—the public key installed in authorized_keys remains one key.
Warning: the private key appears in the terminal. Never paste it into a ticket, chat, or email. Use
scp/WinSCP (item 7) and delete the copy from the server after downloading it.
1. Prerequisite
-
puttygen(theputty-toolspackage)—required for Option 1 and for conversion in item 4. -
ssh-keygen—comes with OpenSSH; used in Option 2, for the fingerprint, and for verification.
sudo apt update && sudo apt install -y putty-tools
Test: puttygen --help should display the header PuTTYgen: key generator and converter for the PuTTY tools.
2. Option 1 — .ppk file (PuTTY)
puttygen generates the pair on the server and saves it directly in PuTTY's native format. The public key is output from the file itself (puttygen key.ppk -L), so the match with authorized_keys is guaranteed by construction.
2.1 New user WITH root privileges, without a password
USERNAME=<username> && \ (command -v puttygen > /dev/null || sudo apt-get install -y putty-tools) && \ sudo adduser --disabled-password --gecos "" "$USERNAME" && \ sudo usermod -aG sudo "$USERNAME" && \ USER_HOME=$(eval echo ~$USERNAME) && \ sudo install -d -m 700 "$USER_HOME/.ssh" && \ sudo chown -R "$USERNAME:$USERNAME" "$USER_HOME/.ssh" && \ sudo -u "$USERNAME" puttygen -t rsa -b 4096 -C "$USERNAME@$(hostname)" -O private -o "$USER_HOME/.ssh/$USERNAME.ppk" --new-passphrase /dev/null && \ sudo -u "$USERNAME" sh -c "puttygen ~/.ssh/$USERNAME.ppk -L > ~/.ssh/authorized_keys" && \ sudo chmod 600 "$USER_HOME/.ssh/authorized_keys" "$USER_HOME/.ssh/$USERNAME.ppk" && \ echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/$USERNAME > /dev/null && \ sudo chmod 440 /etc/sudoers.d/$USERNAME && \ echo "== FINGERPRINT (compare in PuTTYgen) ==" && ssh-keygen -lf "$USER_HOME/.ssh/authorized_keys" && \ echo "== BEGIN OF KEY .PPK ==" && sudo cat "$USER_HOME/.ssh/$USERNAME.ppk" && \ echo "== END OF KEY .PPK =="
What each step does:
-
adduser --disabled-password→ creates the account without a login password (key only). -
install -d -m 700→ creates~/.sshwith the correct permissions already set. -
puttygen -t rsa -b 4096 -O private→ generates the pair on the server and saves it in.ppkformat.-b 4096is the key size (PuTTY's default is 2048); 4096 takes ~10 seconds because it involves searching for primes—-b 2048takes less than 1 second. -
puttygen ... -L→ prints the public key in OpenSSH format (ssh-rsa AAAAB3...), and it is placed inauthorized_keys. -
--new-passphrase /dev/null→ saves the.ppkwithout a passphrase (without this,puttygenpauses and asks for a password). To protect it with a passphrase, use--new-passphrase /root/.ppk-password(a file containing the password). -
ssh-keygen -lf→ SHA256 fingerprint of the key. Use this instead ofputtygen -l -E sha256: the-Eoption does not exist inputty-tools0.74 (Debian 11).
2.2 New user WITHOUT root privileges, without a password
USERNAME=<username> && \ (command -v puttygen > /dev/null || sudo apt-get install -y putty-tools) && \ sudo adduser --disabled-password --gecos "" "$USERNAME" && \ USER_HOME=$(eval echo ~$USERNAME) && \ sudo install -d -m 700 "$USER_HOME/.ssh" && \ sudo chown -R "$USERNAME:$USERNAME" "$USER_HOME/.ssh" && \ sudo -u "$USERNAME" puttygen -t rsa -b 4096 -C "$USERNAME@$(hostname)" -O private -o "$USER_HOME/.ssh/$USERNAME.ppk" --new-passphrase /dev/null && \ sudo -u "$USERNAME" sh -c "puttygen ~/.ssh/$USERNAME.ppk -L > ~/.ssh/authorized_keys" && \ sudo chmod 600 "$USER_HOME/.ssh/authorized_keys" "$USER_HOME/.ssh/$USERNAME.ppk" && \ echo "== FINGERPRINT ==" && ssh-keygen -lf "$USER_HOME/.ssh/authorized_keys" && \ echo "== BEGIN OF KEY .PPK ==" && sudo cat "$USER_HOME/.ssh/$USERNAME.ppk" && \ echo "== END OF KEY .PPK =="
2.3 Existing user: new .ppk key (keeps the old keys)
USERNAME=<username> && \ (command -v puttygen > /dev/null || sudo apt-get install -y putty-tools) && \ USER_HOME=$(eval echo ~$USERNAME) && \ sudo install -d -m 700 "$USER_HOME/.ssh" && \ sudo chown -R "$USERNAME:$USERNAME" "$USER_HOME/.ssh" && \ sudo -u "$USERNAME" puttygen -t rsa -b 4096 -C "$USERNAME@$(hostname)" -O private -o "$USER_HOME/.ssh/$USERNAME.ppk" --new-passphrase /dev/null && \ sudo -u "$USERNAME" sh -c "puttygen ~/.ssh/$USERNAME.ppk -L >> ~/.ssh/authorized_keys" && \ sudo chmod 600 "$USER_HOME/.ssh/authorized_keys" "$USER_HOME/.ssh/$USERNAME.ppk" && \ echo "== BEGIN OF KEY .PPK ==" && sudo cat "$USER_HOME/.ssh/$USERNAME.ppk" && \ echo "== END OF KEY .PPK =="
To replace the old keys (invalidating previous access), change >> to >.
2.4 Existing user + new key + SSH accepts keys only (tested on Proxmox)
USERNAME=<username> && \ (command -v puttygen > /dev/null || sudo apt-get install -y putty-tools) && \ USER_HOME=$(eval echo ~$USERNAME) && \ sudo install -d -m 700 "$USER_HOME/.ssh" && \ sudo chown -R "$USERNAME:$USERNAME" "$USER_HOME/.ssh" && \ sudo -u "$USERNAME" puttygen -t rsa -b 4096 -C "$USERNAME@$(hostname)" -O private -o "$USER_HOME/.ssh/$USERNAME.ppk" --new-passphrase /dev/null && \ sudo -u "$USERNAME" sh -c "puttygen ~/.ssh/$USERNAME.ppk -L >> ~/.ssh/authorized_keys" && \ sudo chmod 600 "$USER_HOME/.ssh/authorized_keys" "$USER_HOME/.ssh/$USERNAME.ppk" && \ sudo sed -i '/^#\?PubkeyAuthentication/d' /etc/ssh/sshd_config && \ echo "PubkeyAuthentication yes" | sudo tee -a /etc/ssh/sshd_config > /dev/null && \ sudo sed -i '/^#\?PasswordAuthentication/d' /etc/ssh/sshd_config && \ echo "PasswordAuthentication no" | sudo tee -a /etc/ssh/sshd_config > /dev/null && \ sudo sed -i '/^#\?PermitRootLogin/d' /etc/ssh/sshd_config && \ echo "PermitRootLogin prohibit-password" | sudo tee -a /etc/ssh/sshd_config > /dev/null && \ sudo sshd -t && sudo systemctl reload sshd && \ echo "== BEGIN OF KEY .PPK ==" && sudo cat "$USER_HOME/.ssh/$USERNAME.ppk" && \ echo "== END OF KEY .PPK =="
Before disabling password authentication, confirm in another session that key-based login works—otherwise you will lock yourself out of the server.
sudo sshd -tvalidates the syntax before reloading.
3. Option 2 — OpenSSH private key (n8n, ssh, automation)
Here, ssh-keygen generates the key: it produces id_rsa + id_rsa.pub, and the public key is already installed in authorized_keys.
3.1 New user WITH root privileges, without a password
USERNAME=<username> && \ sudo adduser --disabled-password --gecos "" "$USERNAME" && \ sudo usermod -aG sudo "$USERNAME" && \ USER_HOME=$(eval echo ~$USERNAME) && \ sudo install -d -m 700 "$USER_HOME/.ssh" && \ sudo chown -R "$USERNAME:$USERNAME" "$USER_HOME/.ssh" && \ sudo -u "$USERNAME" ssh-keygen -t rsa -b 4096 -N "" -C "$USERNAME@$(hostname)" -f "$USER_HOME/.ssh/id_rsa" && \ sudo -u "$USERNAME" sh -c "cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys" && \ sudo chmod 600 "$USER_HOME/.ssh/id_rsa" "$USER_HOME/.ssh/authorized_keys" && \ echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/$USERNAME > /dev/null && \ sudo chmod 440 /etc/sudoers.d/$USERNAME && \ echo "== FINGERPRINT ==" && ssh-keygen -lf "$USER_HOME/.ssh/authorized_keys" && \ echo "== BEGIN OF PRIVATE KEY ==" && sudo cat "$USER_HOME/.ssh/id_rsa" && \ echo "== END OF PRIVATE KEY =="
What changes compared with Option 1:
-
ssh-keygen -t rsa -b 4096 -N ""→ generates the key without a passphrase (-N "") in the modern format-----BEGIN OPENSSH PRIVATE KEY-----. -
cat id_rsa.pub > authorized_keys→ installs the public key without manual typing. - The private file is located at
~/.ssh/id_rsa—the "usual" name used byssh,scp, andgit.
3.2 New user WITHOUT root privileges, without a password
USERNAME=<username> && \ sudo adduser --disabled-password --gecos "" "$USERNAME" && \ USER_HOME=$(eval echo ~$USERNAME) && \ sudo install -d -m 700 "$USER_HOME/.ssh" && \ sudo chown -R "$USERNAME:$USERNAME" "$USER_HOME/.ssh" && \ sudo -u "$USERNAME" ssh-keygen -t rsa -b 4096 -N "" -C "$USERNAME@$(hostname)" -f "$USER_HOME/.ssh/id_rsa" && \ sudo -u "$USERNAME" sh -c "cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys" && \ sudo chmod 600 "$USER_HOME/.ssh/id_rsa" "$USER_HOME/.ssh/authorized_keys" && \ echo "== FINGERPRINT ==" && ssh-keygen -lf "$USER_HOME/.ssh/authorized_keys" && \ echo "== BEGIN OF PRIVATE KEY ==" && sudo cat "$USER_HOME/.ssh/id_rsa" && \ echo "== END OF PRIVATE KEY =="
3.3 Existing user: new OpenSSH key (keeps the old keys)
USERNAME=<username> && \ USER_HOME=$(eval echo ~$USERNAME) && \ sudo install -d -m 700 "$USER_HOME/.ssh" && \ sudo chown -R "$USERNAME:$USERNAME" "$USER_HOME/.ssh" && \ sudo -u "$USERNAME" ssh-keygen -t rsa -b 4096 -N "" -C "$USERNAME@$(hostname)" -f "$USER_HOME/.ssh/id_rsa_automation" && \ sudo -u "$USERNAME" sh -c "cat ~/.ssh/id_rsa_automation.pub >> ~/.ssh/authorized_keys" && \ sudo chmod 600 "$USER_HOME/.ssh/id_rsa_automation" "$USER_HOME/.ssh/authorized_keys" && \ echo "== BEGIN OF PRIVATE KEY ==" && sudo cat "$USER_HOME/.ssh/id_rsa_automation" && \ echo "== END OF PRIVATE KEY =="
Use a name other than id_rsa (id_rsa_automation, id_rsa_n8n, …) when the user already has their own key—this way, nothing is overwritten. To intentionally overwrite it, use -f ~/.ssh/id_rsa and > instead of >>.
4. Both options with the same pair (recommended: OpenSSH + PuTTY)
Generates a single key (id_rsa), installs the public key once, and converts the same pair to .ppk. This is useful for those who will use the same private key for multiple applications.
USERNAME=<username> && \ (command -v puttygen > /dev/null || sudo apt-get install -y putty-tools) && \ USER_HOME=$(eval echo ~$USERNAME) && \ sudo install -d -m 700 "$USER_HOME/.ssh" && \ sudo chown -R "$USERNAME:$USERNAME" "$USER_HOME/.ssh" && \ sudo -u "$USERNAME" ssh-keygen -t rsa -b 4096 -N "" -C "$USERNAME@$(hostname)" -f "$USER_HOME/.ssh/id_rsa" && \ sudo -u "$USERNAME" sh -c "cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys && puttygen ~/.ssh/id_rsa -O private -o ~/.ssh/$USERNAME.ppk --new-passphrase /dev/null" && \ sudo chmod 600 "$USER_HOME/.ssh/id_rsa" "$USER_HOME/.ssh/authorized_keys" "$USER_HOME/.ssh/$USERNAME.ppk" && \ echo "== FINGERPRINT ==" && ssh-keygen -lf "$USER_HOME/.ssh/authorized_keys" && \ echo "== OpenSSH KEY ==" && sudo cat "$USER_HOME/.ssh/id_rsa" && \ echo "== PUTTY (.ppk) KEY ==" && sudo cat "$USER_HOME/.ssh/$USERNAME.ppk" && \ echo "== END =="
Confirmed in testing: ssh-keygen -y -f id_rsa, the line in authorized_keys, and puttygen key.ppk -L are the same key (same SHA256)—both ends come from the same pair.
5. Display again or convert later
Existing OpenSSH key (id_rsa) → .ppk (same pair):
USERNAME=<username> && USER_HOME=$(eval echo ~$USERNAME) && \ sudo -u "$USERNAME" puttygen ~/.ssh/id_rsa -O private -o "$USER_HOME/.ssh/$USERNAME.ppk" --new-passphrase /dev/null && \ sudo cat "$USER_HOME/.ssh/$USERNAME.ppk"
.ppk → OpenSSH key:
USERNAME=<username> && sudo puttygen "$(eval echo ~$USERNAME)/.ssh/$USERNAME.ppk" -O private-openssh-new -o /tmp/id_rsa --new-passphrase /dev/null && \ sudo cat /tmp/id_rsa && sudo rm -f /tmp/id_rsa
Classic PEM (-----BEGIN RSA PRIVATE KEY-----), only for older tools that require this format; then, to return to OpenSSH, use the conversion from the item above:
USERNAME=<username> && sudo -u "$USERNAME" ssh-keygen -p -m PEM -N "" -f "$(eval echo ~$USERNAME)/.ssh/id_rsa"
Display the .ppk that is still on the server:
USERNAME=<username> && sudo cat "$(eval echo ~$USERNAME)/.ssh/$USERNAME.ppk"
6. Remove user
USERNAME=<username> && sudo deluser --remove-home "$USERNAME" && \ sudo rm -f /etc/sudoers.d/"$USERNAME"
--remove-home already deletes /home/<user>.