Linux Basics · Lesson 3 · 15 min

Connecting with SSH

SSH (Secure SHell) lets you type commands on a computer that's somewhere else: in the next room, in a school server closet, or in a data center across the world. It's how almost every Linux server gets managed.

You will learn

  • How SSH works: client, server, port 22, encryption
  • How to switch on the SSH server on Rocky and on Ubuntu
  • How to log in, what the “fingerprint” question means, and how to log out
  • How to use SSH keys so you don't need a password

The big idea

Think of SSH as a secure phone call between two computers:

Step 1: make sure the server is listening

Most servers have SSH turned on already. If you're setting up your own machine (for example, a spare laptop running Linux), this is where the families differ:

Rocky / RHEL
sudo dnf install openssh-server
sudo systemctl enable --now sshd
sudo firewall-cmd --list-services

The service is named sshd. The firewall is on by default and already allows ssh.

Ubuntu / Debian
sudo apt update
sudo apt install openssh-server
systemctl status ssh

The service is named ssh (sshd also works). It starts automatically after you install it. The firewall (ufw) is off by default.

Then find the server's IP address, which is its number on the network:

Same on both
hostname -I

(Linux Sysadmin, lesson 1 explains IP addresses, ip a and the old ifconfig properly.)

Step 2: connect from your computer

This part is the same everywhere: Windows PowerShell, Mac Terminal or Linux. (Prefer an app like PuTTY or iTerm2? That's lesson 4.)

sshcommandstudentusername on the server@192.168.1.50server address

The very first time, you'll see this question:

The authenticity of host '192.168.1.50 (192.168.1.50)' can't be established.
ED25519 key fingerprint is SHA256:Zk3dQ1v8mX4pR2yLw9cT0aB7nE5fH6jK1uS3gV8qW2o.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

That's SSH saying “I've never talked to this server before. Is this really the one you meant?” It's like caller ID for computers. On your own network, type the whole word yes. SSH remembers the server from then on. If that fingerprint ever changes, SSH shows a big scary warning, because someone could be pretending to be your server. When that happens, stop and ask whoever runs the server.

Next, type your password. Nothing appears while you type, not even dots. That's on purpose, so nobody can count the letters. Type it and press Enter anyway.

When you're done, type exit to hang up and return to your own computer.

Try it

This terminal starts on your laptop (a pretend one). Somewhere on the network there's a server at 192.168.1.50. Username: student. Password: linux.

Level up: SSH keys

Passwords can be guessed. SSH keys are much safer, and they save you typing. A key comes as a pair:

Same on both (run these on YOUR computer)
# 1. make a key pair (press Enter to accept the defaults)
ssh-keygen -t ed25519
# 2. put your padlock on the server (asks for your password one last time)
ssh-copy-id student@192.168.1.50
# 3. log in, no password needed
ssh student@192.168.1.50

On Windows, ssh-copy-id doesn't exist. Lesson 4 shows the one-line replacement, plus PuTTY, iTerm2 and phone apps. The bonus missions above let you practice all of this.

When it doesn't work

ErrorWhat it usually means
Connection timed outWrong IP address, the server is off, or a firewall is blocking port 22.
Connection refusedThe computer is there, but the SSH server isn't running. Start it: sshd on Rocky, ssh on Ubuntu.
Permission deniedWrong username or password. Check the part before the @.
Could not resolve hostnameA typo in the server name, or your computer doesn't know that name. Use the IP address instead.
REMOTE HOST IDENTIFICATION HAS CHANGEDThe server's fingerprint changed. Maybe it was reinstalled, maybe something shady is going on. Ask the admin before you continue.
Hacker ethics

Only SSH into machines you own or have been given an account on. Trying to guess passwords on other people's servers is illegal, even “just to see.” Servers log every attempt: Rocky writes them to /var/log/secure and Ubuntu to /var/log/auth.log.

Quick check

1. You type your password and nothing shows up on screen. What should you do?

2. What's the SSH service called on Rocky vs Ubuntu?

3. Which SSH key file is safe to copy to servers?

Finished the missions and the quiz? Mark it done to track your progress.