Cisco 默认使用 telnet 作为登陆管理的工具,可以使用 ssh 来管理。
# 查看路由是否具有 ssh 的功能
switch# show ip ssh
%SSH has not been enabled
# 如果已经设置完毕的,应该是这样的:
switch# show ip ssh
SSH Enabled – version 2.0
Authentication timeout: 120 secs; Authentication retries: 5
# 设置 hostname
switch(config)# hostname switch
# 使用 v2 版本
switch(config)#ip ssh version 2
# 设置 domain name
switch(config)# ip domain-name my.domain.com
# 生成 RSA 密钥对,位数建议 > 1024
switch(config)# crypto key generate rsa
# 超时时间,如果在输入密码期间 120s 没动静,路由自动断开
switch(config)# ip ssh time-out 120
# 登陆尝试最大次数,超过此次数,vty 将自动断开
ISCO877(config)# ip ssh authentication-retries 3
# 修改 ssh 的端口,C2960G 不支持此选项
switch(config)# ip ssh port 1111
# vty 只有 ssh 的方式,阻止 telnet 的登陆方式
switch(config)# line vty 0 4
switch(config)# login local
switch(config)# transport input ssh
# 设置登陆名密码
switch(config)# username hello privilege 15 password 7 xxxxxxxxxxxxxxxx
# 保存设置
switch# wr mem
# 查看 ssh 状态
switch#show ssh
%No SSHv1 server connections running.
Connection Version Mode Encryption Hmac State Username
0 2.0 IN aes128-cbc hmac-md5 Session started hello
0 2.0 OUT aes128-cbc hmac-md5 Session started hello
# 关闭 ssh
switch(config)# crypto key zeroize rsa
switch(config)# line vty 0 4
switch(config)# transport input telnet
# 查看连接状态
switch# show tcp brief
使用 show run 看看登陆的状态:
line con 0
password 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
logging synchronous
login
line vty 0 4
password 7 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
login local
transport input ssh
line vty 5 15
login
transport input none
!
有两条 vty,其中一条是只允许 ssh,一条不允许任何协议登陆。
注意:要将其余的线路的 input 设为 none,也就是不允许任何的连接。现在 telnet 的 23 端口对外就关闭了。或者直接 vty 0 15 进行全部线路的设置。
从安全角度来看,除了禁用 telnet 之外,还应该禁用掉 http 而保留 https:
switch(config)# no ip http server
参考:
http://www.itsyourip.com/cisco/how-to-enable-secure-shell-ssh-in-cisco-ios-and-disable-telnet/