Dec 02, 2025
Domantas G.
10min Read
To access your server from a local computer with Secure Shell Protocol (SSH), you must learn how to set up SSH keys.
An SSH key pair eliminates manual password authentication, creating a faster server login process and enhanced remote server access security.
Whether you’re new to SSH key-based authentication or want to improve your key management, this comprehensive guide will explain the process and provide effective strategies.
Download ultimate SSH commands cheat sheet
Before setting up SSH keys, let’s review the requirements first. You will need access to:
For the last prerequisite, Mac and Linux users can use their respective built-in Terminals.
However, Windows users can’t use Terminal for SSH connection. Fortunately, there are local SSH clients for Windows. These are the top four recommendations:
With these prerequisites in place, you are ready to set up your SSH key authentication.

With your local device, remote server, and Terminal prepared, let’s learn how to set up SSH keys step by step.
To establish secure connections using SSH, you need to generate a pair of public and private keys. These work together to authenticate and encrypt your communication with remote servers.
The remote server uses public keys to verify your identity based on their SSH key fingerprints. Meanwhile, the local computer stores the private keys for authenticating your SSH connection.
When you connect to a remote computer, your local machine provides the private key. Then, the server checks it against the associated public key to grant you access.
There are two commonly used algorithms for generating authentication keys:
This tutorial will generate private and public SSH keys using Ed25519 as an example. However, you can also follow this guide if you use RSA.
To ensure seamless key authentication, check your hosting provider’s documentation to verify your SSH key and server’s compatibility. Hostinger supports both RSA and Ed25519 algorithms.
First, open your Terminal or local SSH client. Then, enter the ssh-keygen command:
ssh-keygen -t ed25519
The SSH command will display the following message:
Generating public/private ed25519 key pair.
Move on to the next step.
The key generator should ask you to choose a location to store the keys:
Enter file in which to save the key (/home/local_username/.ssh/id_ed25519):
Press Enter to save them in the default location, which is the /.ssh directory in /home.
Alternatively, specify a different location by typing its path and file name. For example, you may want to save your key files in a separate directory from the /.ssh folder for better organization or an encrypted external drive for enhanced security.
Next, the key generator window will ask you to create an SSH key passphrase to access your private key.
Enter passphrase (empty for no passphrase):
You can press Enter to skip this step, but it is strongly encouraged to create a private key passphrase to enhance server connection security. If someone gains unauthorized access to your private key, they still need to know the passphrase to use it.
Choose a strong, long, and unique passphrase. Combining uppercase and lowercase letters, numbers, and special characters is ideal. Here are some examples:
Once you have created the passphrase, hit Enter. Then, fill out the same key passphrase and press Enter again.
The ssh-keygen command will now display the SSH key fingerprint and randomart image for the public key. Here’s what the output should look like from start to finish:
ssh-keygen -t ed25519 Generating public/private ed25519 key pair. Enter file in which to save the key (/home/local_username/.ssh/id_ed25519): Enter passphrase (empty for no passphrase): Enter the same passphrase again: Your identification has been saved in /home/local_username/.ssh/id_ed25519 Your public key has been saved in /home/local_username/.ssh/id_ed25519
The key fingerprint is:
SHA256:kbMwyYwHymTudFmkCxt8yX6+2ztczkUJwRWTwXdRzcU localusername@hostname
The key’s randomart image is:
+--[ED25519 256]--+ | ..o==o | | . +*+o*+ | | . +o.*.o+ | | .o. = o | | . o S + | | . o = | | o o | | + . | | . o | +-----------------+
The ssh-keygen command should also have created a public key and a private key in the specified path and file name. The public key file should have a PUB extension, like id_rsa.pub or id_ed25519.pub.
Private RSA keys typically end with RSA in their file name. Meanwhile, the file for Ed25519 often does not have a specific extension.
Now that you know how to set up SSH keys, let’s dive into effective key management. This makes sure your remote connections are secure and efficient.
To use your SSH key pair for remote connection, you need to transfer your public key to an SSH server first.
If you’re a Hostinger VPS user, our hPanel provides a one-click button to copy your public key to your server’s SSH.

