H3C S5130 交换机 SSH 远程开局配置指南
一、概述
本文档适用于 H3C S5130 系列交换机通过 SSH 远程完成开局配置。需先通过 Console 口完成基础网络配置(IP 地址、路由),再使用 SSH 远程管理。
二、准备工作
| 项目 | 说明 |
|---|---|
| Console 配置线 | RJ-45 转 DB9 或 USB 转串口 |
| 终端软件 | PuTTY、Xshell、SecureCRT、macOS 终端等 |
| 串口参数 | 波特率 9600 / 数据位 8 / 停止位 1 / 无校验 / 无流控 |
| 电脑 IP | 与交换机管理 IP 同网段 |
三、第一阶段:Console 口基础配置(让 SSH 可达)
3.1 Console 登录
Console 线连接电脑与交换机 Console 口
打开终端软件,设置串口参数:9600-8-1-无-无
交换机上电,按 Enter 进入命令行
3.2 基础网络配置
<H3C> system-view [H3C] sysname Switch-01 # 配置管理 IP(VLAN 1) [H3C] interface Vlan-interface 1 [H3C-Vlan-interface1] ip address 192.168.1.100 255.255.255.0 [H3C-Vlan-interface1] quit # 配置默认路由(根据实际网关调整) [H3C] ip route-static 0.0.0.0 0.0.0.0 192.168.1.1
3.3 开启 SSH 服务
[H3C] ssh server enable # 生成 RSA 密钥(如未自动生成) [H3C] public-key local create rsa
3.4 创建/配置 SSH 用户
[H3C] local-user admin class manage [H3C-luser-manage-admin] password cipher YourPassword@123 [H3C-luser-manage-admin] service-type ssh [H3C-luser-manage-admin] authorization-attribute user-role network-admin [H3C-luser-manage-admin] quit
3.5 配置 VTY 线路
[H3C] user-interface vty 0 4 [H3C-ui-vty0-4] authentication-mode scheme # 本地用户认证 [H3C-ui-vty0-4] protocol inbound ssh # 仅允许 SSH [H3C-ui-vty0-4] quit
3.6 保存配置
[H3C] save force
四、第二阶段:SSH 远程登录
4.1 客户端连接
macOS / Linux 终端:
ssh admin@192.168.1.100
Windows(PuTTY / Xshell):
Host: 192.168.1.100 Port: 22 连接类型: SSH 用户名: admin
首次连接会提示保存主机指纹,输入yes即可。
4.2 登录后界面
<Switch-01> # 用户视图(>) <Switch-01> system-view [Switch-01] # 系统视图([])
五、第三阶段:SSH 远程开局配置
5.1 修改设备名称
[Switch-01] sysname Core-Switch
5.2 VLAN 划分
# 创建 VLAN [Core-Switch] vlan 10 [Core-Switch-vlan10] name Office [Core-Switch-vlan10] quit [Core-Switch] vlan 20 [Core-Switch-vlan20] name Server [Core-Switch-vlan20] quit [Core-Switch] vlan 30 [Core-Switch-vlan30] name Guest [Core-Switch-vlan30] quit
5.3 Access 端口配置(连接终端设备)
[Core-Switch] interface GigabitEthernet1/0/1 [Core-Switch-GigabitEthernet1/0/1] port link-type access [Core-Switch-GigabitEthernet1/0/1] port access vlan 10 [Core-Switch-GigabitEthernet1/0/1] stp edged-port enable # 边缘端口,快速转发 [Core-Switch-GigabitEthernet1/0/1] quit
5.4 Trunk 端口配置(级联/上联)
[Core-Switch] interface GigabitEthernet1/0/24 [Core-Switch-GigabitEthernet1/0/24] port link-type trunk [Core-Switch-GigabitEthernet1/0/24] port trunk permit vlan all [Core-Switch-GigabitEthernet1/0/24] quit
5.5 生成树协议(防环)
[Core-Switch] stp global enable [Core-Switch] stp mode rstp # 推荐 RSTP,收敛更快
5.6 保存配置
[Core-Switch] save force
六、密码认证详解
6.1 密码格式对比
| 命令 | 说明 | 安全性 |
|---|---|---|
password simple 密码 | 明文存储,display current-config可见 | 低 |
password cipher 密码 | 密文存储,配置显示为加密字符串 | 中 |
password hash 哈希值 | 直接设置哈希 | 高 |
推荐使用 cipher:
[H3C-luser-manage-admin] password cipher MySecret@2024
6.2 VTY 认证模式
| 模式 | 命令 | 说明 |
|---|---|---|
| scheme(推荐) | authentication-mode scheme | 使用本地用户认证,需配用户名+密码 |
| password | authentication-mode password | 仅密码认证,无用户名 |
| none | authentication-mode none | 无认证(不推荐) |
6.3 已有用户添加/修改密码
如果交换机已有用户,只需修改密码:
[H3C] local-user 已有用户名 class manage [H3C-luser-manage-已有用户名] password cipher 新密码 [H3C-luser-manage-已有用户名] service-type ssh [H3C-luser-manage-已有用户名] authorization-attribute user-role network-admin [H3C-luser-manage-已有用户名] quit # 确保 VTY 认证方式正确 [H3C] user-interface vty 0 4 [H3C-ui-vty0-4] authentication-mode scheme [H3C-ui-vty0-4] protocol inbound ssh [H3C-ui-vty0-4] quit [H3C] save
七、SSH 安全加固
# 1. SSH 超时时间(秒) [H3C] ssh server authentication-timeout 30 # 2. SSH 最大重试次数 [H3C] ssh server authentication-retries 3 # 3. 限制 SSH 来源 IP(ACL) [H3C] acl basic 2000 [H3C-acl-ipv4-basic-2000] rule permit source 192.168.1.0 0.0.0.255 [H3C-acl-ipv4-basic-2000] quit [H3C] user-interface vty 0 4 [H3C-ui-vty0-4] acl 2000 inbound [H3C-ui-vty0-4] quit # 4. 关闭 Telnet(仅保留 SSH) [H3C] undo telnet server enable # 5. 限制 VTY 空闲超时 [H3C] user-interface vty 0 4 [H3C-ui-vty0-4] idle-timeout 5 # 5分钟无操作自动断开 [H3C-ui-vty0-4] quit
八、常用验证命令
# 查看 SSH 服务状态 display ssh server status # 查看当前在线用户 display users # 查看本地用户列表及权限 display local-user # 查看 VTY 线路配置 display user-interface vty 0 # 查看当前运行配置 display current-configuration # 查看 VLAN 信息 display vlan brief # 查看端口状态 display interface brief # 查看生成树状态 display stp brief # 查看路由表 display ip routing-table # 查看保存的配置 display saved-configuration
九、常见问题排查
| 故障现象 | 可能原因 | 解决方法 |
|---|---|---|
| SSH 连接被拒绝 | SSH 服务未开启 | ssh server enable |
| 认证失败 | 用户名/密码错误 | display local-user检查 |
| 权限被拒绝 | VTY 未配 scheme 认证 | authentication-mode scheme |
| Connection refused | protocol inbound非 ssh | protocol inbound ssh |
| 无支持的认证方式 | service-type不含 ssh | service-type ssh |
| 密码不过 | 密码强度不够 | 包含字母+数字+特殊字符 |
| 网络不通 | IP 或路由配置错误 | ping测试连通性 |
十、配置清单速查表
| 序号 | 配置项目 | 关键命令 |
|---|---|---|
| 1 | 设备命名 | sysname 名称 |
| 2 | 管理 IP | interface Vlan-interface 1→ip address |
| 3 | 默认路由 | ip route-static 0.0.0.0 0.0.0.0 网关 |
| 4 | 开启 SSH | ssh server enable |
| 5 | 创建用户 | local-user 用户名 class manage |
| 6 | 设置密码 | password cipher 密码 |
| 7 | 授权角色 | authorization-attribute user-role network-admin |
| 8 | 服务类型 | service-type ssh |
| 9 | VTY 认证 | authentication-mode scheme |
| 10 | VTY 协议 | protocol inbound ssh |
| 11 | VLAN 创建 | vlan ID→name 名称 |
| 12 | Access 口 | port link-type access→port access vlan ID |
| 13 | Trunk 口 | port link-type trunk→port trunk permit vlan all |
| 14 | 生成树 | stp global enable |
| 15 | 保存配置 | save force |
📌核心三要素:VTY
authentication-mode scheme+ 用户service-type ssh+password密码,缺一不可!
📅 文档版本:v1.0 | 适用设备:H3C S5130 系列(Comware V7)
