Sub topic 10
Remote access: SSH, Telnet and RDP
This chapter assumes you know what a port is, how TCP differs from UDP, and how to run commands in a terminal. Remote access protocols let you control another machine over the network. Three are common, and each has a default port.
The three protocols
| Protocol | Default port | Transport | Encrypted | Typical use |
|---|---|---|---|---|
| SSH | 22 | TCP | Yes | Command line on Linux, network devices, servers |
| Telnet | 23 | TCP | No | Legacy devices, lab equipment |
| RDP | 3389 | TCP and UDP | Yes | Graphical desktop on Windows |
SSH on port 22
Secure Shell (SSH) gives you an encrypted terminal session. It authenticates the server with a host key and the user with a password or a key pair. It also carries other traffic, such as SFTP and port forwarding, inside the same connection.
Telnet on port 23
Telnet gives you a terminal session, but it sends everything as plain text. That includes your username and password. Anyone who can capture the traffic can read it. Use Telnet only on an isolated lab network, or not at all.
RDP on port 3389
Remote Desktop Protocol (RDP) shows you a Windows desktop and carries keyboard, mouse, clipboard and audio. It uses TCP 3389. Newer versions can also use UDP 3389 for smoother video. RDP encrypts its traffic, but an RDP port exposed to the internet is a frequent target of password-guessing attacks.
Seeing the difference
Telnet shows why plain text matters. The script below reads the first bytes a server sends on port 22. An SSH server announces its version in readable text before encryption starts. Replace the address with a host you own.
import socket
with socket.create_connection(("192.0.2.10", 22), timeout=5) as s:
print(s.recv(256).decode("ascii", errors="replace"))A typical reply looks like SSH-2.0-OpenSSH_9.6. Only this banner is readable. Everything after the key exchange is encrypted.
You can also check which names your system maps to these ports:
import socket
for name in ("ssh", "telnet"):
print(name, socket.getservbyname(name, "tcp"))RDP may not appear in the services file on every system, so look it up in the IANA registry if it is missing.
Common errors
- Connection refused. Nothing is listening on that port, or a firewall rejected the connection. Check with
ss -tlnpon the server. - Connection timed out. A firewall is probably dropping packets silently.
- Changed port. Administrators often move SSH to another port, such as 2222. Use
ssh -p 2222 user@hostto connect. - Assuming the port proves the protocol. A service on port 22 is probably SSH, but the number alone does not guarantee it.
Exercise
A colleague says they "secured" a router by moving Telnet from port 23 to port 2323. Is the router now secure, and what should they do instead?
Show answer
No. Changing the port does not encrypt anything, so passwords still cross the network in plain text and a port scan will find the service. They should disable Telnet and use SSH on port 22, preferably with key authentication and access limited to a management network.
Exercise
Which transport protocol or protocols does RDP use by default, and on which port?
Show answer
RDP uses TCP port 3389, and newer versions can also use UDP port 3389.