8 steps to configure SSH on a Cisco router or switch

You have a Cisco router or switch. You read my post: How to connect to a Cisco router via the console cable and now you are connected to the device. You realize that it is not very comfortable to connect to your Cisco toy with the console cable every time you want to manage it. You ask yourself if there is any other method you can use to connect to your device, but without the need of a separate cable. And the answer is yes, there is a different method you can use. You can use the SSH protocol for managing your Cisco device.

Gulian Technology
Gulian Technology

In this post, I would like to show you the steps you need to take in order to configure SSH and manage your device via this protocol.

1. Connect your Cisco router to the network and assign an IP address to one of its interfaces

In order to be able to manage your device through SSH, first you need to connect your Cisco router or switch to the network using a UTP cable and assign an IP address to the interface that is connected to your LAN.

Router>
Router>en
Router#conf term
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int vlan 1
Router(config-if)#ip address 172.16.10.1 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#
Configure an IP address to the Cisco router/ switch interface
Configure an IP address to the Cisco router/ switch interface

2. Configure a password for access to Privileged mode

Next, you will need to add a password to protect the access to the Privileged mode. In this mode you can change the configuration of the device. This is why it needs to be protected. You don’t want to find out one day that your device does not have a configuration anymore.

Router(config)#enable secret cisco123

Choose a strong password that you can remember. In my lab, I use cisco123.

3. Add a local user account and specify a password

After you have protected the access to the Privileged mode, you need to define a local account and specify a password for it. You will use this account for accessing the Cisco router or switch through SSH.

Router(config)#username petru secret cisco123
Add a local user account and a password for it
Add a local user account and a password for it

4. Configure the VTY lines

Now, it is the time to configure the VTY lines. You will connect to the router or switch through these lines.

Router(config)#line vty ?
  <0-193>  First Line number

Router(config)#line vty 0 15
Router(config-line)#login local
Router(config-line)#trans
Router(config-line)#transport ?
  input      Define which protocols to use when connecting to the terminal
             server
  output     Define which protocols to use for outgoing connections
  preferred  Specify the preferred protocol to use

Router(config-line)#transport in
Router(config-line)#transport input ?
  all     All protocols
  none    No protocols
  pad     X.3 PAD
  rlogin  Unix rlogin protocol
  ssh     TCP/IP SSH protocol
  telnet  TCP/IP Telnet protocol
  udptn   UDPTN async via UDP protocol

Router(config-line)#transport input ssh
Router(config-line)#                   
Configure the VTY lines
Configure the VTY lines

5. Configure the router hostname

You now need to give your router or switch a name. This way you will be able to identify it.

Router(config)#hostname R1

6. Configure the domain name

After you gave a name to your router or switch, you need to specify the domain name. Based on the router/switch name and this domain, a private and public key will be generated in the next step.

R1(config)#ip domain name gulian.uk
Configure the name of the router and the domain name
Configure the name of the router and the domain name

7. Generate the crypto keys

After you have specified the domain name, you need to generate the keys that will be used with SSH. The below command will generate a RSA private key and a public key.

R1(config)#crypto key generate rsa modulus ?
  <360-2048>  size of the key modulus [360-2048]

R1(config)#crypto key generate rsa modulus 1024
The name for the keys will be: R1.gulian.uk

% The key modulus size is 1024 bits
% Generating 1024 bit RSA keys, keys will be non-exportable...[OK]

R1(config)#
Generate the RSA keys
Generate the RSA keys

8. Specify the SSH version

Finally, you need to specify the SSH version that will be used. It is recommended to use SSH version 2.

R1(config)#ip ssh version ?
  <1-2>  Protocol version

R1(config)#ip ssh version 2
R1(config)#
Specify the SSH version
Specify the SSH version

9. Connect to the router through SSH

It is time to verify the connection to the router or switch via SSH.

As you can see, there are no SSH connections at this point in time.

No SSH connection
No SSH connection

You need to run a similar command in order to connect to your router or switch via SSH. Adjust the command according to your environment.

ssh -l petru 172.16.10.1
Checking the SSH connection
Checking the SSH connection

As you can see the connection was successful. You achieved your end goal. You can manage your device through the network.

I hope you find this post useful. Share it on your social media channels so that other people can read it too.

Processing…
Success! You're on the list.

2 comments

Leave a Reply