Sub topic 12
SSH: encrypted command-line access
What this chapter assumes
This chapter assumes you can use a Windows command prompt and a Linux shell. It also assumes you know what an IP address, a port, and a firewall are. You do not need earlier SSH experience.
Secure Shell (SSH) is a protocol that gives you an encrypted command-line session on another computer. It also carries file transfers and forwarded network traffic. On the A+ Core 2 exam, SSH is the standard answer when a question asks for secure remote command-line access to a Linux server, a router, a switch, or another network device.
What SSH does
SSH uses a client-server model. The SSH server (often called the daemon, or sshd on Linux) listens for connections. The SSH client starts them. Once connected, you type commands on your own machine and they run on the remote one. Output comes back to your screen.
SSH provides three protections:
- Confidentiality. Everything in the session is encrypted, including your password and your commands.
- Integrity. SSH detects data that was changed in transit.
- Authentication. The client checks the server's identity, and the server checks the user's identity.
The default port is TCP 22. Memorize this number for the exam.
Why SSH replaced Telnet
Telnet is an older protocol that also gives remote command-line access. It uses TCP port 23 and sends everything in clear text. Anyone who captures the traffic can read the username, the password, and every command.
| Feature | Telnet | SSH |
|---|---|---|
| Default port | TCP 23 | TCP 22 |
| Encryption | None | Yes |
| Typical use today | Legacy devices, testing a port | Standard remote administration |
| Exam guidance | Insecure, avoid | Preferred |
If an exam question asks you to replace Telnet with something secure, the answer is SSH.
Connecting from a client
The basic command is ssh, followed by a username and a host. The host can be an IP address or a name.
ssh [email protected]This opens an encrypted command-line session as user admin to the host at 192.168.1.10, using port 22. If the server uses a different port, add -p:
ssh -p 2222 [email protected]Windows 10 and Windows 11 include an OpenSSH client, so the same commands work in Command Prompt and PowerShell. Linux and macOS include it by default. Older Windows setups often used a separate program such as PuTTY, which is a free graphical SSH client.
You can also run a single command and return to your own prompt:
ssh [email protected] "df -h"This is useful inside scripts, which connects this chapter to the scripting chapters earlier in the tutorial.
The first connection and host keys
The first time you connect to a server, the client shows a message like this:
The authenticity of host '192.168.1.10' can't be established.
ED25519 key fingerprint is SHA256:...
Are you sure you want to continue connecting (yes/no)?Every SSH server has a host key. The fingerprint is a short summary of that key. If you answer yes, the client saves the key in a file called known_hosts in your .ssh folder. On later connections, the client compares the server's key to the saved copy.
If the key suddenly differs, the client prints a loud warning. This can mean the server was rebuilt or reinstalled. It can also mean someone is intercepting your connection (a man-in-the-middle attack). Do not simply delete the saved entry and continue. First confirm with the server's owner why the key changed.
Authentication methods
SSH supports several ways to prove who you are.
Password authentication
You type the account password. It is simple and works everywhere. The password is encrypted in transit, but it can still be guessed. Servers exposed to the internet receive constant automated login attempts, called brute-force attacks.
Key-based authentication
You create a key pair: a private key and a public key. The public key goes on the server. The private key stays on your computer and is never shared. When you connect, the client proves it holds the private key without sending it.
Create a key pair and copy the public key to the server:
ssh-keygen -t ed25519
ssh-copy-id [email protected]ssh-keygen asks where to save the key and for an optional passphrase. Set a passphrase. It encrypts the private key file, so a stolen file is not enough on its own to log in. On Windows, ssh-copy-id is not always present. In that case, append the contents of your .pub file to ~/.ssh/authorized_keys on the server.
Key-based login is stronger than passwords and allows unattended scripts to log in without storing a password. Once keys work, an administrator can turn off password logins in the server configuration file (/etc/ssh/sshd_config) by setting PasswordAuthentication no.
Other methods
Some environments add multifactor authentication, or use certificates, to strengthen login. The exam focus is mainly on knowing that passwords and keys exist and that keys are preferred.
Related tools: SCP and SFTP
SSH also carries file transfers.
- SCP (Secure Copy) copies files over SSH with a single command.
- SFTP (SSH File Transfer Protocol) offers an interactive session for browsing, uploading, and downloading. It runs over SSH on port 22. Do not confuse it with FTPS, which is FTP with TLS, or plain FTP, which is unencrypted.
scp report.txt [email protected]:/home/admin/
scp [email protected]:/var/log/syslog ./syslog-copyThe first command uploads a file. The second downloads one.
Port forwarding (tunneling)
SSH can wrap other traffic inside its encrypted connection. This is called a tunnel or port forwarding. For example, this command makes local port 8080 reach a web server that is only visible from the remote network:
ssh -L 8080:internal-web:80 [email protected]You can then browse to http://localhost:8080 on your own machine. The traffic between your computer and the SSH server is encrypted. The A+ exam rarely goes deep on this, but you should know SSH can tunnel other protocols.
Securing an SSH server
SSH is only as safe as its configuration. Common hardening steps:
- Use key-based authentication and disable password logins where possible.
- Disable direct login as
root(PermitRootLogin no) and use a normal account withsudo. - Limit which users may connect (
AllowUsers). - Restrict port 22 in the firewall to known source addresses.
- Keep the SSH software updated.
- Watch logs for repeated failed logins.
Changing the port from 22 to another number reduces noise from automated scans. It does not stop a determined attacker, so treat it as a minor measure and never as the only one.
Troubleshooting common errors
| Symptom | Likely cause | What to check |
|---|---|---|
| Connection timed out | Firewall blocks port 22, wrong IP, or host is down | Ping the host, check firewall rules |
| Connection refused | The host is reachable but `sshd` is not running or uses another port | Start the service, confirm the port |
| Permission denied | Wrong password, wrong key, or user not allowed | Check the username, key file, and permissions |
| Host key changed warning | Server was rebuilt, or possible interception | Verify with the server's owner before continuing |
| Key ignored | Private key file permissions are too open | On Linux, run `chmod 600` on the private key |
Timed out and refused look similar but differ. A timeout means packets got no answer, often because a firewall dropped them. A refusal means the host answered and said no, so the network path works.
Choosing SSH
SSH fits when you need a command line, not a desktop. It uses very little bandwidth and works well over slow links. It is the usual tool for servers, routers, switches, and scripted tasks. If the user needs to see and use a graphical desktop, RDP or VNC fits better. If you need access to a whole private network rather than one host, a VPN fits better. Those are covered in neighboring chapters.
Practice
Exercise
A technician must run a maintenance command on a Linux server from a laptop. The session must be encrypted, and the technician needs only a command line. Which protocol and default port should be used?
Show answer
SSH on TCP port 22. For example: ssh [email protected]. Telnet (TCP 23) is unencrypted, and RDP or VNC provide a graphical desktop that is not needed here.
Exercise
You connect to a server you have used for months, and the client warns that the host key has changed. What should you do, and why?
Show answer
Stop and do not accept the new key yet. A changed key can mean the server was reinstalled, or that someone is intercepting the connection. Confirm the change with the server's owner, then replace the old entry in known_hosts only if the change is legitimate.
Exercise
A user gets "Connection refused" when running ssh to a server, but ping to the same address succeeds. What does this suggest, and how does it differ from "Connection timed out"?
Show answer
The host is reachable, but nothing is accepting connections on the SSH port. The sshd service may be stopped or listening on a different port. A timeout would suggest packets are being dropped, often by a firewall, or the host is unreachable.