在思科路由器或交换机上配置SSH(Secure Shell)需要首先完成一些基本的设置,包括配置设备的域名、生成加密密钥对、创建用户账户以及启用SSH服务。下面是一个逐步配置SSH的指南:
1. 配置设备的域名
登录到你的设备,并进入全局配置模式,设置域名:
plaintext
Router> enable
Router# configure terminal
Router(config)# ip domain-name example.com
将`example.com`替换为你的实际域名。
2. 生成RSA加密密钥对
生成SSH所需的RSA加密密钥对:
plaintext
Router(config)# crypto key generate rsa
The name for the keys will be: Router.example.com
Choose the size of the key modulus in the range of 360 to 2048 for your
General Purpose Keys. Choosing a key modulus greater than 512 may take
a few minutes.
How many bits in the modulus [512]: 1024
按回车选择默认的512位密钥或输入“1024”以生成1024位密钥。
3. 创建用户账户
创建一个本地用户账户并设置密码:
plaintext
Router(config)# username admin privilege 15 secret C0mpl3xP@ssw0rd
将`admin`替换为你想要的用户名,并将`C0mpl3xP@ssw0rd`替换为你选择的安全密码。
4. 启用SSH并设置vty线
启用SSH版本2并配置vty线路以只允许SSH访问:
plaintext
Router(config)# ip ssh version 2
Router(config)# line vty 0 4
Router(config-line)# transport input ssh
Router(config-line)# login local
Router(config-line)# exit
Router(config)#
5. (可选)限制特定IP地址的访问
你可以使用访问控制列表(ACL)来限制哪些IP地址可以通过SSH连接到设备:
plaintext
Router(config)# access-list 10 permit 192.168.1.0 0.0.0.255
Router(config)# line vty 0 4
Router(config-line)# access-class 10 in
Router(config-line)# exit
Router(config)#
这将仅允许来自`192.168.1.0/24`子网的设备通过SSH连接。
6. 保存配置
最后,保存你的配置:
plaintext
Router# write memory
或者使用:
plaintext
Router# copy running-config startup-config
完成以上步骤后,你应该可以通过SSH连接到思科设备。请注意,SSH客户端应用程序如`PuTTY`或命令行工具(例如Linux和macOS上的`ssh`命令)可以用来测试连接。
例如:
plaintext
ssh admin@192.168.1.1
将`admin`替换为你的用户名,`192.168.1.1`替换为你的设备的IP地址。
查看详情
查看详情