Перейти к содержимому

Ip ssh version 2 что это

  • автор:

Configure SSH on Routers and Switches

The documentation set for this product strives to use bias-free language. For the purposes of this documentation set, bias-free is defined as language that does not imply discrimination based on age, disability, gender, racial identity, ethnic identity, sexual orientation, socioeconomic status, and intersectionality. Exceptions may be present in the documentation due to language that is hardcoded in the user interfaces of the product software, language used based on RFP documentation, or language that is used by a referenced third-party product. Learn more about how Cisco is using Inclusive Language.

Contents

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 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.

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 start in Cisco IOS Software Release 12.2.2.T.

SSH Version 2.0 (SSH v2) support was introduced in Cisco IOS platforms and images start in Cisco IOS Software Release 12.1(19)E.

Conventions

SSH v2 Network Diagram

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».

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.

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.

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.

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

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.

Specify the Host name.

2. Define a default domain name.

3. Generate RSA key pairs.

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

5. Configure the SSH username.

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

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

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

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.

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

  • You can use this command from Solaris:

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:

Define an access-list that permits the traffic from that specific subnetwork.

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.

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

Configure the 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

Displays before log into device.

Displays before log into device.

Displays before log into device.

Displays after log into device.

Displays after log into device.

Displays after log into device.

Note: SSH version 1 is no longer recommended.

Unable to Display the Login Banner

SSH version 2 supports the login banner. When it initiates the SSH session with the Cisco router, the login banner is displayed if the SSH client sends the username. For example, when the Secure Shell ssh client is used, the login banner is displayed. When the PuTTY ssh client is used, the login 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 screenshot shows that the login banner is displayed when SSH connects to the router. The banner then prompts for a password.

Banner Prompts for a Password

The PuTTY client does not require the username to initiate the SSH connection to the router. This screenshot shows that the PuTTY client connects to the router and prompts for the username and password. It does not display the login banner.

SSH Connection to Router

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

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 ssh Displays debug messages for SSH.

show ssh Displays the status of SSH server connections.

show ip ssh Displays the version and configuration data for SSH.

Sample Debug Output

Router Debug

Server Debug

Note: This is Solaris machine output.

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

SSH Client Sends Unsupported (Blowfish) Cipher

Router Debug

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.

If the previous workaround does not work, try these steps:

Zeroize all RSA keys.

Reload the device.

Create new labeled keys for SSH.

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:

No hostname specified

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

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 vty resource.

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:

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.

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.

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

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. To enable 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

SSH Version 2 Configuration on Cisco Router

SSH Version 2 Configuration

The SSH protocol (Secure Shell) is a method for secure remote login from one device to other. SSH provides a secure channel over an unsecured network in a client-server architecture, connecting an SSH client application with an SSH server. As discussed in another blog , SSH has two versions –

SSH VERSION 1

SSH v1 (Secure Shell) provides an encrypted channel to users for logging into remote device. It provides strong host-to-host and user authentication. It also provides secure encrypted communications over the Internet.

SSH Version2

On the contrary, SSH2 is a much more secured, an efficient version of SSH that includes SFTP, which is functionally similar to FTP with addition of SSH2 encryption.

SSH works on port 22. It is a secure alternative to the non-protected login protocols (such as Telnet ) and insecure file transfer methods (such as FTP).

Configuring SSH on Cisco routers and switches

cisco

Older IOS images on Cisco devices used telnet as default login method for the vty lines. Nowadays using telnet is not safe because all traffic including usernames and passwords is transmitted in clear text. This way anybody using a protocol analyzer can gain access to the data. Lately telnet access method has been replaced by SSH which offers increased security by encrypting all traffic between source and destination. SSH protocol comes in two versions SSH1 and SSH2. Communication between the client and server is encrypted in both versions. You should implement SSH version 2 when possible because it uses a more enhanced security encryption algorithm. SSH1 became available in Cisco’s IOS, starting with release 12.1(1)T. In order to use SSH2 you need a IOS version 12.3(4)T or newer.

Prerequisites for configuring SSH

In order to enable SSH on a Cisco router or switch you must verify first if the IOS image on the device supports it. The easiest way to find out if your IOS images supports SSH is to run the show version command in user exec mode and look at the image name. Find the line that starts with System image file is:. If the image contains k9 in its name then you can use cryptographic features, otherwise you need to upgrade the IOS version.

After you have confirmed your IOS image supports SSH, verify if it’s not already enabled. From user or privileged exec mode run the following command:

Router#show ip ssh
SSH Disabled – version 1.99
%Please create RSA keys (of at least 768 bits size) to enable SSH v2.

The output of this command shows that SSH is supported but it’s disabled. The next step is to configure the hostname and the domain name. Enter global configuration mode and run the following sequence of commands, replacing the hostname (R1) and the domain name (cioby.ro) with your own names:

Router1#configure terminal
Router(config)# hostname R1
R1(config)# ip domain-name cioby.ro

After the hostname and domain name have been configured you must generate an RSA key pair for your device. Type the following command in global configuration mode:

R1(config)# crypto key generate rsa

After typing this command you will be asked the length of the key. The key length accepted by the router or switch is between 360 and 2048 bits. Larger keys provide greater security, but affect performance. Using keys shorter than 1024 bits is not recommended. Once the keys are created, they are stored in NVRAM and are inaccessible. The output of this command looks similar to the below:

