Configure SSH on Routers and Switches (2024)

    Introduction

    This document describes how to configure and debug Secure Shell (SSH) on Cisco routers or switches that run Cisco IOS® Software.

    Prerequisites

    Requirements

    The Cisco IOS image used must be a k9(crypto) image in order to support SSH. For example,c3750e-universalk9-tar.122-35.SE5.tar is a k9 (crypto) image.

    Components Used

    The information in this document is based on Cisco IOS 3600 Software (C3640-IK9S-M), Release 12.2(2)T1.

    SSH was introduced into these Cisco IOS platforms and images:

    • SSH terminal-line access (also known as reverse-Telnet) was introduced in Cisco IOS platforms and images starting in Cisco IOS Software Release 12.2.2.T.
    • SSH Version 2.0 (SSH v2) support was introduced in Cisco IOS platforms and images starting in Cisco IOS Software Release 12.1(19)E.

    The information in this document was created from the devices in a specific lab environment. All of the devices used in this document started with a cleared (default) configuration. If your network is live, ensure that you understand the potential impact of any command.

    Conventions

    Refer to Cisco Technical Tips Conventions for more information.

    SSH v2 Network Diagram

    Configure SSH on Routers and Switches (1)

    Test Authentication

    Authentication Test without SSH

    First test the authentication without SSH to make sure that authentication works with the router Carter before you add SSH. Authentication can be with a local username and password or with an authentication, authorization, and accounting (AAA) server that runs TACACS+ or RADIUS. (Authentication through the line password is not possible with SSH.) This example shows local authentication, which lets you Telnet into the router with username cisco and password cisco.

    Note: Throughout this document, vty is used to indicate Virtual Terminal Type.

    !--- The aaa new-model command causes the local username and password on the router to be used in the absence of other AAA statements.aaa new-modelusername cisco password 0 ciscoline vty 0 4transport input telnet!--- Instead of aaa new-model, you can use the login local command.

    Authentication Test with SSH

    In order to test authentication with SSH, you have to add to the previous statements in order to enable SSH on Carter, and test SSH from the PC and UNIX stations.

    ip domain-name rtp.cisco.com!--- Generate an SSH key to be used with SSH.crypto key generate rsaip ssh time-out 60ip ssh authentication-retries 2

    At this point, the show crypto key mypubkey rsa command must show the generated key. After you add the SSH configuration, test your ability to access the router from the PC and UNIX station.

    Optional Configuration Sets

    Prevent Non-SSH Connections

    If you want to prevent non-SSH connections, add the transport input ssh command under the lines to limit the router to SSH connections only. Straight (non-ssh) Telnets are refused.

    line vty 0 4!--- Prevent non-SSH Telnets.transport input ssh

    Test to ensure that non-SSH users cannot Telnet to the router Carter.

    Set Up an IOS Router or Switch as SSH Client

    There are four steps required to enable SSH support on a Cisco IOS router:

    1. Configure the hostname command.

    2. Configure the DNS domain.

    3. Generate the SSH key.

    4. Enable SSH transport support for the vty.

    If you want to have one device act as an SSH client to the other, you can add SSH to a second device called Reed. This puts these devices in a client-server arrangement, where Carter acts as the server, and Reed acts as the client. The Cisco IOS SSH client configuration on Reed is the same as required for the SSH server configuration on Carter.

    !--- Step 1: Configure the hostname if you have not previously done so.hostname carter!--- The aaa new-model command causes the local username and password on the router to be used in the absence of other AAA statements.aaa new-modelusername cisco password 0 cisco!--- Step 2: Configure the DNS domain of the router.ip domain-name rtp.cisco.com!--- Step 3: Generate an SSH key to be used with SSH.crypto key generate rsaip ssh time-out 60ip ssh authentication-retries 2!--- Step 4: By default the vty transport is Telnet. In this case, Telnet is disabled and only SSH is supported.line vty 0 4transport input ssh!--- Instead of aaa new-model, you can use the login local command.

    Issue this command to SSH from the Cisco IOS SSH client (Reed) to the Cisco IOS SSH server (Carter) to test this:

    ssh -v 2 -c aes256-cbc -m hmac-sha1-160 -l cisco 10.31.1.99

    Setup an IOS Router as an SSH Server that Performs RSA-based User Authentication

    Complete these steps to configure the SSH server to perform RSA-based authentication.

    1. Specify the Host name.

    Router(config)#hostname <host name>

    2. Define a default domain name.

    Router(config)#ip domain-name <Domain Name>

    3. Generate RSA key pairs.

    Router(config)#crypto key generate rsa

    4. Configure SSH-RSA keys for user and server authentication.

    Router(config)#ip ssh pubkey-chain

    5. Configure the SSH username.

    Router(conf-ssh-pubkey)#username <user name>

    6. Specify the RSA public key of the remote peer.

    Router(conf-ssh-pubkey-user)#key-string

    7. Specify the SSH key type and version. (This step is optional.)

    Router(conf-ssh-pubkey-data)#key-hash ssh-rsa <key ID>

    8. Exit the current mode and return to privileged EXEC mode.

    Router(conf-ssh-pubkey-data)#end

    Add SSH Terminal-Line Access

    If you need outbound SSH terminal-line authentication, you can configure and test SSH for outbound reverse Telnets through Carter, which acts as a comm server to Philly.

    ip ssh port 2001 rotary 1line 1 16 no exec rotary 1 transport input ssh exec-timeout 0 0 modem InOut stopbits 1

    If Philly is attached to the Carter Port 2, then you can configure SSH to Philly through Carter from Reed with this command:

    ssh -v 2 -c aes256-cbc -m hmac-shal-160 -p 2002 10.31.1.99

    You can use this command from Solaris:

    ssh -c 3des -p 2002 -x -v 10.13.1.99

    Restrict SSH Access to a Subnet

    You need to limit SSH connectivity to a specific subnetwork where all other SSH attempts from IPs outside the subnetwork are dropped.

    You can use these steps to do the same:

    1. Define an access-list that permits the traffic from that specific subnetwork.
    2. Restrict access to the VTY line interface with an access-class.

    This is an example configuration. In this example, only SSH access to the 10.10.10.0 255.255.255.0 subnet is permitted, any other is denied access.

    Router(config)#access-list 23 permit 10.10.10.0 0.0.0.255Router(config)#line vty 5 15Router(config-line)#transport input sshRouter(config-line)#access-class 23 inRouter(config-line)#exit

    Note: The same procedure to lock down the SSH access is also used for switch platforms.

    Configure the SSH Version 2

    carter(config)#ip ssh version 2

    Variations on Banner Command Output

    The banner command output varies between the Telnet and different versions of SSH connections. This table illustrates how different banner command options work with various types of connections.

    Banner Command Options

    Telnet

    SSH v2

    banner log

    Displays before log in to device.

    Displays before log in to device.

    banner motd

    Displays before log in to device.

    Displays after log in to device.

    banner exec

    Displays after log in to device.

    Displays after log in to device.

    Note: SSH version 1 is no longer recommended.

    Unable to Display the LoginBanner

    SSH version 2 supports the log in banner. When it initiates the SSH session with the Cisco router, the log in banner is displayed if the SSH client sends the username. For example, when the Secure Shell ssh client is used, the log in banner is displayed. When the PuTTY ssh client is used, the log in banner is not displayed. This is because SSH sends the username by default and PuTTY does not send the username by default.

    The SSH client needs the username to initiate the connection to the SSH enabled device. The Connect button is not enabled if you do not enter the host name and username. This screen imageshows that the log in banner is displayed when SSH connects to the router. The banner then prompts for a password.

    Configure SSH on Routers and Switches (2)Banner Prompts for a Password

    The PuTTY client does not require the username to initiate the SSH connection to the router. This screen imageshows that the PuTTY client connects to the router and prompts for the username and password. It does not display the log in banner.

    Configure SSH on Routers and Switches (3)SSH Connection to Router

    This screen shot shows that the log in banner is displayed when PuTTY is configured to send the username to the router.

    Configure SSH on Routers and Switches (4)Send Username to Router

    Debug and Show Commands

    Before you issue the debug commands described here, refer to Important Information on Debug Commands. Certain show commands are supported by the Output Interpreter Tool(registered to customers only), which allows you to view an analysis of show command output.

    • debug ip sshDisplays debug messages for SSH.

    • show sshDisplays the status of SSH server connections.

    carter#show ssh Connection Version Encryption State Username 0 2.0 DES Session started cisco
    • show ip ssh displays the version and configuration data for SSH.

    carter#show ip ssh SSH Enabled - version 2.0 Authentication timeout: 120 secs; Authentication retries: 3

    Sample Debug Output

    Router Debug

    00:23:20: SSH0: starting SSH control process00:23:20: SSH0: sent protocol version id SSH-2.0-Cisco-1.2500:23:20: SSH0: protocol version id is - SSH-2.0-1.2.2600:23:20: SSH0: SSH_SMSG_PUBLIC_KEY msg00:23:21: SSH0: SSH_CMSG_SESSION_KEY msg - length 112, type 0x0300:23:21: SSH: RSA decrypt started00:23:21: SSH: RSA decrypt finished00:23:21: SSH: RSA decrypt started00:23:21: SSH: RSA decrypt finished00:23:21: SSH0: sending encryption confirmation00:23:21: SSH0: keys exchanged and encryption on00:23:21: SSH0: SSH_CMSG_USER message received00:23:21: SSH0: authentication request for userid cisco00:23:21: SSH0: SSH_SMSG_FAILURE message sent00:23:23: SSH0: SSH_CMSG_AUTH_PASSWORD message received00:23:23: SSH0: authentication successful for cisco00:23:23: SSH0: requesting TTY00:23:23: SSH0: setting TTY - requested: length 24, width 80; set: length 24, width 8000:23:23: SSH0: invalid request - 0x2200:23:23: SSH0: SSH_CMSG_EXEC_SHELL message received00:23:23: SSH0: starting shell for vty 

    Server Debug

    Note: This is Solaris machine output.

    rtp-evergreen.rtp.cisco.com#ssh -c 3des -l cisco -v 10.31.1.99rtp-evergreen#/opt/CISssh/bin/ssh -c 3des -l cisco -v 10.13.1.99SSH Version 1.2.26 [sparc-sun-solaris2.5.1], protocol version 1.5.Compiled with RSAREF.rtp-evergreen: Reading configuration data /opt/CISssh/etc/ssh_configrtp-evergreen: ssh_connect: getuid 0 geteuid 0 anon 0rtp-evergreen: Allocated local port 1023.rtp-evergreen: Connecting to 10.13.1.99 port 22.rtp-evergreen: Connection established.rtp-evergreen: Remote protocol version 2.0, remote software version Cisco-1.25rtp-evergreen: Waiting for server public key.rtp-evergreen: Received server public key (768 bits) and host key (512 bits).rtp-evergreen: Host '10.13.1.99' is known and matches the host key.rtp-evergreen: Initializing random; seed file //.ssh/random_seedrtp-evergreen: Encryption type: 3desrtp-evergreen: Sent encrypted session key.rtp-evergreen: Installing crc compensation attack detector.rtp-evergreen: Received encrypted confirmation.rtp-evergreen: Doing password authentication.cisco@10.13.1.99's password: rtp-evergreen: Requesting pty.rtp-evergreen: Failed to get local xauth data.rtp-evergreen: Requesting X11 forwarding with authentication spoofing.Warning: Remote host denied X11 forwarding, perhaps xauth program could not be run on the server side.rtp-evergreen: Requesting shell.rtp-evergreen: Entering interactive session. 

    Incorrect Configurations

    These sections have sample debug output from several incorrect configurations.

    SSH from an SSH Client not Compiled with Data Encryption Standard (DES)

    Bad Password

    Router Debug

    00:26:51: SSH0: starting SSH control process00:26:51: SSH0: sent protocol version id SSH-2.0-Cisco-1.2500:26:52: SSH0: protocol version id is - SSH-2.0-1.2.2600:26:52: SSH0: SSH_SMSG_PUBLIC_KEY msg00:26:52: SSH0: SSH_CMSG_SESSION_KEY msg - length 112, type 0x0300:26:52: SSH: RSA decrypt started00:26:52: SSH: RSA decrypt finished00:26:52: SSH: RSA decrypt started00:26:52: SSH: RSA decrypt finished00:26:52: SSH0: sending encryption confirmation00:26:52: SSH0: keys exchanged and encryption on00:26:52: SSH0: SSH_CMSG_USER message received00:26:52: SSH0: authentication request for userid cisco00:26:52: SSH0: SSH_SMSG_FAILURE message sent00:26:54: SSH0: SSH_CMSG_AUTH_PASSWORD message received00:26:54: SSH0: password authentication failed for cisco00:26:54: SSH0: SSH_SMSG_FAILURE message sent00:26:54: SSH0: authentication failed for cisco (code=7)00:26:54: SSH0: Session disconnected - error 0x07 

    SSH Client Sends Unsupported (Blowfish) Cipher

    Router Debug

    00:39:26: SSH0: starting SSH control process00:39:26: SSH0: sent protocol version id SSH-2.0-Cisco-1.2500:39:26: SSH0: protocol version id is - SSH-2.0-W1.000:39:26: SSH0: SSH_SMSG_PUBLIC_KEY msg00:39:26: SSH0: SSH_CMSG_SESSION_KEY msg - length 112, type 0x0300:39:26: SSH0: Session disconnected - error 0x20 

    Get "%SSH-3-PRIVATEKEY: Unable to Retrieve RSA Private Key for" Error

    A change in the domain name or host name can trigger this error message. Use these workarounds:

    • Zeroize the RSA keys and re-generate the keys.

    crypto key zeroize rsa label key_namecrypto key generate rsa label key_name modulus key_size
    • If the previous workaround does not work, try these steps:

      1. Zeroize all RSA keys.

      2. Reload the device.

      3. Create new labeled keys for SSH.

    Tips

    • If your SSH configuration commands are rejected as illegal commands, you have not successfully generated a RSA key pair for your router. Ensure you have specified a host name and domain. Then use the crypto key generate rsa command to generate a RSA key pairs and enable the SSH server.

    • When you configure RSA key pairs, you can get these error messages:

      1. No hostname specified.

        You must use the hostname global configuration command to configure a host name for the router.

      2. No domain specified.

        You must use the ip domain-name global configuration command to configure a host domain for the router.

    • The number of allowable SSH connections is limited to the maximum number of vty configured for the router. Each SSH connection uses a vtyresource.

    • SSH uses either local security or the security protocol configured through AAA on your router for user authentication. When you configure AAA, you must ensure that the console is not run under AAA. Apply a keyword in the global configuration mode to disable AAA on the console.

    • No SSH server connections running:

    carter#show ssh%No SSHv2 server connections running.

    This output suggests that the SSH server is disabled or not enabled properly. If you have already configured SSH, it is recommended that you reconfigure the SSH server in the device. Complete these steps in order to reconfigure the SSH server on the device.

    1. Delete the RSA key pairs. After the RSA key pairs are deleted, the SSH server is automatically disabled.
    carter(config)#crypto key zeroize rsa

    Note: It is important to generate key pairs with at least 768 as bit size when you enable SSH v2.

    Caution: This command cannot be undone after you save your configuration. Also, after RSA keys are deleted, you cannot use certificates or the CA or participate in certificate exchanges with other IP Security (IPSec) peers unless you regenerate the RSA keys to reconfigure CA interoperability, get the CA certificate, and request your own certificate again.

    2. Reconfigure the hostname and domain name of the device.

    carter(config)#hostname hostnamecarter(config)#ip domain-name domainname

    3.Generate RSA key pairs for your router. This automatically enables SSH.

    carter(config)#crypto key generate rsa

    Note: Refer to crypto key generate rsa - Cisco IOS Security Command Reference, Release 12.3 for more information on the usage of this command.

    Note: You can receive the SSH2 0: Unexpected mesg type received error message due to a packet received that is not understandable by the router. Increase the key length while you generate rsa keys for ssh in order to resolve this issue.

    4. Configure the SSH server.

    5. Toenable and configure a Cisco router/switch for the SSH server, you must configure SSH parameters. If you do not configure SSH parameters, the default values are used.

    ip ssh {[timeout seconds] | [authentication-retries integer]}

    carter(config)# ip ssh

    Related Information

    • SSH Product Support Page
    Configure SSH on Routers and Switches (2024)

    FAQs

    How to configure SSH in a switch? ›

    Configuring the switch for SSH operation
    1. Assign a local login (operator) and enable (manager) password. ...
    2. Generate the switch public and private key pair. ...
    3. Provide the switch public key to clients. ...
    4. Enable SSH on the switch and anticipate SSH client contact behavior.
    5. Configure the switch for SSH authentication.

    What is required for SSH on a router? ›

    For SSH to work, the switch needs an RSA public/private key pair. This is the same with SCP, which relies on SSH for its secure transport. Because SSH also relies on AAA authentication, and SCP relies further on AAA authorization, correct configuration is necessary.

    What command has to be configured on the router to complete the SSH configuration? ›

    To complete the SSH configuration on a router, the "ip domain-name" command needs to be configured. This command sets the domain name for the router, which is a requirement for generating RSA keys used in SSH authentication. SSH (Secure Shell) is a network protocol that allows secure remote access to network devices.

    What are the typical six configuration steps to implement SSH access to a router? ›

    In this example, we will go through the below six steps one by one:
    1. IP Configurations.
    2. Password Encryption.
    3. Router Name Change.
    4. Domain Data and Data Encryption.
    5. Router User Config.
    6. SSH Config.
    7. SSH Verification.

    What are the four steps needed to configure SSH? ›

    There are four steps required to enable SSH support on a Cisco IOS router:
    • Configure the hostname command.
    • Configure the DNS domain.
    • Generate the SSH key.
    • Enable SSH transport support for the vty.
    Aug 9, 2023

    How to SSH into a Cisco router? ›

    SSH from a computer

    Open Putty and type “192.168. 12.1” for the “Host Name” field, Port 22 (SSH) and click “Open” to connect to the router via SSH.

    How do I connect to my router with SSH? ›

    For Linux/Mac User
    1. Launch Terminal. Click the Terminal icon to launch Terminal. Then, input the following command: ssh root@192.168.8.1. If you have ever connected to another router, host key verification failed may displayed as follow: ...
    2. Log In Router. Retry the SSH login command: ssh root@192.168.8.1. Type "yes"

    Do all routers have SSH? ›

    Note: Most routers have SSH enabled by default, but you may need to enable it manually in your router's settings. Please consult your router's documentation for more information. Here are some additional tips for accessing your router via SSH: Make sure that the SSH server on your router is running.

    Do you have to be on the same WiFi network to SSH? ›

    Not necessarily. The internet is based on ports. SSH runs on a port, so long as connectivity to that port is available/open from the network from which you are wishing to connect, then you will be able to connect. Check out port forwarding, firewall rules etc if you want to learn more.

    Which configuring SSH on a router to implement? ›

    Final answer: To complete SSH configuration on a router, one must generate RSA keys, configure the IP domain name, and create a local username and password database. These steps ensure secure communications and authorized access.

    How to configure SSH protocol? ›

    To enable SSH, the following steps are required:
    1. set up a hostname and and a domain name.
    2. configure local username and password.
    3. generate RSA public and private keys.
    4. allow only SSH access.

    How to connect SSH to switch? ›

    SSH Configuration on Cisco Switch!
    1. Step 1: IP Address assignment tot VLAN 1. ...
    2. Step 2: Generate RSA Keys. ...
    3. Step 3: Set a Hostname (if not already set): ...
    4. Step 4: Configure Domain Name (if not already set): ...
    5. Step 5: Create Usernames and Passwords (if not already set): ...
    6. Step 6: Enable the VTY Lines for SSH Access:
    Jan 19, 2024

    What are the mandatory configurations required for SSH to work? ›

    For SSH to work, the switch needs an Rivest, Shamir, and Adleman (RSA) public/private key pair. This is the same with Secure Copy Protocol (SCP), which relies on SSH for its secure transport.

    What are the 5 main steps in configuring a router? ›

    How to Set Up a WiFi Router
    • Step 1: Decide Where to Place The Router. ...
    • Step 2: Connect to The Internet. ...
    • Step 3: Set Up The Configuration for The Wireless Router Gateway. ...
    • Step 4: Establish The Connection Between The Gateway and Router. ...
    • Step 5: Utilize An App or Web Dashboard. ...
    • Step 6: Establish A Username and Password.
    Mar 14, 2024

    How to SSH into a switch from command prompt? ›

    How to start a SSH session from the command line
    1. 1) Type the path to Putty.exe here.
    2. 2) Then type the connection type you wish to use (i.e. -ssh, -telnet, -rlogin, -raw)
    3. 3) Type the username...
    4. 4) Then type '@' followed by the server IP address.
    5. 5) Finally, type the port number to connect to, then press <Enter>

    How to set up SSH on terminal? ›

    Creating SSH Keys (Terminal)
    1. Create an .ssh folder in the home directory. Create a .ssh folder in your user account's home directory if it doesn't already exist: $ mkdir /home/<user name>/.ssh. ...
    2. Use ssh-keygen to generate SSH key. ...
    3. Retrieve the public key file. ...
    4. Use the key in an async session.

    Top Articles
    10 Places To Sell Silver for Cash
    How Much of Your Portfolio Should You Put Into REITs? | The Motley Fool
    Craigslist Myrtle Beach Motorcycles For Sale By Owner
    Washu Parking
    Lorton Transfer Station
    Cooking Chutney | Ask Nigella.com
    Paris 2024: Kellie Harrington has 'no more mountains' as double Olympic champion retires
    What happens if I deposit a bounced check?
    According To The Wall Street Journal Weegy
    Apnetv.con
    Myunlb
    Classroom 6x: A Game Changer In The Educational Landscape
    Divina Rapsing
    Carson Municipal Code
    Bible Gateway passage: Revelation 3 - New Living Translation
    R&S Auto Lockridge Iowa
    Drift Hunters - Play Unblocked Game Online
    Koninklijk Theater Tuschinski
    Anonib Oviedo
    Wat is een hickmann?
    Papa Johns Mear Me
    Superhot Free Online Game Unblocked
    Elijah Streams Videos
    Courtney Roberson Rob Dyrdek
    Package Store Open Near Me Open Now
    Rugged Gentleman Barber Shop Martinsburg Wv
    Poe T4 Aisling
    Pdx Weather Noaa
    Have you seen this child? Caroline Victoria Teague
    R3Vlimited Forum
    Mobile Maher Terminal
    Southern Democrat vs. MAGA Republican: Why NC governor race is a defining contest for 2024
    ShadowCat - Forestry Mulching, Land Clearing, Bush Hog, Brush, Bobcat - farm & garden services - craigslist
    No Hard Feelings Showtimes Near Tilton Square Theatre
    Spinning Gold Showtimes Near Emagine Birch Run
    Los Garroberros Menu
    Toth Boer Goats
    3496 W Little League Dr San Bernardino Ca 92407
    Mixer grinder buying guide: Everything you need to know before choosing between a traditional and bullet mixer grinder
    ACTUALIZACIÓN #8.1.0 DE BATTLEFIELD 2042
    Bustednewspaper.com Rockbridge County Va
    Television Archive News Search Service
    Child care centers take steps to avoid COVID-19 shutdowns; some require masks for kids
    Youravon Com Mi Cuenta
    Joblink Maine
    St Anthony Hospital Crown Point Visiting Hours
    Zom 100 Mbti
    552 Bus Schedule To Atlantic City
    Craigslist Sparta Nj
    Mlb Hitting Streak Record Holder Crossword Clue
    Tyrone Unblocked Games Bitlife
    Unbiased Thrive Cat Food Review In 2024 - Cats.com
    Latest Posts
    Article information

    Author: Moshe Kshlerin

    Last Updated:

    Views: 6209

    Rating: 4.7 / 5 (57 voted)

    Reviews: 88% of readers found this page helpful

    Author information

    Name: Moshe Kshlerin

    Birthday: 1994-01-25

    Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

    Phone: +2424755286529

    Job: District Education Designer

    Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

    Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.