问题描述
通过 telnet 登录设备,对帐号密码的输入不够友好(无法自动登录,需要使用 except 工具配合),也不够安全。
好在华为设备支持 SSH(STelnet)登录,这样我们便能通过本地工具,并使用密钥等安全方式登录设备。
该笔记将记录:如何配置 Huawei 路由交换设备,以实现通过 SSH 登录,以及相关问题解决方法。
解决方案
参考 设备文档/配置通过STelnet登录设备 文档,以获取配置 SSH 登录设备的细节说明。
实验示例
注意事项:模拟器环境仅演示部分基础操作,实际环境操作建议参照设备手册(两者命令存在出入);
密码登录
// 配置 VTY 认证方式 user-interface vty 0 4 authentication-mode aaa protocol inbound all # SSH + Telnet // 配置用户的服务类型 aaa local-user client001 password cipher Huawei@123 local-user client001 privilege level 3 local-user client001 service-type ssh # 注意保留原始用户服务类型 // 进行用户相关配置 ssh user client001 authentication-type password // 开启 SSH 服务 stelnet server enable
客户端密码登录测试:
[AR1]ssh client first-time enable [AR1]stelnet 10.0.0.3 ... <AR3>
密钥登录
在 AR2 中,创建密钥对:
[AR2]rsa local-key-pair create ... [AR2]display rsa local-key-pair public ... # 注意,公钥为 Key name: Host 部分
在 AR3 中,添加公钥:
[AR3]rsa peer-public-key AR2 [AR3-rsa-public-key]public-key-code begin [AR3-rsa-key-code]3047 ... [AR3-rsa-key-code] 010001 [AR3-rsa-key-code]public-key-code end [AR3-rsa-public-key]peer-public-key end
在 AR3 中,配置认证方式:
// 配置 VTY 认证方式 user-interface vty 0 4 authentication-mode aaa protocol inbound all # SSH + Telnet // 配置用户的服务类型 aaa local-user client002 password cipher Huawei@123 local-user client002 privilege level 3 local-user client002 service-type ssh # 注意保留原始用户服务类型 // 进行用户相关配置 [AR3]ssh user client002 authentication-type rsa [AR3]ssh user client002 assign rsa-key AR2 // 开启 SSH 服务 stelnet server enable
在 AR2 中,客户端密码登录测试:
[AR2]ssh client first-time enable [AR2]stelnet 10.0.0.3 Please input the username:client002 Trying 10.0.0.3 ... Press CTRL+K to abort Connected to 10.0.0.3 ... The server is not authenticated. Continue to access it? (y/n)[n]:y Feb 10 2022 15:54:54-08:00 AR2 %%01SSH/4/CONTINUE_KEYEXCHANGE(l)[1]:The server h ad not been authenticated in the process of exchanging keys. When deciding wheth er to continue, the user chose Y. Save the server's public key? (y/n)[n]:y The server's public key will be saved with the name 10.0.0.3. Please wait... Feb 10 2022 15:54:57-08:00 AR2 %%01SSH/4/SAVE_PUBLICKEY(l)[2]:When deciding whet her to save the server's public key 10.0.0.3, the user chose Y. <AR3>
常见问题处理
no matching key exchange method found
ssh – How to enable diffie-hellman-group1-sha1 key exchange on Debian 8.0?
问题描述:
# ssh admin@router.example.com Unable to negotiate with ... no matching key exchange method found. Their offer: diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1
原因分析:
网络设备提供的密钥交换算法,不被 SSH 客户端识别(或被废弃)
解决方案:
# 在登录时,指定密钥交换方法 ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 admin@router.example.com
shell request failed on channel 0
问题描述:
# ssh -v -oKexAlgorithms=diffie-hellman-group-exchange-sha1 admin@192.168.23.15 ... debug1: Next authentication method: keyboard-interactive User Authentication Password: // 提示输入用户名密码 debug1: Authentication succeeded (keyboard-interactive). // 提示认证成功 Authenticated to 192.168.23.15 ([192.168.23.15]:22). debug1: channel 0: new [client-session] debug1: Entering interactive session. debug1: pledge: network debug1: Requesting authentication agent forwarding. debug1: Sending environment. debug1: Sending env LANG = en_US.UTF-8 shell request failed on channel 0 // 但是无法进入终端
解决方案:
[SWITCH-01]ssh user admin service-type all
补充说明:
模拟器环境仅演示部分基础操作,不一定试用于实际环境操作(两者命令过程存在出入);
参考文献
设备文档/配置通过STelnet登录设备