如何配置SSH

312 阅读2分钟

如何配置SSH

一、SSH配置通用知识

SSH(Secure Shell)是用于安全远程登录的网络协议,通过加密通信保障数据传输安全。核心配置要素包括:

  1. 生成RSA/DSA密钥对
  2. 创建本地用户及权限设置
  3. 配置VTY线路认证方式
  4. 启用SSH协议版本控制
  5. 设置SSH连接参数(超时时间、认证重试次数等)

二、四大厂商配置对比

配置项思科(Cisco)华为(Huawei)华三(H3C)锐捷(Ruijie)
密钥生成命令crypto key generate rsarsa local-key-pair createpublic-key local create rsacrypto key generate rsa
SSH版本控制ip ssh version 2ssh server compatible-ssh1x disablessh server compatibility legacy disablessh version 2
VTY认证模式login localauthentication-mode aaaauthentication-mode schemelogin authentication local
用户权限设置privilege level 15user privilege level 15authorization-attribute user-role network-adminprivilege level 15
默认SSH端口22222222
ACL应用方式access-class <ACL> inacl <ACL> inboundacl <ACL> inboundaccess-class <ACL> in

三、配置步骤及命令

1. 思科设备配置
! 配置域名(必须)
conf t
hostname Router
ip domain-name cisco.com

! 生成RSA密钥
crypto key generate rsa modulus 2048

! 配置SSH参数
ip ssh version 2
ip ssh time-out 90
ip ssh authentication-retries 3

! 创建本地用户
username admin privilege 15 secret Admin@123

! 配置VTY线路
line vty 0 4
 transport input ssh
 login local
 access-class 10 in
exit

! 创建ACL(可选)
ip access-list standard 10
 permit 192.168.1.0 0.0.0.255
2. 华为设备配置
sys
sysname Switch

# 生成RSA密钥
rsa local-key-pair create

# 配置SSH参数
stelnet server enable
ssh user admin
ssh user admin authentication-type password
ssh user admin service-type stelnet
ssh server compatible-ssh1x disable

# 创建本地用户
aaa
 local-user admin password irreversible-cipher Admin@123
 local-user admin privilege level 15
 local-user admin service-type ssh
quit

# 配置VTY线路
user-interface vty 0 4
 authentication-mode aaa
 protocol inbound ssh
 acl 2000 inbound
quit

# 创建ACL(可选)
acl 2000
 rule permit source 192.168.1.0 0.0.0.255
3. 华三设备配置
sys
sysname Switch

# 生成RSA密钥
public-key local create rsa

# 配置SSH参数
ssh server enable
ssh server authentication-retries 3
ssh server timeout 90

# 创建本地用户
local-user admin class manage
 password hash Admin@123
 service-type ssh
 authorization-attribute user-role network-admin

# 配置VTY线路
line vty 0 63
 authentication-mode scheme
 protocol inbound ssh
 acl basic 2000 inbound
quit

# 创建ACL(可选)
acl basic 2000
 rule permit source 192.168.1.0 0.0.0.255
4. 锐捷设备配置
enable
configure terminal
hostname Switch

# 生成RSA密钥
crypto key generate rsa modulus 2048

# 配置SSH参数
ip ssh version 2
ip ssh timeout 90
ip ssh authentication-retries 3

# 创建本地用户
username admin privilege 15 password Admin@123

# 配置VTY线路
line vty 0 4
 login authentication local
 transport input ssh
 access-class 10 in
exit

# 创建ACL(可选)
ip access-list standard 10
 permit 192.168.1.0 0.0.0.255

注意:所有密码建议使用复杂密码并定期更换,SSH版本建议强制使用v2,ACL应根据实际网络环境配置访问控制策略。