Simply follow these steps:
Important! You only need to add your public SSH key to hPanel. Make sure to never share your private key file with anyone.
Hostinger Premium and Business clients can also establish secure connections with SSH for their websites. Simply find the SSH settings page on your Dashboard → Advanced → SSH Access. Then, click Enable on the SSH status section.
From there, follow steps three to five from the previous VPS explanation to connect your local device to the server’s SSH service.
If you encounter any issues, performing SSH key troubleshooting is essential. Check for potential errors in key generation. Additionally, verify that the public key is properly configured on the remote server.
For assistance, go to our knowledge base or contact our 24/7 Customer Success team. Our VPS also includes Kodee – a built-in AI assistant that can help solve your issues.
You can ask Kodee to add or remove SSH keys on your VPS, all by asking it through the chat interface.
Another way to transfer your public key is with your Terminal or SSH client using the ssh-copy-id command. Replace ‘username’ with your server’s username and ‘remote_server’ with its IP address or domain name:
ssh-copy-id username@remote_server
The SSH command will display this output and ask you for the remote server’s password login:
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/localusername/.ssh/id_ed25519.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys username@remote_server's password:
If the password authentication is successful, you should see this result:
Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'username@remote_server'" and check to make sure that only the key(s) you wanted were added.
Test out your new SSH key user authentication using the suggested command. If it works, you will see a welcome message, which will differ by your server and operating system. Here’s an example of what a successful login may look like:
Important! The PuTTY key agent does not include the ssh-copy-id command. To establish a remote VPS connection with PuTTY, check out our article on How to Use PuTTY (SSH Terminal).
As your projects grow and diversify, you may utilize more than one SSH key for different servers, user accounts, or projects.
If this occurs, we recommend using SSH Agent. This feature runs in the background and securely stores your private keys. It lets you manage SSH key pairs across multiple connections and eliminates the need to repeatedly enter private key passphrases during a session.
To use an SSH agent, follow these steps:
eval "$(ssh-agent -s)"
ssh-add ‘private_key’
If your private key is protected with a passphrase, it will prompt you to enter it.
ssh-add -l
With the SSH agent running and your private key added, you can connect to remote servers without entering your passphrase for each session. Simply use the ssh username@remote_server command to log in.
PuTTY users will need Pageant to use an SSH agent. Go to the PuTTY downloads page to access the installation package.
Here are other strategies for multiple SSH keys management:
How to Use Linux Screen for Effective Terminal Management in 2025
If a private SSH key gets lost or compromised, take immediate action to mitigate potential security risks.
To prevent unauthorized access, remove SSH keys from the remote servers where they were installed. Follow these steps:
cd ~/.ssh
ls id_ed25519 id_ed25519.pub known_hosts
rm ‘private_key_file’
rm ‘public_key_file’
Hostinger clients should delete the public key on hPanel as well. Go to SSH keys for VPS users or SSH Access if you’re a web hosting customer. Then, press Delete on the SSH key.
Besides deleting compromised keys, using the ssh-keygen command to regenerate a new key pair is highly recommended. Doing this ensures that any copies of the compromised keys will be useless.
To minimize the risk of loss or compromise, follow these SSH key management tips:
Basic SSH Commands That You Should Know About
How to Use SFTP (SSH File Transfer Protocol)
How to Disable SSH Password Authentication on Linux VPS
SSH Compression: How to Zip and Unzip via SSH
SSH Connection Refused: What It Is, Causes, and 6 Effective Methods to Fix It
How to Change the SSH Port on VPS, Common Ports and How to Choose the Right One
Learning to set up SSH keys is essential for website owners looking to establish remote server access. Let’s summarize the key steps:
Afterward, transfer the public key to the remote server through your hosting control panel or using the ssh-copy-id command.
To effectively manage your keys, use an SSH agent to store the private keys securely. Also, consider other tips like following the best file management practices, creating unique key pairs for specific SSH servers, and utilizing key aliases.
If a private key gets lost or compromised, don’t panic. Simply remove it from your local device and run the ssh-keygen command again to generate a new key pair.
Here are some commonly asked questions about setting up SSH keys and their answers:
In SSH, the public key is stored on the remote server to verify your identity, while the private key is kept on your local machine for authentication. When you connect to a remote server, your local device provides the private key, which the server matches with the associated public key to establish the connection.
Transferring your public key to the remote server is necessary for authentication. When you attempt to connect to the server, it checks your public key against the private key stored on your local machine. If they match, the device will give your computer access.
Yes, in fact, it is recommended. It can isolate potential security threats and ensure that giving access to one server does not grant it to others. Proper key management is crucial for maintaining a secure and efficient remote environment.
Comments
March 17 2018
I tried Connecting.... But error was :- /sbin/nologin: No such file or directory Even though I am entering correct password
March 23 2018
Hey Piyusg, It seems that you forgot to create the file.
January 06 2022
I did those steps but now I don't know how to login through android app called juicessh any idea?
January 11 2022
Hi! I'd suggest checking out this guide from Juice SSH themselves or contact them via email :)
March 07 2022
When you use this command: ssh-copy-id user@serverip It's probably that you get an error like: /usr/bin/ssh-copy-id: ERROR: No identities found it's because you have to define the directory and the file, I did it adding -i to the command: ssh-copy-id -i ~/.ssh/yourfilename user@serverip and it worked.
March 23 2022
Thank you Felix, it worked :)