Course contents

Unit 7: TCP, UDP and PortsLesson 7.3.3 (18 of 23 in this unit)67 of 104 in the Network Fundamentals course

SSH and Telnet

Logging in to a router or server remotely, and why SSH replaced Telnet.

Beginner · 8 min read

Covers Remote CLI, Encryption and Configuring SSH.

Technical definition

SSH (Secure Shell) is a protocol that provides an encrypted, authenticated remote command-line session, by default over TCP port 22. It replaces Telnet (TCP port 23), which sends everything, including passwords, in clear text.

A VLAN change five floors up

A switch in a wiring closet on the fifth floor needs a new VLAN. You are at your desk on the ground floor. Walking up with a console cable works, but it is slow, and with 200 switches it is not practical. You need to reach each device's command line over the network.

Two ways to reach a remote CLI

Telnet and SSH (Secure Shell) both give you a remote CLI (command-line interface). You type commands on your computer, and they run on the remote device. On a Cisco device, remote sessions arrive on VTY lines (virtual terminal lines), numbered 0 to 4 or 0 to 15.

Diagram
Two ways to reach a remote CLI
Two ways to reach a remote CLI
TelnetSSH
PortTCP 23TCP 22
EncryptionNone: everything is in clear textThe whole session is encrypted
Server identity checkNoYes, with the server's host key
Login optionsPasswordPassword or public key
Use todayOld labs, port testingStandard for remote management
Read each row across: the left box names the item, the others describe it.

Why SSH replaced Telnet

Telnet sends every keystroke as clear text, including the username and password. Anyone who can capture traffic on the path can read them. SSH encrypts the session before the login prompt even appears.

Diagram
What an attacker on the path can see
What an attacker on the path can see
Admin PCIP 10.1.1.50Access switchAttackercapturingR1IP 10.1.1.1

Device key: Admin PC, Attacker (laptop) · R1 (router)

Lines show the example’s network connections. Dashed wireless links: radio connections. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • Admin PC: IP 10.1.1.50
  • Attacker: capturing
  • R1: IP 10.1.1.1
  1. 1. Telnet: the attacker's capture shows "Username: admin" and "Password: Cisco123" in clear text.
  2. 2. SSH: the attacker sees only random-looking bytes. The password never appears.

How an SSH session starts

Step 1 of 4 · Version exchange
Admin PC
IP 10.1.1.50
Management LAN
R1
10.1.1.1:22

Device key: Admin PC (laptop) · R1 (router)

Arrows run from each message's sender to its receiver. Rows show message order, not separate cables or elapsed time to scale. Port numbers identify services or conversations, not physical switch sockets.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • Admin PC: IP 10.1.1.50
  • R1: 10.1.1.1:22

The first time you connect, your SSH client asks you to accept R1's host key. If the key changes later, treat it as a warning sign.

Configure SSH on a Cisco router

SSH needs a hostname and a domain name (used to name the key), an RSA key pair, a local user and VTY lines that accept only SSH. This configuration is based on Cisco documentation, not run on a lab device:

hostname R1
ip domain name example.com
crypto key generate rsa modulus 2048
ip ssh version 2
username admin privilege 15 secret Str0ng-Passw0rd
!
line vty 0 4
 login local
 transport input ssh
 exec-timeout 10 0

crypto key generate rsa modulus 2048 creates the key pair, and ip ssh version 2 allows only SSH version 2. login local checks the username and password against the local user list. transport input ssh blocks Telnet on these lines (on a switch, also configure line vty 5 15). exec-timeout 10 0 logs out an idle session after 10 minutes.

A classic way to lock yourself out is to apply transport input ssh and login local before the RSA key or the local user exists. Keep the console or your current session open until a fresh SSH login works.

Confirming SSH version 2 is in use

This output is based on Cisco documentation, not run on a lab device.

Example output · based on Cisco documentation; exact format varies by platform and software version
R1#show ip ssh
SSH Enabled - version 2.0
Authentication methods:publickey,keyboard-interactive,password
Encryption Algorithms:aes128-ctr,aes192-ctr,aes256-ctr
MAC Algorithms:hmac-sha2-256,hmac-sha2-512
Authentication timeout: 120 secs; Authentication retries: 3
Minimum expected Diffie Hellman key size : 2048 bits
What to look for: SSH Enabled - version 2.0 confirms that SSH is running (so the RSA key exists) and that only SSH version 2 is allowed. The Encryption Algorithms line lists the ciphers R1 will accept, and Authentication retries: 3 is how many failed logins are allowed per connection.
Example output · based on Cisco documentation; exact format varies by platform and software version
R1#show ssh
Connection Version Mode Encryption  Hmac           State             Username
0          2.0     IN   aes256-ctr  hmac-sha2-256  Session started   admin
0          2.0     OUT  aes256-ctr  hmac-sha2-256  Session started   admin
%No SSHv1 server connections running.
What to look for: one active session (connection 0) from user admin, using SSH version 2.0. The IN and OUT lines show it is encrypted with AES-256 in both directions.
ssh -l admin 10.1.1.1

Connect from a PC (or from another Cisco router) to R1 as user admin.

Test yourself on SSH and Telnet

Predict · scenario 1

You configure transport input ssh on R1's VTY lines. A colleague then tries telnet 10.1.1.1. What happens?

Predict · scenario 2

On a new router, crypto key generate rsa fails with an error asking for a domain name. Why?