Logging In to Another Computer: ssh
ssh user@host opens a shell on another computer right in your own terminal, asks the first time whether that computer is really the one you meant by showing its fingerprint, and exit brings you home; you can practice for free on your own computer with ssh localhost.
Journeyman · Unix · Linux · Updated
After this lesson you can
- Log in to another computer with ssh user@host, and leave it with exit
- Explain why ssh asks about a fingerprint the first time, and when to answer yes
Key takeaways
- A server is a computer whose job is to serve others, such as a website or files. Most have no screen or mouse, so people reach them with ssh.
- ssh user@host logs you in to host as user. The prompt changes to the other computer's, and every command runs there until you type exit.
- The first time, ssh shows the computer's fingerprint and asks whether to go on. Answer yes only when it matches the one the computer's owner gave you.
- Practice for free on your own computer, localhost, once its SSH server is turned on. A rented cloud server costs money for as long as it exists.
The book club's website runs on a small computer in a data center, hundreds of miles from Sam, with no screen, keyboard or mouse. When a page needs fixing, Sam has to work on that computer as if sitting in front of it. That's what ssh does: it opens a shell on another computer, right in your own terminal. Web developers use it to put sites live, IT and cloud administrators to look after servers, and hobbyists to reach a Raspberry Pi or a game server they run for friends.
A computer with no screen: the server
A server is a computer whose job is to serve other computers: a website, files, a database, a game. The computer that asks, such as your laptop, is the client. Nobody sits at a server, so it needs no screen; people reach it over the network.
ssh (read "S S H", for Secure Shell) is the client for that. ssh carries each command you type to the server, and the server's shell runs it and sends back what it prints. Everything on the way, your password included, is scrambled, so nobody on the network can read it. ssh comes with Linux, macOS and Ubuntu in WSL:
ssh -V
OpenSSH_10.2p1 Ubuntu-2ubuntu3.6, OpenSSL 3.5.5 27 Jan 2026
Your version may be different. Any recent one works the same for this chapter.
ssh user@host
The command is ssh, then who you are on the other computer, @ (read "at") and the computer's name or address. ssh sam@bookclub.example.com reads "log in as sam at bookclub.example.com". The address can also be a number, such as 203.0.113.25. When your user name is the same on both computers, leave out sam@.
You don't need to rent a server to practice. Your own computer can be one, under the name localhost (read "local host"), the name every computer has for itself. Try it:
ssh localhost
ssh: connect to host localhost port 22: Connection refused
Connection refused means ssh found the computer, but no program there is waiting for SSH logins. A server runs an SSH server program for that, and a laptop doesn't have one turned on. To practice, turn it on. This changes your computer: anyone who can reach it over the network can try to log in with your user name and password, so turn it off again when you've finished this chapter.
sudo apt install openssh-server # Ubuntu, and Ubuntu in WSL: installs it and starts it
sudo apt remove openssh-server # when you're done: turns it off for good
On a Mac, open System Settings, then General, then Sharing, and turn on Remote Login. Turn it off there when you're done.
A cloud server, a computer you rent in a data center, is an optional extra. It costs money for every hour it exists, used or not, and free trials usually ask for a credit card, so read the price first and delete it when you're done. Everything in this chapter works on localhost for free.
The first time: "Are you sure?"
Connect to a computer for the first time, with ssh localhost now that its server is on, and ssh stops to ask a question:
Think of a phone call from someone who says they're your bank. Before you tell them anything, you check the number against the one printed on your card. Every SSH server has its own host key, and the key's fingerprint, SHA256: and 43 letters and numbers, is its printed number. ssh has never met this computer, so it can't tell the real one from an impostor in between. It shows you the fingerprint and asks Are you sure you want to continue connecting (yes/no/[fingerprint])?
- Answer
yeswhen the fingerprint matches the one the computer's owner gave you. A cloud provider shows it on the server's page. On your own computer,ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pubprints it. - ssh then saves the key in
~/.ssh/known_hosts, its list of computers you've met, and never asks about this one again. - If that key ever changes, ssh refuses with a loud REMOTE HOST IDENTIFICATION HAS CHANGED! The server may have been rebuilt, or someone may be in the middle: ask its owner before you go on.
Inside, and home again
Next, ssh asks for your password on that computer: sam@localhost's password:. Nothing shows while you type it, as with sudo. Then come the computer's welcome message and its prompt, and everything you type runs there: ls lists its files. Not sure which computer you're on? Read the prompt: on a real server it has the server's name, such as sam@bookclub:~$.
To leave, type exit, or press Ctrl+D. ssh says Connection to localhost closed., and your own prompt is back.
When it doesn't work, the message says where to look. Names that end in .invalid never exist, so this one fails every time:
ssh sam@bookclub.invalid
ssh: Could not resolve hostname bookclub.invalid: Name or service not known
| Message | What it means |
|---|---|
Could not resolve hostname |
No computer has that name. Check the spelling. (A Mac words the end of the line differently.) |
Connection refused |
The computer is there, but no SSH server is waiting for logins. |
Permission denied |
The user name or password is wrong, or the server accepts only keys, the next lesson's subject. |
Check yourself
2 questions to try on the lesson page.
So what
With ssh, any computer you're allowed into is one line away, screen or no screen, and the fingerprint question keeps you from typing your password into the wrong one.