当我们使用telnet登录到设备时,用户名和密码是采用明文的方式传输的,为了保证数据的安全,建议采用SSH的方式登录设备。以下就是Cisco路由器SSH的配置:

  1. 配置hostname和domain-name

  R1(config)#hostname R1

  R1(config)#ip domain-name sky.com   (注:SSH的关键字名就是hostname + . +ip domain-name)

  2. 产生密钥,这里产生的是1024位的密钥,密钥长度范围为360-2048

  R1(config)#crypto key generate rsa


% You already have RSA keys defined named R5.sky.com .

% Do you really want to replace them? [yes/no]: yes

The name for the keys will be: R5.sky.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]


  3. 配置SSH的信息

  配置所使用的SSH版本:

  R1(config)#ip ssh version 2

  配置SSH会话的超时时间:

  R1(config)#ip ssh time-out 120

  配置SSH认证的最大次数:

  R1(config)#ip ssh authentication-retries 3

  启用SSH认证:

  R1(config)#line vty 0 4

  R1(config-line)#transport input ssh

  R1(config-line)#login local     //使用本地认证,登录时必须输入用户名和密码才可以


注:(1)、如果是no login,则不需要密码

    (2)、如果是login,并设置有密码,则所有ssh登录直接以password的明文密码登录,安全性不高

故一定要设置login local方式



  4. 配置本地认证用户

  R1(config)#username test password test

  5. ssh登录测试

   SSH登录:

  R2#ssh -l frame 1.1.1.1

  Password:

  R1>

  通过使用-l指定登录的用户名。

  服务器端查看SSH会话:show  ssh

  R1#sh ssh


Connection      Version Mode Encryption  Hmac State             Username

323             1.99    IN   aes128-cbc      hmac-sha1     Session Started         test

323             1.99    OUT  aes128-cbc      hmac-sha1     Session Started         test




测试问题,还未解决:

删除ssh的key:


R2(config)#crypto key zeroize rsa

% All RSA keys will be removed.

% All router certs issued using these keys will also be removed.

Do you really want to remove these keys? [yes/no]: yes

R2(config)#do wr

*?? 1 4:55:36.844: %SSH-5-DISABLED: SSH 1.5 has been disabled

Building configuration...

[OK]



查看SSH状态:


R2#show ip ssh

SSH Disabled - version 2

%Please create RSA keys (of atleast 768 bits size) to enable SSH v2.

Authentication timeout: 120 secs; Authentication retries: 3


现在在无key状态下,远程ssh还是可以访问的(不管在原有用户还是新增用户下)

只有在vty 0 4中关掉ssh访问才可以禁止SSH访问。