How to configure network devices for remote access using SSH

How to configure network devices for remote access using SSH

Before SSH existed, network engineers commonly used Telnet to remotely manage routers and switches. Telnet works, but it sends everything — including usernames and passwords — as plain, readable text across the network. Anyone capturing traffic on the path could read your login credentials instantly.

SSH (Secure Shell) solves this problem by encrypting the entire session. This article explains, from first principles, how SSH works, why it replaced Telnet, and exactly how to configure, verify, and troubleshoot SSH access on Cisco devices and Linux servers.

Why Remote Access Matters

Network devices are often physically located in server rooms, wiring closets, or remote branch offices that engineers cannot walk to every time a change is needed. Remote access protocols let an administrator connect to a device’s Command Line Interface (CLI) over the network itself, as if they were sitting at the console — but this convenience is dangerous if the connection isn’t secured.

Telnet vs SSH — Why the Difference Matters

FeatureTelnetSSH
PortTCP 23TCP 22
EncryptionNone (cleartext)Full session encryption
AuthenticationPlaintext username/passwordPassword or public-key, encrypted
Data Integrity CheckingNoYes (via MAC — Message Authentication Code)
Modern UsageDeprecated for productionIndustry standard
sequenceDiagram
    participant Attacker
    participant Admin
    participant Router
    Note over Admin,Router: Telnet Session (cleartext)
    Admin->>Router: username: admin, password: Cisco123 (visible!)
    Attacker-->>Admin: Packet capture reveals credentials
    Note over Admin,Router: SSH Session (encrypted)
    Admin->>Router: Encrypted key exchange + login
    Attacker-->>Admin: Packet capture shows only ciphertext

How SSH Works, From First Principles

SSH relies on asymmetric (public-key) cryptography to set up a secure, encrypted channel, and then typically uses a password or key for authentication within that channel. The process happens in stages:

  1. TCP connection is established on port 22.
  2. Key exchange — client and server agree on a shared secret using algorithms like Diffie-Hellman, without ever sending the secret itself over the network.
  3. Server authentication — the client verifies the server’s identity using the server’s public key (this is why you see “the authenticity of host X can’t be established” the first time you connect).
  4. Session encryption begins — from this point, all traffic, including login credentials, is encrypted.
  5. User authentication — via password or SSH key pair.
  6. Encrypted session — the CLI session now runs entirely inside this encrypted tunnel.

SSH Versions: SSH1 vs SSH2

SSH version 1 had known cryptographic weaknesses and is now considered insecure. SSH version 2 (SSHv2) is the current standard and should always be enforced explicitly on Cisco devices.

Prerequisites for Enabling SSH on a Cisco Device

Before SSH will work, the device needs:

  1. A hostname other than the default (SSH requires a unique hostname for key generation).
  2. A domain name configured.
  3. RSA (or ECDSA) key pair generated locally.
  4. A local username/password database or AAA authentication configured.
  5. VTY lines configured to accept SSH (not Telnet).

Step-by-Step: Configuring SSH on a Cisco Router/Switch

Step 1: Set Hostname and Domain Name

Router(config)# hostname R1
R1(config)# ip domain-name mycompany.local

Step 2: Generate the RSA Key Pair

R1(config)# crypto key generate rsa
% You already have RSA keys defined...
How many bits in the modulus [512]: 2048

Use at least 2048 bits for a modern, secure key.

Step 3: Create a Local User Account

R1(config)# username admin privilege 15 secret StrongP@ssw0rd!

Using secret (not password) ensures the credential is stored as an encrypted hash, not reversible plaintext.

Step 4: Enable SSH Version 2 Only

R1(config)# ip ssh version 2

Step 5: Configure VTY Lines for SSH-Only Access

R1(config)# line vty 0 4
R1(config-line)# transport input ssh
R1(config-line)# login local
R1(config-line)# exec-timeout 10 0

transport input ssh explicitly disables Telnet on these lines — a critical security step many engineers forget.

Step 6: (Optional but Recommended) Harden SSH Further

R1(config)# ip ssh time-out 60
R1(config)# ip ssh authentication-retries 3

Verifying SSH Configuration

R1# show ip ssh
R1# show ssh
R1# show crypto key mypubkey rsa
R1# show running-config | section line vty

Sample output of show ip ssh:

SSH Enabled - version 2.0
Authentication timeout: 60 secs; Authentication retries: 3

Sample output of show ssh (active sessions):

Connection  Version Mode Encryption  Hmac        State        Username
0           2.0     IN   aes256-cbc  hmac-sha1   Session started admin
0           2.0     OUT  aes256-cbc  hmac-sha1   Session started admin

Testing the Connection

From another Cisco device:

R2# ssh -l admin 192.168.1.1

From a Linux/Mac terminal:

ssh admin@192.168.1.1

From Windows, using PuTTY or the built-in OpenSSH client:

ssh admin@192.168.1.1

SSH Key-Based Authentication (More Secure Than Passwords)

Instead of a password, you can configure public-key authentication, removing the risk of password guessing entirely.

On the client (Linux example):

