≡ Menu

How to Enable SSH on Cisco Switch, Router and ASA

Q: I have a Cisco switch in my network, which I can access by hooking up a console cable directly to the device. I like to access the switch remotely using SSH. How can I enable ssh on my Cisco 3750 Catalyst Switch?

A: By default, when you configure a Cisco device, you have to use the console cable and connect directly to the system to access it. Follow the steps mentioned below, which will enable SSH access to your Cisco devices. Once you enable SSH, you can access it remotely using PuTTY or any other SSH client.

1. Setup Management IP

First, make sure you have performed basic network configurations on your switch. For example, assign default gateway, assign management ip-address, etc. If this is already done, skip to the next step.

In the following example, the management ip address is set as 192.168.101.2 in the 101 VLAN. The default gateway points to the firewall, which is 192.168.101.1

# ip default-gateway 192.168.101.1

# interface vlan 101
(config-if)# ip address 192.168.101.2 255.255.255.0

2. Set hostname and domain-name

Next, make sure the switch has a hostname and domain-name set properly.

# config t
(config)# hostname myswitch
(config)# ip domain-name thegeekstuff.com

3. Generate the RSA Keys

The switch or router should have RSA keys that it will use during the SSH process. So, generate these using crypto command as shown below.

myswitch(config)# crypto key generate rsa
 The name for the keys will be: myswitch.thegeekstuff.com
 Choose the size of the key modulus in the range of 360 to 2048 for your
   General Purpose Keys. Choosing a key modulus greater than 512 may take
   a few minutes.

How many bits in the modulus [512]: 1024
 % Generating 1024 bit RSA keys, keys will be non-exportable...[OK]

Also, if you are running on an older Cisco IOS image, it is highly recommended that you upgrade to latest Cisco IOS.

4. Setup the Line VTY configurations

Setup the following line vty configuration parameters, where input transport is set to SSH. Set the login to local, and password to 7.

# line vty 0 4
(config-line)# transport input ssh
(config-line)# login local
(config-line)# password 7
(config-line)# exit

If you have not set the console line yet, set it to the following values.

# line console 0
(config-line)# logging synchronous
(config-line)# login local

5. Create the username password

If you don’t have an username created already, do it as shown below.

myswitch# config t
Enter configuration commands, one per line.  End with CNTL/Z.
myswitch(config)# username ramesh password mypassword

Note: If you don’t have the enable password setup properly, do it now.

myswitch# enable secret myenablepassword

Make sure the password-encryption service is turned-on, which will encrypt the password, and when you do “sh run”, you’ll seee only the encrypted password and not clear-text password.

myswitch# service password-encryption

5. Verify SSH access

From the switch, if you do ‘sh ip ssh’, it will confirm that the SSH is enabled on this cisco device.

myswitch# sh ip ssh
SSH Enabled - version 1.99
Authentication timeout: 120 secs; Authentication retries: 3

After the above configurations, login from a remote machine to verify that you can ssh to this cisco switch.

In this example, 192.168.101.2 is the management ip-address of the switch.

remote-machine# ssh 192.168.101.2
login as: ramesh
Using keyboard-interactive authentication.
Password:

