交换机开启 SSH 远程登录 — 三厂商完整配置

H3C Comware · 华为 VRP · 思科 IOS。每段配置可整段复制到设备,按注释理解每步作用。

H3C(Comware V7)

# 1. 生成本地密钥对(RSA + DSA)
public-key local create rsa
public-key local create dsa

# 2. 创建管理 VLAN 的 IP(假设用 VLAN 1)
interface Vlan-interface1
 ip address 192.168.1.1 255.255.255.0
 undo shutdown
quit

# 3. 开启 SSH 服务
ssh server enable

# 4. 创建本地用户(管理角色 + 密码)
local-user admin
 password hash Your_Str0ng_Pass!
 service-type ssh
 authorization-attribute user-role network-admin
quit

# 5. VTY 线路:只允许 SSH
user-interface vty 0 4
 authentication-mode scheme
 protocol inbound ssh
quit

# 6.(可选)关闭 Telnet 提升安全
undo telnet server enable

# 7. 验证
display ssh server status
display ssh user-information

华为(VRP)

# 1. 生成本地密钥对
rsa local-key-pair create
# (新版设备也可用)dsa local-key-pair create

# 2. 管理 IP
interface Vlanif1
 ip address 192.168.1.1 255.255.255.0
 undo shutdown
quit

# 3. 开启 SSH(stelnet)服务
stelnet server enable
ssh user admin authentication-type password
ssh user admin service-type stelnet

# 4. AAA 本地用户
aaa
 local-user admin password irreversible-cipher Your_Str0ng_Pass!
 local-user admin privilege level 15
 local-user admin service-type ssh
quit

# 5. VTY 线路
user-interface vty 0 4
 authentication-mode aaa
 protocol inbound ssh
quit

# 6.(可选)关闭 Telnet
undo telnet server enable

# 7. 验证
display ssh server status
display ssh user-information admin

思科(IOS)

# 1. 生成 RSA 密钥(同时自动开启 SSH)
crypto key generate rsa modulus 2048

# 2. 只允许 SSH v2
ip ssh version 2

# 3. 管理 IP
interface vlan 1
 ip address 192.168.1.1 255.255.255.0
 no shutdown

# 4. 本地用户数据库(启用加密密码)
username admin privilege 15 secret Your_Str0ng_Pass!

# 5. VTY 线路:本地认证 + 只允许 SSH
line vty 0 4
 login local
 transport input ssh
 exec-timeout 10 0

# 6.(可选)关闭 Telnet
line vty 0 4
 transport input ssh   ! 这一行本身就等于禁 Telnet

# 7. 验证
show ip ssh
show running-config | include ssh

常见排错

症状排查点
Connection refuseddisplay ssh server status / show ip ssh 确认服务开启;检查管理 IP 可 ping
提示密码错但密码确定对AAA/本地用户 service-type 是否含 ssh;H3C authentication-mode scheme 是否配在 vty
能连上立刻断开VTY 全被占用:display users / who;配 exec-timeout / idle-timeout
SSH 客户端算法协商失败老设备 SSH v1 与新客户端不兼容;升级或开启兼容模式
安全提醒:① 密码避免 admin/123456 类;② 有条件上 AAA/TACACS+ 集中认证;③ ACL 限制管理源 IP;④ 关闭 Telnet 后留好 console 口作为最后通道。

更多三厂商对照(VLAN/Trunk/STP/聚合/SNMP):30 任务命令总对照表 · VLAN/Trunk 专页。批量开启/审计这些配置可用开源工具 netcfg-vault。