ssh-keygen -t rsa -b 4096 -f ~/.ssh/router_key
cat ~/.ssh/router_key.pub

On the Cisco device (IOS supports this on newer platforms via ip ssh pubkey-chain):

R1(config)# ip ssh pubkey-chain
R1(conf-ssh-pubkey)# username admin
R1(conf-ssh-pubkey-user)# key-string
R1(conf-ssh-pubkey-data)# AAAAB3NzaC1yc2EAAAADAQABAAAB...
R1(conf-ssh-pubkey-data)# exit

Then connect with:

ssh -i ~/.ssh/router_key admin@192.168.1.1

Configuring SSH Server on a Linux Machine

Most Linux distributions ship with OpenSSH.

sudo apt update
sudo apt install openssh-server -y
sudo systemctl enable ssh
sudo systemctl start ssh
sudo systemctl status ssh

Hardening /etc/ssh/sshd_config:

Port 2222
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
AllowUsers admin
sudo systemctl restart ssh

Automating SSH Connections with Python (Netmiko)

Network engineers commonly use the netmiko Python library to automate SSH logins to dozens or hundreds of devices at once — for backups, audits, or bulk configuration changes.

from netmiko import ConnectHandler

device = {
    "device_type": "cisco_ios",
    "host": "192.168.1.1",
    "username": "admin",
    "password": "StrongP@ssw0rd!",
    "secret": "StrongP@ssw0rd!",
}

connection = ConnectHandler(**device)
connection.enable()
output = connection.send_command("show ip ssh")
print(output)
connection.disconnect()

This kind of script is the foundation of network automation pipelines — instead of manually SSHing into each device, engineers script the same task across an entire fleet.

Best Practices for SSH on Network Devices

  • Always disable Telnet (transport input ssh) once SSH is confirmed working.
  • Use SSH version 2 only — never allow version 1.
  • Use RSA keys of at least 2048 bits.
  • Set an exec-timeout on VTY lines to auto-disconnect idle sessions.
  • Limit SSH access with an ACL applied via access-class on the VTY lines.
  • Use AAA (TACACS+/RADIUS) for centralized authentication in larger environments instead of local usernames.
  • Rotate/change default and shared passwords regularly.
  • Log all SSH login attempts to a syslog server for auditing.
  • Prefer key-based authentication over passwords where the platform supports it.

Troubleshooting SSH Access

SymptomLikely CauseFix
“Connection refused”SSH not enabled, wrong port, or ACL blocking port 22Verify show ip ssh, check ACLs
“% SSH keys have not been generated”RSA key pair missingRun crypto key generate rsa
Login fails despite correct passwordlogin local missing, or user account not createdVerify username command and login local on VTY
Falls back to Telnet unexpectedlytransport input still allows telnetSet transport input ssh explicitly
Session hangs / very slowDNS lookup failure delays loginDisable DNS lookup: no ip domain-lookup
“Too many authentication failures”Multiple SSH keys offered before passwordUse ssh -o IdentitiesOnly=yes or increase ip ssh authentication-retries

Real-World Example: Securing a Branch Office Router

A company has 20 branch routers, previously managed via Telnet. The security team mandates SSH-only access with a maximum of 3 login attempts and a 5-minute idle timeout, restricted to the IT team’s subnet (10.0.99.0/24).

hostname BR-R1
ip domain-name branch.company.com
crypto key generate rsa modulus 2048
ip ssh version 2
ip ssh authentication-retries 3
username netadmin privilege 15 secret VeryStr0ngPass!

access-list 50 permit 10.0.99.0 0.0.0.255
access-list 50 deny any log

line vty 0 4
 transport input ssh
 login local
 access-class 50 in
 exec-timeout 5 0

This configuration, replicated (ideally via automation) across all 20 routers, closes the Telnet security gap company-wide.

Conclusion

SSH is the modern standard for securely managing network devices remotely. It replaces the plaintext vulnerabilities of Telnet with strong encryption, supports both password and public-key authentication, and integrates cleanly with automation tools like Netmiko for large-scale operations. Mastering SSH configuration, verification, and troubleshooting is essential for any network professional operating in a real production environment.

References

  1. Cisco Configuring Secure Shell (SSH) — https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/sec_usr_ssh/configuration/xe-16/sec-usr-ssh-xe-16-book.html
  2. OpenSSH Documentation — https://www.openssh.com/manual.html
  3. RFC 4251 – The Secure Shell (SSH) Protocol Architecture — https://datatracker.ietf.org/doc/html/rfc4251
  4. Netmiko GitHub Repository — https://github.com/ktbyers/netmiko
  5. Cisco IOS Security Command Reference — https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/security/command/reference/sec-cr-book.html
  6. NIST Guidelines for SSH Key Management — https://csrc.nist.gov/publications/detail/sp/800-77/rev-1/final
Total
1
Shares

Leave a Reply

Previous Post
Configure and verify DHCP client and relay

Configure and Verify DHCP Client and Relay

Next Post
Describe the capabilities and function of TFTP/FTP in the network

Describe the Capabilities and Function of TFTP/FTP in the Network

Related Posts