Nanohost logo
PricingFAQ
Log inSign Up

How to Create an SSH Key in Linux (Easy Step-by-Step Guide)

Tutorials

8 Aug 2025

How to Create an SSH Key in Linux (Easy Step-by-Step Guide) full

How to Create an SSH Key in Linux: Easy Step-by-Step Guide

If you're using a VPS, the safest way to log in is not with a password — it's with SSH keys.

In this guide, you'll learn how to create an SSH key on Linux, and how to use it to securely access your VPS (for example, from nanohost.org, where VPS plans start at just $8/month).

No prior experience required.

What is an SSH Key?

An SSH key is a pair of files used to authenticate with a server. It consists of:

  • Private key — stored on your local machine (keep this secret!)
  • Public key — stored on the server

When you try to log in, your VPS checks the public key, and if it matches your private key, access is granted — no password needed.

Step 1: Generate the SSH Key Pair

Open your Terminal and run: ssh-keygen

You’ll see something like:

Just press Enter to accept the default location.

➕ You’ll then be asked:

Enter passphrase (empty for no passphrase):

This is optional. If you want extra security, type a passphrase.

Otherwise, press Enter twice to skip.

🎉 Done! Your SSH key pair is now created.

Step 2: Check the Files

Your keys are saved in the ~/.ssh folder:

  • Private key: ~/.ssh/id_rsa
  • Public key: ~/.ssh/id_rsa.pub

Never share your private key!

Step 3: Upload the Public Key to Your VPS

Assuming your VPS IP is 45.12.34.56 and your username is root:

ssh-copy-id root@45.12.34.56

You’ll be asked to enter your VPS password once. After that, your key will be uploaded.

Don’t have ssh-copy-id? Use this:

cat ~/.ssh/id_rsa.pub | ssh root@45.12.34.56 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Step 4: Log In Using Your Key

Now try logging in:

ssh root@45.12.34.56

If everything worked, you’ll be logged in without a password!

Disable Password Login (Optional but Recommended)

To force key-only logins, edit the SSH config on your server: nano /etc/ssh/sshd_config

Find or add these lines:

PasswordAuthentication no
PermitRootLogin prohibit-password

Then restart SSH:

systemctl restart ssh


⚠️ Only do this if you're sure your key works! Otherwise, you may lock yourself out.

🌍 Get a VPS with SSH Access Ready

Looking to set up your own server?

At nanohost.org, you get:

  • ⚡ Fast and reliable VPS
  • 🌐 Global locations
  • 🔐 SSH access pre-configured
  • 💸 Starting at just $8/month

Perfect for running proxies, apps, or learning Linux.

linuxhow-tobasics

Read also

How to Reboot Linux Now (Safely): systemctl reboot, shutdown -r now, and Force-Reboot Options

How to Reboot Linux Now (Safely): systemctl reboot, shutdown -r now, and Force-Reboot Options

Tutorials

Whether you’re applying kernel updates, clearing a stuck device, or finishing a configuration change, a reboot is sometimes the cleanest fix. This guide shows beginner-friendly and safe ways to restart Linux immediately (“reboot now Linux”), plus how to force reboot if the system is unresponsive. We’ll cover desktops, servers, and remote machines over SSH.

Linux Navigation and File Management

Linux Navigation and File Management

Tutorials

Learning how to move around and manage files and folders in the Linux filesystem is one of the most important skills for working with any computer. On cloud servers, these tasks are usually done through the terminal using well-known Linux shells and standard commands. This guide will walk you through some of the essential skills needed to work with files and directories from the terminal.

Linux Essentials: Step-by-Step Guides

Linux Essentials: Step-by-Step Guides

Tutorials

Learn the basics of the Linux terminal — what it is, how the shell and command prompt work, and how to run your first commands.

Products

Server in the United StatesServer in the United KingdomServer in NetherlandsServer in SingaporeServer in Poland

NOVPS CLOUD LTD ©2025