In this article, we’ll explore how to create an SSH Key on Ubuntu for remote server access. This approach allows us to access the server without a password, significantly enhancing security.
What is SSH?
SSH stands for Secure Shell Protocol, a cryptographic network protocol that enables users to access remote computers securely over the internet.
While SSH supports password-based authentication, using SSH keys is generally recommended. SSH keys provide a more secure method for logging into a Linux server, as they are not vulnerable to brute-force password attacks.
Generating an SSH key on Ubuntu creates two keys: a public key and a private key. The public key can be placed on any server, and you can connect to that server using an SSH client that has access to the private key.
When the public and private keys match, the server grants access without requiring a password. You can further enhance SSH key security by protecting the private key with a passphrase, which is optional but highly recommended.
Steps to Create an SSH Key on Ubuntu
Here are the steps to create an SSH key on Ubuntu:
Generating the Key Pair
The first step to generate an SSH key on Ubuntu is to create a key pair on the client side, which could be your laptop or PC. Type the following command in the terminal:
|
|
This command will produce the following output:
|
|
A confirmation screen will appear indicating that the SSH key generation process has started, and you will be prompted for some information, which we will discuss in the next steps.
Specifying the Key Pair Storage Location
The first prompt from the ssh-keygen
command will ask where to save the key pair:
|
|
You can press ENTER to save the file to the default location in the .ssh
directory of your home directory.
Alternatively, you can choose a different file name or location by typing it after the prompt and pressing ENTER.
Creating a Passphrase
The second and final prompt will ask you to enter a passphrase:
|
|
You can leave the passphrase empty, but it is highly recommended to enter a passphrase to make your key pair more secure.
A passphrase ensures that your key pair cannot be used by unauthorized persons, as you will be prompted to enter the passphrase whenever you use the key pair to access the target server.
The overall output will look like this:
|
|
The public key is now located at /home/your_username/.ssh/id_ed25519.pub
, and the private key is located at /home/your_username/.ssh/id_ed25519
.
Copying the Public Key to the Server
After successfully creating the key pair, it’s time to place the public key on the server you wish to access.
You can copy the public key to the authorized_keys
file on the target server with the following command. Be sure to replace the example username and server address:
|
|
With this command, you will be able to log into the server via SSH without using a password. However, if you set a passphrase when creating the SSH key, you will be prompted to enter the passphrase upon login.
Conclusion
Creating an SSH key on Ubuntu is simple and significantly improves the security of your remote server access. By following these steps, you can connect to your server securely without using passwords, reducing the risk of unauthorized access. Adding a passphrase to your private key provides extra protection, ensuring only you can use it to access your server. Implementing SSH keys is essential for maintaining a secure and efficient server management environment.