Skip to content

2.2 远程管理:Telnet 与 SSH

作为网工,我们不可能每次调整配置都抱着笔记本跑到机房去插 Console 线。远程管理是我们的日常工作方式。

1. 虚拟终端 (VTY)

VRP 使用 VTY (Virtual Teletype) 接口来处理远程连接。通常我们配置 user-interface vty 0 4,表示允许 5 个管理员同时在线。

2. 配置 Telnet (明文,不推荐但基础)

Telnet 使用 TCP 23 端口。它的最大缺点是明文传输(账号密码在网上裸奔)。

方式一:仅密码验证 (简单)

bash
[R1] user-interface vty 0 4
[R1-ui-vty0-4] authentication-mode password
[R1-ui-vty0-4] set authentication-password cipher Huawei@123
[R1-ui-vty0-4] user-privilege level 3    # 赋予管理员权限(3级)

方式二:AAA 认证 (推荐,用户名+密码)

AAA = Authentication (认证), Authorization (授权), Accounting (审计)。

bash
# 1. 创建本地用户
[R1] aaa
[R1-aaa] local-user admin password cipher Huawei@123
[R1-aaa] local-user admin service-type telnet
[R1-aaa] local-user admin privilege level 3  # 3级代表管理级,最高15级

# 2. 应用到 VTY 接口
[R1] user-interface vty 0 4
[R1-ui-vty0-4] authentication-mode aaa

3. 配置 SSH (安全,加密)

SSH (Secure Shell) 使用 TCP 22 端口,数据全程加密。这是生产环境的标准配置。

配置步骤:

  1. 生成密钥对 (RSA):
    bash
    [R1] rsa local-key-pair create
  2. 开启 SSH 服务
    bash
    [R1] stelnet server enable
  3. 配置 AAA 用户 (支持 SSH)
    bash
    [R1] aaa
    [R1-aaa] local-user python password cipher Huawei@123
    [R1-aaa] local-user python service-type ssh    # 服务类型改为 ssh
    [R1-aaa] local-user python privilege level 3
  4. 配置 VTY 接口支持 SSH
    bash
    [R1] user-interface vty 0 4
    [R1-ui-vty0-4] authentication-mode aaa
    [R1-ui-vty0-4] protocol inbound ssh   # 仅允许 SSH (或者 all)
  5. 配置 SSH 用户认证方式
    bash
    [R1] ssh user python authentication-type password

4. 权限等级 (Privilege Level)

华为设备将用户权限分为 0-15 共 16 个等级:

  • Level 0 (参观级):只能运行 ping, tracert 等极少数命令。
  • Level 1 (监控级):可以 display 查看大部分状态,但不能修改。
  • Level 2 (配置级):可以修改配置,但不能操作文件系统。
  • Level 3 (管理级):最高权限,可以管理文件、用户等。
  • Level 4-15:预留给自定义权限。