myswitch>en
Password:
myswitch#
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • John August 22, 2013, 12:29 pm

    I’m using telnet to connect to my Cisco switch. Is telnet enabled by default? If yes, how should I disable that?

  • Kane August 23, 2013, 5:54 am

    To disable telnet:

    myswitch#configure terminal
    myswitch(config)#line VTY 0 15
    myswitch(config-line)#Transport preferred ssh

    This will allow only SSH connections to the device. Be sure to complete the above listed steps as well.

  • Selvam August 23, 2013, 7:12 am

    Very nice explanation! Thanks.

  • Biswajit August 23, 2013, 8:34 am

    Great post. Thanks !!!

  • Jalal Hajigholamali August 24, 2013, 9:48 pm

    Hi,
    Very nice and useful material…

  • Anon August 26, 2013, 1:14 am

    This is definitely not the way you do it on a Cisco ASA btw 😉

  • Pedram August 30, 2013, 3:49 am

    Anon, this is just my words coming out of your mouth 😉

  • Kane August 30, 2013, 11:38 am

    Hey Anon & Pedram,

    Why don’t you 2 enlighten us then.

    Thanks,.

  • ali January 16, 2014, 5:22 am

    very user full post, thanks for sharing it. BDY if you can also describe how to use telnet and ssh on line vty same it i will be gr8

  • prat March 28, 2014, 6:28 am

    very good explanation thanks!! a lot

  • Lossless October 16, 2014, 10:17 am

    Example ASA

    username sshuser password sshpassword
    crypto key generate rsa modulus 2048
    ssh 10.1.1.1 255.255.255.255 inside
    ssh timeout 5
    ssh version 2
    aaa authentication ssh console LOCAL

  • John November 2, 2014, 12:05 am

    Hi is the RSA key ” myswitch.thegeekstuff.com” automatically chosen by the router when you key in the crypto command?

  • Mansoor Ali March 13, 2015, 11:17 am

    @JOHN:- you can choose by yourself…
    hi my question is that after enabling the SSH on a cisco device, how to Disable SSH?

  • Mansoor Ali March 13, 2015, 11:27 am

    friends i have found way to disable SSH from cisco device generally we use no before any command to remove that perticular command,
    Do notice if you use the command “no crypto key generate rsa” it will not work
    rather the device will suggest you to use the
    ‘crypto key zeroize rsa’ command, amazing…..!!!!!!!!!!

  • Harry February 15, 2016, 11:38 am

    How do you see what modulus the switch is configured for after it has been configured?

  • Mina May 31, 2016, 11:43 pm

    Please I am trying to follow this steps to enable ssh on my home lab I am conneceting via console to a switch 2950 and router is connected to switch via rj45 cable.
    I have enable ssh on my switch while connecting to my serial port .
    the problem is that when I set password 7
    it says incomplete command ! what am I doing wrong ?

    thanks for your help.

    # line vty 0 4
    (config-line)# transport input ssh
    (config-line)# login local
    (config-line)# password 7
    (config-line)# exit

  • leenus June 18, 2016, 6:26 am

    nice explanation

  • Joe March 31, 2017, 7:46 am

    I have some remote switches up to an hour away that I currently access through telnet. Can I login with Telnet, enable SSH, then switch the the SSH connection to login and disable telnet? So as to avoid visiting each switch physically?

  • Anonymous April 18, 2017, 4:46 am

    password 7 ?

    Yeah, that’s wrong. You either need to set a password (and why do you need one if you are using local authentication with a user/pass?) or not set one (ie have no password line at all).

  • Chand May 14, 2017, 4:43 am

    My question is, the following commands are generated by default or do we need to configure?

    crypto pki trustpoint TP-self-signed-1134361687
    enrollment selfsigned
    subject-name cn=IOS-Self-Signed-Certificate-1134361687
    revocation-check none
    rsakeypair TP-self-signed-113436168

    and how does this crypto key generated ?
    crypto pki certificate chain TP-self-signed-1134361687
    certificate self-signed 01
    3082024F 308201B8 A0030201 02020101 300D0609 2A864886 F70D0101 04050030
    31312F30 2D060355 04031326 494F532D 53656C66 2D536967 6E65642D 43657274
    69666963 6174652D 31313334 33363136 3837301E 170D3037 31313236 31353138
    35325A17 0D323030 31303130 30303030 305A3031 312F302D 06035504 03132649
    4F532D53 656C662D 5369676E 65642D43 65727469 66696361 74652D31 31333433
    36313638 3730819F 300D0609 2A864886 F70D0101 01050003 818D0030 81890281
    8100A736 BE0686B5 08396D41 86CAF6C3 90D0C3AE 19DE30B1 44231816 E723ADE1
    16B6A5F3 B1EC84A7 523735A2 72406164 2B9C2C33 DEA3E4C8 D273AF3D 19482724
    3C13ABDC 4575A1D1 2F4C27D4 0306EABB 4A1826DB 326E746F 54970E3E 99F6D1AC
    CE6362BC B5673A4F E18B7E59 4E591E05 E2B5772E 6CA8AF8A 475D1B07 760E7065
    E5390203 010001A3 77307530 0F060355 1D130101 FF040530 030101FF 30220603
    551D1104 1B301982 17796F75 726E616D 652E796F 7572646F 6D61696E 2E636F6D
    301F0603 551D2304 18301680 14D9ADAA EB5BA80F 051EB9AB DD559144 294CD5D6
    C1301D06 03551D0E 04160414 D9ADAAEB 5BA80F05 1EB9ABDD 55914429 4CD5D6C1
    300D0609 2A864886 F70D0101 04050003 8181001E FBD340BE 2DAC68CF B073A8A3
    6930C5FD 2AFAF675 FE803E30 9FA6D61D A16A557D 51331506 BEE81F2E A3F41DCD
    A370BB59 A3B7A90C 690DA7C9 48547FF4 2005CAF4 677A59CC 774FE833 31EC0CC3
    A8D6C07B 161C9C4E B3D53589 6199C2E6 6093B60E F3D1692E F356B2EE 375676EE
    10B846A0 ACC13B68 461C2FE2 F575E922 36AEF8
    quit
    file verify auto

  • Anonymous March 18, 2019, 3:15 pm

    Thanks for that but i want to ask this if i have reached where there is cryto key what is the next