Theme editor

Guide Linux Ubuntu SSH Key Login Guide 2025

  • Thread starter Thread starter CL4Y
  • Start date Start date
  • Views 161

CL4Y

Keyboard Ninja
Administrator
Thread owner

Ubuntu SSH Key Login Guide 2025​

SSH is an encrypted protocol used to manage and communicate with servers securely. When working on an Ubuntu server, you'll likely spend most of your time connected via SSH in the terminal. This guide focuses on setting up SSH key authentication on all major Ubuntu versions (18.04, 20.04, 22.04, 24.04). SSH keys provide a secure way to log into your server without using passwords.

SSH (Secure Shell or Secure Socket Shell) is a network protocol commonly used by system administrators to securely access and manage remote machines over an untrusted network. It is used for making installations, configurations, and file transfers directly through the terminal or via tools.



🔐 Step 1 – Generate SSH Key​

In this tutorial, we'll use PuTTY to generate the SSH key. Start by downloading and installing the program.

After installation, search for “PuTTYgen” in your Windows start menu and open it. PuTTYgen is an integrated utility that comes with PuTTY. Without changing any settings, click the “Generate” button and move your mouse randomly over the blank "KEY" area above. Your random mouse movements will help generate a secure, encrypted key.

jetto-ubuntu-ssh-key-enable-1.webp




📜 Step 2 – Save and Manage the Keys​

As shown in the image below, the generated key will appear in the “KEY” section. Now, it's time to save the keys. Click on "Save public key" and "Save private key" and save both files in a preferred directory. Do not close PuTTYgen yet!

jetto-ubuntu-ssh-key-enable-2.webp




🗃️ Step 3 – Upload the Key to Your Server

Now that you've created your key pair, it's time to upload the public key to your server. Connect to your Ubuntu server via PuTTY as the root user.

Once logged in, run the following commands:
Bash:
cd ~/.ssh/
ls

You should see a file named authorized_keys. We'll need to edit this file. Use the Nano text editor:

Bash:
nano authorized_keys

Once the file is open, delete any existing content. Then, copy the public key from PuTTYgen and paste it into this file (you can right-click to paste in PuTTY). To save and exit: press CTRL + X, then Y, and hit Enter.

jetto-ubuntu-ssh-key-enable-3.webp


Your key is now added to the server. However, we must ensure the server is configured to allow key-based root login. Run the following command to edit the SSH config file:

Bash:
nano /etc/ssh/sshd_config

Find and modify (or add) the following lines:
Bash:
LogLevel VERBOSE
PermitRootLogin yes
PasswordAuthentication no



✅ Final Step – Restart the SSH Service​

To apply the changes, restart the SSH service with the command below:

Bash:
service ssh restart
 
Thread owner
You can now securely log in to your Ubuntu operating system server using only your SSH key. This method is much more secure than using a password and is the recommended access method.
 
Back
Top