SSH Configuration & Telnet Hardening (Cisco IOS)
Telnet sends all data — including usernames and passwords — as plain text across the network. Anyone running a packet capture tool such as Wireshark on the same network can read every character you type. SSH (Secure Shell) encrypts the entire session, making it the only acceptable protocol for remote management of Cisco routers and switches in any production environment. For a conceptual overview, see SSH and SSH & Telnet Security.
This lab covers the complete process of enabling SSHv2 on a Cisco device — from prerequisites (hostname, domain name, RSA keys) through VTY line hardening and final verification. Before starting, make sure Hostname, Password, and Banner Configuration and Console & VTY Line Configuration are already in place.
SSH vs Telnet — Why It Matters
| Feature | Telnet | SSH |
|---|---|---|
| Encryption | ❌ None — plain text | ✅ Full session encryption |
| TCP Port | 23 | 22 |
| Password visibility | Visible in a packet capture | Encrypted — unreadable in a capture |
| Authentication | Password only | Password or public key authentication. See AAA Authentication Methods. |
| Use in production | ❌ Never | ✅ Always |
| CCNA exam relevance | Know why it is insecure | Know how to configure SSHv2 |
SSH Versions
| Version | Status | Notes |
|---|---|---|
| SSHv1 | ⚠️ Legacy — deprecated | Known security vulnerabilities. Some older IOS versions default to v1. Always force v2. |
| SSHv2 | ✅ Current standard | Stronger encryption, improved integrity checking. Required for CCNA compliance. |
SSH Prerequisites on Cisco IOS
SSH on Cisco IOS requires three items to be configured before RSA keys can be generated.
If any of these are missing, the crypto key generate rsa command will either
fail or produce a non-functional result:
| Requirement | Command | Why Required |
|---|---|---|
| Hostname (not default) | hostname NetsTuts_R1 |
The RSA key name is derived from hostname.domain-name. A default hostname (Router/Switch) produces a generic key name. See Hostname, Password, and Banner Configuration. |
| Domain name | ip domain-name netstuts.com |
Required to complete the FQDN used in key generation. Without it, crypto key generate rsa may fail. |
| Local user account | username admin privilege 15 secret ... |
SSH requires login local on VTY lines — a local user must exist for authentication to succeed. See Console & VTY Line Configuration. |
Lab Scenario
In this lab, NetsTuts_R1 will be fully configured for SSHv2 access with Telnet completely disabled:
| Parameter | Value |
|---|---|
| Device hostname | NetsTuts_R1 |
| Domain name | netstuts.com |
| RSA key size | 2048 bits |
| SSH version | 2 (forced) |
| Authentication timeout | 60 seconds |
| Max authentication retries | 3 |
| VTY transport | SSH only (Telnet disabled). See Console & VTY Line Configuration. |
| Local username | admin / privilege 15 |
Step 1: Configure Prerequisites
Set the hostname, domain name, and local user account before generating RSA keys. If your device already has these from a previous lab, skip to Step 2.
NetsTuts_R1>en NetsTuts_R1#conf t Enter configuration commands, one per line. End with CNTL/Z. NetsTuts_R1(config)#hostname NetsTuts_R1 NetsTuts_R1(config)#ip domain-name netstuts.com NetsTuts_R1(config)#username admin privilege 15 secret Admin@Secure1!
Step 2: Generate RSA Keys
RSA keys are the cryptographic foundation of SSH on Cisco IOS. The key pair (public + private) is used to establish the encrypted session. A larger key size provides stronger encryption — 2048 bits is the current recommended minimum. Keys smaller than 768 bits do not support SSHv2.
NetsTuts_R1(config)#crypto key generate rsa modulus 2048 The name for the keys will be: NetsTuts_R1.netstuts.com % The key modulus size is 2048 bits % Generating 2048 bit RSA keys, keys will be non-exportable... [OK] (elapsed time was 3 seconds) NetsTuts_R1(config)#
NetsTuts_R1.netstuts.com) and size (2048 bits).
Key generation may take a few seconds — this is normal.
RSA Key Size Guide
| Modulus Size | SSH Version Support | Recommendation |
|---|---|---|
| 512 bits | SSHv1 only | ❌ Too weak — never use |
| 768 bits | SSHv1 and SSHv2 | ⚠️ Minimum for SSHv2 — below current standards |
| 1024 bits | SSHv1 and SSHv2 | ⚠️ Acceptable but not ideal |
| 2048 bits | SSHv2 | ✅ Recommended minimum for production |
| 4096 bits | SSHv2 | ✅ Maximum security — slower key generation |
NetsTuts_R1(config)#crypto key zeroize rsa
This immediately destroys all RSA keys and disables SSH until new keys are generated.
Step 3: Force SSHv2
After generating RSA keys, Cisco IOS enables SSH but may allow both SSHv1 and SSHv2 connections. You must explicitly force version 2 to prevent clients from negotiating the weaker v1:
NetsTuts_R1(config)#ip ssh version 2
Additional SSH Hardening Parameters
NetsTuts_R1(config)#ip ssh time-out 60 NetsTuts_R1(config)#ip ssh authentication-retries 3
ip ssh time-out 60 — SSH negotiation must complete within 60 seconds.
ip ssh authentication-retries 3 — after 3 failed login attempts, the connection is dropped.
See show logging to review connection failure events
captured by syslog.
| Command | Default | Recommended | Purpose |
|---|---|---|---|
ip ssh version 2 |
Both v1 and v2 | v2 only | Prevents weak SSHv1 connections |
ip ssh time-out 60 |
120 seconds | 60 seconds | Reduces window for incomplete connection attacks |
ip ssh authentication-retries 3 |
3 | 2–3 | Limits brute-force attempts per connection. See Brute-Force Protection |
Step 4: Configure VTY Lines for SSH Only
Generating RSA keys and setting ip ssh version 2 makes SSH available on
the device, but VTY lines control what is actually accepted for remote connections.
You must set transport input ssh to explicitly disable Telnet and
enforce SSH as the only allowed protocol. For full VTY line options including
access-class ACLs, see Console & VTY Line Configuration.
NetsTuts_R1(config)#line vty 0 4 NetsTuts_R1(config-line)#login local NetsTuts_R1(config-line)#transport input ssh NetsTuts_R1(config-line)#exec-timeout 10 0 NetsTuts_R1(config-line)#logging synchronous NetsTuts_R1(config-line)#exit NetsTuts_R1(config)#end NetsTuts_R1#wr Building configuration... [OK] NetsTuts_R1#
login local requires credentials from the local user database.
logging synchronous prevents syslog messages from interrupting CLI input —
see Syslog Configuration for syslog setup.
Save the completed configuration with copy run start.
transport input ssh
is sufficient to block Telnet. Some engineers also add
transport output ssh to prevent the device from initiating Telnet
connections to other devices — a useful additional control in high-security
environments.
Step 5: Complete SSH Baseline Configuration
The following is the complete SSH configuration from start to finish for NetsTuts_R1:
! ══════════════════════════════════════════════════════════ ! NetsTuts SSH Hardening Baseline — NetsTuts_R1 ! ══════════════════════════════════════════════════════════ NetsTuts_R1>en NetsTuts_R1#conf t Enter configuration commands, one per line. End with CNTL/Z. ! ── Prerequisites ───────────────────────────────────────── NetsTuts_R1(config)#hostname NetsTuts_R1 NetsTuts_R1(config)#ip domain-name netstuts.com NetsTuts_R1(config)#username admin privilege 15 secret Admin@Secure1! ! ── Generate RSA keys ───────────────────────────────────── NetsTuts_R1(config)#crypto key generate rsa modulus 2048 ! ── SSH hardening ───────────────────────────────────────── NetsTuts_R1(config)#ip ssh version 2 NetsTuts_R1(config)#ip ssh time-out 60 NetsTuts_R1(config)#ip ssh authentication-retries 3 ! ── VTY lines: SSH only ─────────────────────────────────── NetsTuts_R1(config)#line vty 0 4 NetsTuts_R1(config-line)#login local NetsTuts_R1(config-line)#transport input ssh NetsTuts_R1(config-line)#exec-timeout 10 0 NetsTuts_R1(config-line)#logging synchronous NetsTuts_R1(config-line)#exit ! ── Save ────────────────────────────────────────────────── NetsTuts_R1(config)#end NetsTuts_R1#wr Building configuration... [OK] NetsTuts_R1#
6. Verification
show ip ssh
Confirms SSH is enabled, the version, timeout, and retry settings:
NetsTuts_R1#show ip ssh SSH Enabled - version 2.0 Authentication timeout: 60 secs; Authentication retries: 3 Minimum expected Diffie Hellman key size : 1024 bits IOS Keys in SECSH format(ssh-rsa, base64 encoded): NetsTuts_R1.netstuts.com
ip ssh version 2 is in the running config
with show running-config | section ssh.
show ssh
Shows all currently active SSH sessions:
NetsTuts_R1#show ssh %No SSHv1 server connections running. 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
show crypto key mypubkey rsa
Verifies RSA keys were generated successfully and shows the key name and size:
NetsTuts_R1#show crypto key mypubkey rsa % Key pair was generated at: 00:01:14 UTC Mar 1 1993 Key name: NetsTuts_R1.netstuts.com Key type: RSA KEYS Storage Device: not specified Usage: General Purpose Key Key is not exportable. Key Data: 30820122 300D0609 2A864886 F70D0101 01050003 82010F00 ...
show running-config | section ssh
NetsTuts_R1#show running-config | section ssh ip ssh version 2 ip ssh time-out 60 ip ssh authentication-retries 3
show running-config filtered by section
to audit all SSH-related configuration lines in one view.
Verify from a Client — SSH Connection Test
From another Cisco device on the network, use the built-in SSH client to test connectivity.
First confirm reachability with ping, then attempt SSH:
NetsTuts_PC1#ssh -l admin 192.168.1.1 Password: ***Unauthorized access is strictly prohibited.*** NetsTuts_R1>
ssh -l [username] [IP] connects to the target device via SSH.
The MOTD banner appears after successful authentication.
You are now in a fully encrypted remote session.
Verify Telnet is Blocked
NetsTuts_PC1#telnet 192.168.1.1 Trying 192.168.1.1 ... % Connection refused by remote host
transport input ssh on the VTY lines
is working correctly.
Verification Command Summary
| Command | What It Confirms |
|---|---|
show ip ssh |
SSH version, timeout, retries — confirms SSHv2 is active |
show ssh |
Active SSH sessions, encryption cipher, and authenticated username |
show crypto key mypubkey rsa |
RSA key name, size, and generation status |
show running-config | section ssh |
All SSH-related configuration lines in running config |
show running-config | section line vty |
Confirms transport input ssh and login local on VTY |
ssh -l [user] [IP] |
End-to-end test — confirms SSH connects and Telnet is blocked |
ping [IP] |
Verify IP reachability before troubleshooting SSH connectivity |
7. Troubleshooting SSH Issues
| Problem | Symptom | Cause | Fix |
|---|---|---|---|
| SSH not available | show ip ssh shows "SSH disabled" |
RSA keys not generated, or hostname/domain name missing | Set ip domain-name, verify hostname is not default, then run crypto key generate rsa modulus 2048. See Hostname Configuration. |
| SSHv1 still accepted | show ip ssh shows "version 1.99" |
ip ssh version 2 not configured |
Add ip ssh version 2 to the configuration. Verify with show running-config | section ssh. |
| Authentication fails | Username and password rejected every time | No local user exists, or login local not set on VTY |
Verify user with show running-config | section username; confirm login local on VTY lines. See VTY Line Configuration. |
| Connection refused | SSH client reports connection refused or times out | Management IP not reachable, or ACL blocking the source IP | Ping the device IP first; check VTY ACL with show ip access-lists. See Standard ACL Configuration for VTY ACL setup. |
| Telnet still accepted | Telnet connects successfully when it should be blocked | transport input ssh not applied, or applied to wrong VTY range |
Check all VTY ranges with show running-config | section line vty |
| RSA keys deleted accidentally | SSH stops working after a configuration change | crypto key zeroize rsa was run, or hostname/domain changed after key generation |
Regenerate with crypto key generate rsa modulus 2048. Check show logging for clues about when the change occurred. |
NetsTuts_R1(config)#crypto key zeroize rsa
NetsTuts_R1(config)#crypto key generate rsa modulus 2048
After regenerating, save the configuration immediately with
wr.
Key Points & Exam Tips
- Telnet sends all data as plain text on TCP port 23 — never use it in production. SSH uses TCP port 22 and encrypts the entire session. See SSH & Telnet Security for a full comparison.
- SSH requires three prerequisites before RSA keys can be generated: a non-default hostname, an ip domain-name, and a local user account. See Hostname, Password, and Banner Configuration.
- RSA key size must be at least 768 bits to support SSHv2. The current recommended minimum is 2048 bits.
- Always force SSHv2 with
ip ssh version 2— without it, the device may accept SSHv1 connections which have known vulnerabilities. show ip sshis the primary verification command — it shows the SSH version, timeout, and retry count. Version 1.99 means both v1 and v2 are accepted — version 2.0 means v2 only.transport input sshon VTY lines is what actually blocks Telnet — generating RSA keys alone does not disable Telnet. Always configure all VTY line ranges. See Console & VTY Line Configuration.- If you change the hostname or domain name after generating RSA keys, you must
crypto key zeroize rsaand regenerate. ip ssh authentication-retries 3limits failed login attempts — pair this with login block-for for full brute-force protection.- Use
show sshto see active sessions including the encryption cipher — aes256-ctr with hmac-sha2-256 is the current strong standard. - Test both directions after configuration: confirm SSH connects successfully and confirm Telnet is actively refused.
- This SSH configuration is a prerequisite for automation tools: Python Netmiko, NAPALM, and RADIUS/TACACS+ centralised authentication all depend on SSH being correctly configured.