← Networking and Remote Servers from Zero
Connect to a server with SSH: ssh, whoami, -p, exit and -v

Lesson 4 of 6

Connect to a server with SSH: ssh, whoami, -p, exit and -v

Log in to a remote machine from your own terminal. Learn how SSH works, what the fingerprint warning means, how to use another port, and how to debug a failed login.

The idea in plain words

SSH stands for secure shell. Think of it as a remote control for another computer, where everything you type travels in a locked tunnel. Your laptop is the client, and the remote machine, the server, listens on port 22.

To use the remote control you need three things: a user name, the server address and a way to prove who you are. At first that proof is a password. In the next lesson you will switch to keys.

Commands in this lesson

ssh ava@203.0.113.10
Log in to a server as a user. The first time, SSH asks you to trust the server fingerprint.
whoami
Print the user you are logged in as. Pair it with hostname to confirm which machine you are on.
ssh -p 2222 ava@203.0.113.10
Connect on a port other than the default 22.
exit
Close the SSH session and return to your own computer. Ctrl+D does the same.
ssh -v ava@203.0.113.10
Print what SSH is doing step by step. Add more v letters for more detail.

Written notes from the video

Why SSH

Servers live far away, in data centres, without a screen or a keyboard. This is Networking and Remote Servers from zero, episode four: connecting with SSH. By the end, you will be able to log in to a remote machine from your own terminal.

The remote control analogy

SSH stands for secure shell. Think of it as a remote control for another computer, where everything you type travels in a locked tunnel. Your laptop is the client. The remote machine, the server, listens on port 22. You need three things: a user name, the server address, and a way to prove who you are. For now, that proof is a password. In the next episode, you will switch to keys.

Command 1: ssh

Command one: ssh, then your user name, an at sign, and the server address. The first time, SSH shows the server's fingerprint, and asks if you trust it. Type yes. SSH remembers it in a file called known_hosts. Then enter your password. Nothing appears while you type. That is normal. Your prompt changes to the server. Every command now runs there, not on your laptop.

Command 2: whoami and hostname

Command two: whoami, and hostname. whoami prints the user you are logged in as. hostname prints the name of the machine you are on. Run these whenever you are unsure which computer you are typing into. It prevents expensive mistakes.

Command 3: ssh -p

Command three: ssh -p. Some servers move SSH off port 22, to cut down on random login attempts. Use -p, then the port number, to connect. If it times out, check the port, and check the firewall from the last episode.

Command 4: exit

Command four: exit. It closes the SSH session, and brings you back to your laptop. Control D does the same. Always log out of servers you have finished with.

Command 5: ssh -v

Command five: ssh -v. -v prints what SSH is doing, step by step. It is your debugging tool. You can see it connect, check the server, and try each way to log in. Add more v letters for even more detail. If a login fails, this tells you why.

Recap

Recap. ssh user@host logs you in. whoami and hostname tell you where you are. ssh -p uses another port. exit logs you out. And ssh -v shows what is going on.

Next episode

Next episode: SSH keys. You will log in without a password, and save shortcuts for your servers. Subscribe so you do not miss it, and find written notes for every lesson at changecv.com/skills.

Common questions

What does the fingerprint warning mean?

The first time you connect, SSH shows a fingerprint of the server’s key and asks whether you trust it. Compare it with the one your hosting provider shows if you can, then type yes. SSH remembers it in the known_hosts file.

Why does nothing appear when I type my password?

SSH hides the password as you type, even the number of characters. It is working, so type the password and press enter.

What is the default SSH port?

Port 22. Some servers use a different number to cut down on random login attempts, in which case you add -p and the port to the command.

What does "Permission denied (publickey)" mean?

The server only accepts key logins and did not accept the key you offered. Lesson 5 shows how to create a key and install it on the server.

Can I use SSH on Windows?

Yes. Current versions of Windows include the OpenSSH client, so ssh works in PowerShell and the Windows Terminal.