Router(config)#hostname R1841 // 设置hostname R1841(config)#ip domain-name router.com // 设置domain-name R1841(config)#username cisco privilege 15 password cisco // 创建本地用户和密码 R1841(config)#service password-encryption // 把密码加密 R1841(config)#enable secret cisco // 设置特权密码,不然后面远程无法进入特权模式 R1841(config)#crypto key generate rsa // 生成ssh密钥 The name for the keys will be: R1841.router.com Choose the size of the key modulus in the range of 360 to 2048for your General Purpose Keys. Choosing a key modulus greater than 512 may take a few minutes.
How many bits in the modulus [512]: 1024// 这里需要产生1024位的密钥因为ssh版本2需要位数较多 % Generating 1024 bit RSA keys, keys will be non-exportable...[OK]
R1841(config)#ip ssh version 2 // 设置使用的ssh版本 *3? 10:7:2.224: %SSH-5-ENABLED: SSH 1.99 has been enabled R1841(config)#ip ssh time-out 120 // ssh会话超时时间 R1841(config)#ip ssh authentication-retries 3 // ssh验证的最大次数 R1841(config)#line vty 0 4 R1841(config-line)#transport input all // 启用所有的认证(telnet和ssh) R1841(config-line)#login local // 启用本地验证 R1841(config-line)#exit R1841(config)#interface f0/0 R1841(config-if)#no shutdown // 启动路由器端口 %LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up