路由器 Console、VTY 用户界面密码、SSH 加密远程登录全套配置方案
以下是一套完整的路由器 Console、VTY 用户界面密码及 SSH 加密远程登录的配置方案,适用于 Cisco IOS 设备(其他品牌设备命令可能略有不同):一、Console 接口密码配置
Console 是物理串口登录方式,需设置密码并启用登录验证。
Router(config)# line console 0
Router(config-line)# password your_console_password ! 设置Console密码
Router(config-line)# login ! 启用登录验证
Router(config-line)# exit
可选增强:
[*]设置超时时间(防止未授权长期占用):
Router(config-line)# exec-timeout 5 0 ! 5分钟无操作自动退出
[*]启用加密存储密码(避免明文存储):
Router(config)# service password-encryption
二、VTY 用户界面密码配置
VTY 用于 Telnet/SSH 远程登录,需配置密码及访问控制。
Router(config)# line vty 0 4 ! 配置0-4号VTY线路(共5会话)
Router(config-line)# password your_vty_password ! 设置VTY密码
Router(config-line)# login ! 启用登录验证
Router(config-line)# transport input ssh ! 仅允许SSH(禁用Telnet)
Router(config-line)# exit
安全建议:
[*]限制同时登录会话数:
Router(config)# line vty 0 4
Router(config-line)# absolute-timeout 10 ! 强制10分钟后断开
[*]或使用ACL限制来源IP:
Router(config)# access-list 10 permit 192.168.1.0 0.0.0.255
Router(config)# line vty 0 4
Router(config-line)# access-class 10 in
三、SSH 加密远程登录配置
SSH 替代 Telnet 提供加密通信,需生成密钥并配置用户。
1. 配置主机名和域名(SSH必需)
Router(config)# hostname Router_Name
Router(config)# ip domain-name example.com
2. 生成RSA密钥对
Router(config)# crypto key generate rsa modulus 2048 ! 生成2048位RSA密钥
3. 启用SSH服务
Router(config)# line vty 0 4
Router(config-line)# transport input ssh ! 确保仅允许SSH
Router(config)# ip ssh version 2 ! 强制使用SSHv2(更安全)
Router(config)# ip ssh time-out 60 ! SSH超时时间(秒)
Router(config)# ip ssh authentication-retries 3 ! 认证失败重试次数
4. 创建本地用户(可选,替代密码认证)
Router(config)# username admin privilege 15 secret your_ssh_password
Router(config)# line vty 0 4
Router(config-line)# login local ! 使用本地用户数据库
四、完整配置示例
! 基础配置
hostname SecureRouter
ip domain-name example.com
service password-encryption
! Console配置
line console 0
password encrypted $1$xyz... (加密后的密码,或直接明文测试时用`password yourpass`)
login
exec-timeout 5 0
! VTY配置
line vty 0 4
password your_vty_password
login local ! 或使用`login` + 密码,若用本地用户则需下面用户配置
transport input ssh
access-class 10 in ! 可选ACL限制
! SSH配置
crypto key generate rsa modulus 2048
ip ssh version 2
ip ssh time-out 60
ip ssh authentication-retries 3
! 本地用户(替代密码认证)
username admin privilege 15 secret StrongPassword123!
! ACL示例(可选)
access-list 10 permit 192.168.1.0 0.0.0.255
五、验证配置
[*]检查SSH服务状态:
show ip ssh ! 应显示SSH已启用,版本为2
[*]测试登录:
[*]通过SSH客户端连接:ssh admin@router_ip
[*]检查VTY会话:show users
六、安全加固建议
[*]禁用Telnet:确保transport input ssh,无telnet。
[*]强密码策略:密码长度≥12位,混合大小写、数字、符号。
[*]定期更换密钥:crypto key zeroize rsa后重新生成。
[*]日志监控:启用logging记录登录事件。
[*]禁用未用服务:如no service tcp-small-servers。
通过以上配置,路由器将具备安全的物理控制台访问、受限的远程VTY访问及加密的SSH登录能力。
页:
[1]