How to Generate SSH Keys and Add to Hostinger
In this article
SSH keys provide a secure, passwordless way to connect to your Hostinger hosting account. Instead of typing a password every time you log in via SSH, you generate a pair of cryptographic keys on your computer, upload the public key to Hostinger, and then authenticate automatically. This guide walks you through generating the keys on Windows, macOS, or Linux, and adding them to your Hostinger dashboard.
What You'll Need
- A Hostinger account with an active hosting plan (shared, VPS, or cloud).
- Access to your Hostinger hPanel dashboard.
- A local computer (Windows, macOS, or Linux) with a terminal or command prompt.
- For Windows 10/11: OpenSSH client is usually pre-installed; if not, enable it via "Optional Features" or install Git for Windows.
Step-by-Step
- Open your terminal or command prompt.
- Windows: Press
Win, typecmd, and hit Enter. Or use PowerShell. - macOS/Linux: Open Terminal from Applications or your app launcher.
- Windows: Press
- Check if you already have SSH keys. Run
ls -al ~/.ssh. If you see files likeid_rsaandid_rsa.pub, you already have keys. You can reuse them or skip to step 4. If the directory doesn't exist or is empty, continue. - Generate a new SSH key pair. Type the following command and press Enter:
ssh-keygen -t ed25519 -C "your_email@example.com"-t ed25519creates a modern, secure key type. If your system doesn't support Ed25519, usessh-keygen -t rsa -b 4096.-Cadds a comment (usually your email) to help identify the key.
- Choose a save location. When prompted "Enter file in which to save the key", press Enter to accept the default (
~/.ssh/id_ed25519). If you already have a key and don't want to overwrite it, type a new filename like~/.ssh/hostinger_key. - Set a passphrase (optional but recommended). You'll be asked for a passphrase. You can leave it empty by pressing Enter, but a passphrase adds an extra layer of security. If you set one, you'll need to enter it each time you use the key.
- Locate your public key. After generation, you'll see a message with the key's fingerprint and the path to the public key. To view the public key, run:
(If you used a custom filename, replacecat ~/.ssh/id_ed25519.pubid_ed25519.pubwith your filename). The output will be a long string starting withssh-ed25519orssh-rsa. - Copy the public key. Select the entire line and copy it to your clipboard. Be careful not to include extra spaces or newlines.
- Log in to your Hostinger hPanel. Go to hpanel.hostinger.com and sign in.
- Navigate to SSH keys.
- For shared hosting: look for "Advanced" or "SSH Access" in the sidebar. Click on "SSH Keys".
- For VPS/Cloud: go to your VPS management page, then find "SSH keys" or "Security" section.
- Add the public key. Click the "Add" or "New SSH key" button. Paste the copied public key into the "Public key" field. Give it a descriptive name (e.g., "My Laptop") so you can identify it later.
- Save the key. Click "Add" or "Save". Hostinger will store the key.
- Test the connection. Open your terminal and connect to your hosting account using SSH. The command typically looks like:
Replacessh username@yourdomain.comusernamewith your cPanel or SSH username (found in hPanel under "SSH Access") andyourdomain.comwith your actual domain or server IP. If you set a passphrase, you'll be prompted to enter it. If everything is set up correctly, you'll be logged in without a password.
Common Mistakes
- Copying the wrong key. Make sure you copy the
.pubfile, not the private key (id_ed25519). The private key must never be shared. - Adding extra whitespace. When pasting, ensure no line breaks or spaces are added at the beginning or end. Use
catto display the key and copy it directly. - Using the wrong username. Your SSH username is not always your email or domain. Check hPanel under "SSH Access" for the exact username.
- Key permissions too open. On Unix-like systems, if the private key file has permissions that are too open (e.g., world-readable), SSH will refuse to use it. Fix with
chmod 600 ~/.ssh/id_ed25519. - Generating a new key when you already have one. Overwriting an existing key can break other services that use it. Always check for existing keys first.
Tips
- Use a strong passphrase for your private key. It protects you even if your key file is stolen.
- Use an SSH agent to avoid typing your passphrase repeatedly. On macOS/Linux, run
eval "$(ssh-agent -s)"and thenssh-add ~/.ssh/id_ed25519. On Windows, you can use the built-in OpenSSH agent service. - Keep your private key safe. Never upload it to any server or share it with anyone.
- If you use multiple devices, generate a separate key pair for each device and add each public key to Hostinger.
- Regularly review the keys in your Hostinger dashboard and remove any that you no longer use.
Troubleshooting
- "Permission denied (publickey)" error. This usually means the public key is not correctly added or the username is wrong. Double-check the key in hPanel and the username in your SSH command. Also ensure the key was added to the correct hosting account (shared vs VPS).
- Key not working after adding. It can take a few minutes for the key to propagate. Wait 5-10 minutes and try again. Also verify that you copied the entire key, including the type prefix (e.g.,
ssh-ed25519). - Passphrase forgotten. If you forget your passphrase, you cannot recover it. You'll need to generate a new key pair and add the new public key to Hostinger.
- Windows OpenSSH not recognized. If
sshis not recognized, install OpenSSH Client via Settings > Apps > Optional Features, or install Git for Windows which includes ssh. - Connection timed out. Ensure your hosting plan includes SSH access. Some shared hosting plans require SSH to be enabled in hPanel. Check your plan's features or contact Hostinger support.
Frequently Asked Questions
Can I use the same SSH key for multiple Hostinger accounts?
Yes, you can add the same public key to multiple accounts. However, it's better to use a unique key per account for security and easier revocation.
What is the difference between a public and private key?
The public key is placed on the server (Hostinger) and is safe to share. The private key stays on your computer and is used to prove your identity. Never share the private key.
How do I remove an SSH key from Hostinger?
In hPanel, go to SSH Keys, find the key you want to remove, and click the delete or trash icon. Confirm the action.
Do I need to regenerate keys if I change my hosting plan?
No, keys are tied to your account, not the plan. You can keep using the same key unless you delete it.
Can I use SSH keys for Git deployments on Hostinger?
Yes, you can use SSH keys to authenticate with Git repositories hosted on Hostinger or to push code via SSH. The setup is the same as described above.
What if I lose my private key?
If you lose your private key, you won't be able to authenticate. You'll need to generate a new key pair, add the new public key to Hostinger, and remove the old one.