The name for the keys will be: R1.cioby.ro
Choose the size of the key modulus in the range of 360 to 4096 for your
General Purpose Keys. Choosing a key modulus greater than 512 may take
a few minutes.
How many bits in the modulus [512]: 2048
% Generating 2048 bit RSA keys, keys will be non-exportable…[OK]
R1(config)#
*Sep 7 11:22:03.131: %SSH-5-ENABLED: SSH 1.99 has been enabled

The above command enables the SSH server for local and remote authentication on the router. The last line shows us that SSH version 2 was enabled. To delete the RSA key-pair, use the following global configuration command:

R1(config)# crypto key zeroize rsa

After the RSA key-pair, is deleted the SSH server is automatically disabled.

In order to access a router or switch by SSH you need to configure authentication for local or remote access. This implies either using a local user database to authenticate remote users or an AAA server such as a RADIUS or TACACS+ server. To enable authentication using a local user database we must type the following sequence of commands:

R1(config)# username cisco privilege 15 secret 0 C!sc0P@ss
R1(config)# line vty 0 4
R1(config-line)# login local

Here we added a username named cisco with full privileges. The secret keyword followed by 0 tells us that the following textplain password will be encrypted in the running configuration. Here access is allowed only to the first 5 virtual terminals.

Configuring SSH parameters

After the key-pair was generated SSH can be used with the default settings. There are some configuration parameters which can be adjusted to our needs. By default, the router will run in compatibility mode, meaning it will enable both versions of SSH. Since SSH Version 2 has significant security advantages over SSH Version 1 it’s highly suggested that you disable SSH Version 1 whenever possible. To enable only SSH Version 2, use the following command:

R1(config)# ip ssh version 2

The ip ssh global configuration command is used to configure Secure Shell (SSH) control parameters on your router. For example to specify the time interval that the router waits for the SSH client to respond we can use the timeout option like below.

R1(config)# ip ssh timeout 60

The timeout is specified in seconds and its default value is 120.

By default SSH allows us 3 attempts to enter a valid username and password. If that number is reached the vty interface is reset. To modify this value change the authentication-retries option like below:

R1(config)# ip ssh authentication-retries 5

Some newer IOS versions allows us to change the default listening port for SSH (port 22). This can be done by using the port option of the ip ssh global configuration command:

R1(config)# ip ssh port 2022

Verifying SSH

To view the default SSH options or the SSH state we can use the ip show ssh command:

R1# show ip ssh
SSH Enabled – version 1.99
Authentication timeout: 120 secs; Authentication retries: 3

From the previous output we can see that SSH is enabled with the default options. This command must be ran from privileged EXEC mode.

In order to display the status of Secure Shell (SSH) server connections, we can use the show ssh privileged EXEC command.

R1# show ssh
Connection Version Encryption State Username
0 1.99 3DES Session started cisco

From the output of this command we can see that there is one active SSH session on line vty 0, using SSH version 2 and the logged on user is named cisco.

Using the builtin SSH client

Cisco IOS version 12.1(3)T and above began to support SSH client functionality. This feature is available only when the SSH server is enabled. The SSH client allows us to establish a secure, encrypted connection to another Cisco router or to any other device running the SSH server. For example if we want to connect to our router from a Linux server we would run a command similar to the below:

Server# ssh -l cisco R1.cioby.ro
cisco@R1’s password:xxxxxxxxxx
R1>

When starting a new SSH session the client allows us to specify several options:

  • -l – specifies the username used to log onto the SSH server. If no user is specified the current user is assumed.
  • -p – specifies the desired port number for the remote host. The default port number is 22.
  • -c – specifies the used algorithm, (DES or 3DES), for encrypting data.

Optionally after the remote IP or domain name we can specify a command to be ran after loggging on.

ssh -l cisco R1 “show ip route”

Troubleshooting SSH

Some error messages might appear when configuring the RSA key pair:

  • No hostname specified – you must configure a host name for the router using the hostname global configuration command.
  • No domain specified – you must configure a host domain for the router using the ip domain-name global configuration command.

To perform advanced troubleshooting on SSH you can use the debug ip ssh command.

Disabling telnet access

For security it’s recommended to disable telnet access on the vty lines and allow only SSH. This can be done by running the following sequence of commands:

R1(config)# line vty 0 4
R1(config-line)# transport input ssh

After all these changes have been applied you must save them in the startup configuration by running one of the following two commands:

R1# copy running-config startup-config

R1# write memory

The startup config file is stored on NVRAM so these settings will be available even if the device is rebooted.

Cisco SSH

Подключение с соседнего маршрутизатора (к порту 2009):

Пользователь подключился к vty 4:

Ограничение числа сессий ssh ip ssh maxstartups Пример: ограничим 2 сессиями

Ограничение времени timeoutá аутентификации (по-умолчанию 120 секунд)ip ssh time-out

SSH сервер прерывает соединение, если на стадии аутентификации не передаются никакие данные в течение этого времени ожидания.

Указание интерфейса для всех сессий ssh

Включение журналирования событий SSH ip ssh logging events

Указание версии использования протокола ip ssh version версия Пример:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *