Skip to content

Expert · Network security · topic 42 of 57 · 30 min

Securing device access: secrets and SSH

Explanation

A router or switch is only as safe as the way people log in to it. Use enable secret (hashed) instead of enable password, personal usernames with login local, and SSH version 2 instead of Telnet on the VTY lines. Add timeouts, login delays, a warning banner, and shut down unused ports and services.

Why harden devices?

Hardening means removing easy ways in. A new Cisco device is built to be easy to set up, not to be safe on a live network. Anyone who gets into a router can read its configuration, redirect traffic or take the network down. So the first job after the basic setup is to lock the doors: the console, the VTY lines (the virtual lines used for remote logins) and privileged EXEC mode.

enable secret, not enable password

Privileged EXEC mode (the # prompt) can change anything, so it needs a password. enable password stores it in plain text in the configuration. enable secret stores a one-way hash, which cannot simply be turned back into the password. If both are set, the device uses enable secret and ignores enable password.

output
Router(config)# hostname R1
R1(config)# enable secret Ch@iT1me-2026!
R1(config)# service password-encryption
R1(config)# username admin secret Str0ng-Passphrase-77
R1(config)# do show running-config | include secret|password
Cisco IOS: a hashed enable secret, a local user with a hashed secret, and type 7 hiding for any remaining plain passwords.
Careful: service password-encryption only hides passwords such as line passwords with a weak "type 7" scheme. Free tools reverse type 7 in a second. It stops someone reading a password over your shoulder, nothing more. Always use "secret" (enable secret, username ... secret) for real protection.

Local users and login local

A shared line password gives no accounting: you cannot tell who logged in. Instead, create a username for each engineer and tell the lines to check the local user list with login local. In larger networks the same idea moves to a TACACS+ or RADIUS server, with local users kept as a fallback.

SSH instead of Telnet

Telnet (TCP 23) sends everything in clear text, including the password. Anyone who can capture the traffic can read it. SSH (Secure Shell, TCP 22) encrypts the whole session. SSH needs an RSA key pair, and the key name is built from the hostname and domain name, so those come first.

output
R1(config)# hostname R1
R1(config)# ip domain-name campus.local
R1(config)# crypto key generate rsa modulus 2048
R1(config)# ip ssh version 2
R1(config)# username admin secret Str0ng-Passphrase-77
R1(config)# line vty 0 4
R1(config-line)# transport input ssh
R1(config-line)# login local
R1(config-line)# exec-timeout 5 0
R1(config-line)# exit
Cisco IOS: SSH step by step. Many switches have 16 VTY lines, so use line vty 0 15 there.
  1. Set a hostname other than the default Router or Switch.
  2. Set a domain name with ip domain-name.
  3. Generate the RSA keys: crypto key generate rsa modulus 2048. SSH version 2 needs at least 768 bits; 2048 is the sensible minimum today.
  4. Force version 2 with ip ssh version 2. Version 1 has known weaknesses.
  5. Create a local user with a secret.
  6. On the VTY lines allow only SSH (transport input ssh) and use login local.
  7. Test from a PC: ssh -l admin 192.168.1.1, and check with show ip ssh and show ssh.

Timeouts, login delays and banners

exec-timeout 5 0 logs out an idle session after 5 minutes and 0 seconds, so a forgotten open session on a desk PC does not stay logged in all day. login block-for 120 attempts 3 within 60 blocks all logins for 120 seconds if 3 attempts fail within 60 seconds, which slows password guessing. A banner motd shows a legal warning before login; it does not stop anyone, but it makes clear that access is only for authorised users.

output
R1(config)# login block-for 120 attempts 3 within 60
R1(config)# banner motd # Authorised access only. Activity is logged. #
R1(config)# line console 0
R1(config-line)# login local
R1(config-line)# exec-timeout 5 0
R1(config-line)# exit
R1(config)# no ip http server
R1(config)# no ip http secure-server
Cisco IOS: slowing password guessing, a warning banner, a protected console, and the built-in web server turned off.

Turn off what you do not use

Every running service and every live port is a possible way in. On switches, shut down unused access ports and move them into an unused VLAN that goes nowhere, so a cable plugged in later gets no network. Turn off the HTTP server unless you really use the web GUI (and if you do, prefer HTTPS).

output
SW1(config)# vlan 999
SW1(config-vlan)# name UNUSED
SW1(config-vlan)# exit
SW1(config)# interface range gigabitEthernet1/0/20 - 24
SW1(config-if-range)# switchport mode access
SW1(config-if-range)# switchport access vlan 999
SW1(config-if-range)# shutdown
Cisco IOS: unused ports are shut and parked in a dead VLAN.

Common mistakes and fixes

  • SSH "does not work": usually the RSA keys were never generated, or the hostname is still the default. Check with show ip ssh.
  • Locked out after login local: you forgot to create a username first. Always create the user before you change the lines, and keep a console session open while you test.
  • transport input all left on the VTY lines: Telnet is still allowed. Use transport input ssh.
  • Only lines 0 to 4 secured on a switch with 16 lines: lines 5 to 15 still accept Telnet. Configure line vty 0 15.
Tip: Save the work with copy running-config startup-config, then reload a lab device and confirm you can still log in with SSH. A setting that disappears after a reboot is a common surprise.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

Securing device access: secrets and SSH · 1/8

Hardening device access

In this lesson you lock down the ways people log in to a router or switch.

Prefer a video by a teacher? Find free videos on “CCNA configure SSH on Cisco router enable secret login local” on YouTube ↗

In real life: A college network audit

An engineering college in Coimbatore failed an internal audit: 12 switches still accepted Telnet, and the enable password was the college name. Over one weekend the network admin generated RSA keys on every switch, set enable secret, created personal accounts for the three admins, allowed only SSH on line vty 0 15, added exec-timeout 10 0 and login block-for, and moved unused ports to VLAN 999. The next audit passed, and failed logins now show up in the logs.

output
SW-LAB3# show ip ssh
SSH Enabled - version 2.0
Authentication methods:publickey,keyboard-interactive,password
Authentication timeout: 120 secs; Authentication retries: 3
Cisco IOS: confirming SSH version 2 is running.

Practice (0/3 done)

Task 1 · Question

A configuration has both "enable password cisco" and "enable secret Ch@i-2026". Which one does the router use for the enable command?

Task 2 · Code · Python

Write audit(config) that checks a list of Cisco config lines and returns a SORTED list of problem codes: - "enable-password" if any line starts with "enable password" - "no-enable-secret" if no line starts with "enable secret" - "telnet" if any line starts with "transport input" and contains "telnet" or "all" - "http-server" if any line is exactly "ip http server" - "no-ssh-v2" if no line is exactly "ip ssh version 2" Lines may have spaces at the start (strip them first).

Task 3 · Practice

Packet Tracer lab: put one router and one PC on a LAN. Configure the router so the PC can manage it only with SSH version 2, using a local user. Then prove that Telnet is refused.

Quick quiz

Question 1

1.What does service password-encryption really give you?

Question 2

2.Which step must come before crypto key generate rsa will work?

Question 3

3.What does exec-timeout 5 0 do on a line?

Question 4

4.A switch has 16 VTY lines. Only line vty 0 4 has transport input ssh. What is the risk?

Question 5

5.What is the best way to handle unused switch ports?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

What does service password-encryption really give you?

Answer: Weak, reversible type 7 hiding of plain-text passwords

Type 7 only stops casual shoulder-surfing; it is easy to reverse.

Which step must come before crypto key generate rsa will work?

Answer: Setting a hostname other than the default, and ip domain-name

The RSA key is named from the hostname and domain name, so both must be set first.

What does exec-timeout 5 0 do on a line?

Answer: Logs out a session idle for 5 minutes

exec-timeout takes minutes and seconds of idle time before the session is closed.

A switch has 16 VTY lines. Only line vty 0 4 has transport input ssh. What is the risk?

Answer: Lines 5 to 15 may still accept Telnet

Unconfigured lines keep their own settings; secure all of them with line vty 0 15.

What is the best way to handle unused switch ports?

Answer: Shut them down and put them in an unused VLAN

Shut ports cannot be used, and an unused VLAN goes nowhere even if someone turns one on.

Which key type is a good modern default for ssh-keygen?Related

Answer: ed25519

Ed25519 is short, fast and strong. (RSA 3072+ is also fine.)

From SSH: keys, ssh-copy-id and hardening sshd

Why is enable secret preferred over enable password?Related

Answer: It is stored as a hash instead of plain text or weak encryption

enable secret stores a hashed password and takes priority over enable password.

From The Cisco IOS command line

Why is Telnet (port 23) dangerous?Related

Answer: It sends everything, including passwords, in clear text

Telnet has no encryption. SSH replaced it.

From Ports and protocols

Which sshd_config line stops direct root logins over SSH?Related

Answer: PermitRootLogin no

PermitRootLogin no is the standard OpenSSH setting.

From Linux security basics

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 3 more topics in “Network security” before its exam: Access control lists (ACLs), Layer 2 security: port security, DHCP snooping, DAI, Firewalls, IPS and VPNs.
  2. Module 9 exam: Network security · 13 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Wireless networking. 57 topics left in the course before the final exam.

← Previous: Security basics: threats, CIA and AAA