Expert · Network security · topic 42 of 57 · 30 min
Securing device access: secrets and SSH
Explanation
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.
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|passwordLocal 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.
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- Set a hostname other than the default Router or Switch.
- Set a domain name with ip domain-name.
- Generate the RSA keys: crypto key generate rsa modulus 2048. SSH version 2 needs at least 768 bits; 2048 is the sensible minimum today.
- Force version 2 with ip ssh version 2. Version 1 has known weaknesses.
- Create a local user with a secret.
- On the VTY lines allow only SSH (transport input ssh) and use login local.
- 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.
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-serverTurn 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).
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)# shutdownCommon 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.
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
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.
SW-LAB3# show ip ssh
SSH Enabled - version 2.0
Authentication methods:publickey,keyboard-interactive,password
Authentication timeout: 120 secs; Authentication retries: 3Practice (0/3 done)
A configuration has both "enable password cisco" and "enable secret Ch@i-2026". Which one does the router use for the enable command?
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).
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
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Access control lists (ACLs)Network security · same module
- Layer 2 security: port security, DHCP snooping, DAINetwork security · same module
- SSH: keys, ssh-copy-id and hardening sshdLinux and Red Hat (RHCSA to RHCE) · SELinux and SSH
- Ports and protocolsCyber Security: from zero to SOC analyst · Networking for security
- Linux security basicsCyber Security: from zero to SOC analyst · Systems and cryptography
- Keeping secrets safeBackend Development · Backend security
Questions people ask about this
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.)
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.
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.
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
- 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.
- Module 9 exam: Network security · 13 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, Wireless networking. 57 topics left in the course before the final exam.