PASSWORD,ENABLE,CONSOLE,VTY及TACACS认证顺序及区别

本文详细解析了交换机登录过程中不同认证方式(本地、line、TACACS)的配置顺序及区别,包括如何在交换机上建立用户名、密码、enable密码,并通过console口和虚拟终端进行认证。此外,还探讨了TACACS服务器认证的实现及其对登录的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

交换机的登录,用户名,密码是最基础的问题,然而由于很少有人去关心它,所以用的时候难免手忙脚乱,本文讲述了PASSWORD,ENABLECONSOLE,VTYTACACS认证顺序及区别

我们先做如下配置

Switch(config)#aaa authentication login BBDD local    新建个认证方式BBDD为本地认证

Switch(config)#aaa authentication login CCSS line      新建个认证方式CCSSline认证

Switch(config)#aaa authentication login TTCC group tacacs+  新建个认证方式TTCCtacacs认证


Switch(config)#username user privilege 15 password 123 在交换机上建个用户名密码


Switch(config)#enable secret 123456  设定enable的密码


Switch(config)#line console 0  进入console

Switch(config-line)#password 1234  设置console 口认证的密码


Switch(config)#line vty 0 4   进入虚拟终端0-4
 
Switch(config)#line console 0
Switch(config-line)#login authentication BBDD
 Username:user
Pssword:123
Enable:123456
 
 
Switch(config)#line vty 0 4
Switch(config-line)#login authentication BBDD
 
 Username:user
Pssword:123
Enable:123456
 
Switch(config)#line console 0
Switch(config-line)#login authentication CCSS
 Pssword:1234
Enable:123456
 
 
Switch(config)#line vty 0 4
Switch(config-line)#login authentication CCSS
 
 Pssword:12345
Enable:123456
 
Switch(config)#line console 0
Switch(config-line)#login authentication TTCC
 Tacacs server 认证
 
 
Switch(config)#line vty 0 4
Switch(config-line)#login authentication TTCC
 
 Tacacs server 认证
 
#aaa authentication login default group tacacs+ local
aaa authentication enable default group tacacs+ enable
且Tacacs Server正常
 Tacacs server 认证
 Tacacs server 认证
 
#aaa authentication login default group tacacs+ local
aaa authentication enable default group tacacs+ enable
且Tacacs Serverr 挂掉
 Username:user
Pssword:123
Enable:123456
 Username:user
Pssword:123
Enable:123456
 
aaa authentication login default group tacacs+ line
aaa authentication enable default group tacacs+ enable
且Tacacs Server正常
 Tacacs server 认证
 Tacacs server 认证
 
aaa authentication login default group tacacs+ line
aaa authentication enable default group tacacs+ enable
且Tacacs Serverr 挂掉
 Pssword:1234
Enable:123456
 Pssword:12345
Enable:123456
 
Switch(config)#line console 0
Switch(config-line)#login authentication BBDD
 Username:user
Pssword:123
Enable:123456
 
 
Switch(config)#line vty 0 4
Switch(config-line)#login authentication BBDD
 
 Username:user
Pssword:123
Enable:123456
 
Switch(config)#line console 0
Switch(config-line)#login authentication CCSS
 Pssword:1234
Enable:123456
 
 
Switch(config)#line vty 0 4
Switch(config-line)#login authentication CCSS
 
 Pssword:12345
Enable:123456
 
Switch(config)#line console 0
Switch(config-line)#login authentication TTCC
 Tacacs server 认证
 
 
Switch(config)#line vty 0 4
Switch(config-line)#login authentication TTCC
 
 Tacacs server 认证
 
#aaa authentication login default group tacacs+ local
aaa authentication enable default group tacacs+ enable
且Tacacs Server正常
 Tacacs server 认证
 Tacacs server 认证
 
#aaa authentication login default group tacacs+ local
aaa authentication enable default group tacacs+ enable
且Tacacs Serverr 挂掉
 Username:user
Pssword:123
Enable:123456
 Username:user
Pssword:123
Enable:123456
 
aaa authentication login default group tacacs+ line
aaa authentication enable default group tacacs+ enable
且Tacacs Server正常
 Tacacs server 认证
 Tacacs server 认证
 
aaa authentication login default group tacacs+ line
aaa authentication enable default group tacacs+ enable
且Tacacs Serverr 挂掉
 Pssword:1234
Enable:123456
 Pssword:12345
Enable:123456
 

几点说明:
1.
Switch(config)#enable password123456
Switch(config)#enable secret 123456
都是设置 enable的密码,只不过有secret 时 password不起作用

2.username user privilege 15 password 123
username user privilege 15 secret 123
不能同时设置,privilege 后面的数字 1-15 用来划分权限级别,15最高

3.Switch(config)#line vty 0 4
代表终端0到4,最多是0到15一共16个终端,是用来设置同时允许多少人TELNET,所以一般设成0 4 ,共五个终端就够用了。
from netmiko import ConnectHandler from netmiko.exceptions import NetmikoAuthenticationException, NetmikoTimeoutException import time import logging # ===================== 配置参数 ===================== SWITCH = { 'device_type': 'hp_comware', # H3C设备类型 'ip': '192.168.1.1', # 交换机IP地址 'username': 'admin', # SSH用户名 'password': 'admin123', # SSH密码 'port': 22, # SSH端口 'secret': '', # Enable密码(若无则留空) 'timeout': 120, # 连接超时时间 } # VLAN配置 VLAN_CONFIG = { 'vlan_id': 230, 'vlan_ip': '192.168.230.1', 'subnet_mask': '255.255.255.0' } # DHCP配置 DHCP_POOL = { 'name': 'vlan230_pool', 'network': '192.168.230.0', 'mask': '255.255.255.0', 'gateway': '192.168.230.1', 'dns': '114.114.114.114', 'range_start': '192.168.230.50', 'range_end': '192.168.230.200' } # 接口配置 INTERFACE_CONFIG = { 'trunk_ports': ['GigabitEthernet1/0/1', 'GigabitEthernet1/0/2'], 'mirror_source': 'GigabitEthernet1/0/3', 'mirror_dest': 'GigabitEthernet1/0/10' } # TACACS配置 TACACS_CONFIG = { 'scheme_name': 'TACACS_GROUP', 'server_ip': '10.10.10.100', 'key': 'TacacsSecretKey123!', 'vty_range': '0 4' } # ===================== 配置函数 ===================== def configure_ssh(conn): """配置SSH服务并关闭不安全协议""" commands = [ 'public-key local create rsa', # 生成RSA密钥 'ssh server enable', # 启用SSH服务 'ssh user admin service-type all authentication-type password', 'undo telnet server enable', # 关闭Telnet 'undo ftp server', # 关闭FTP 'undo sftp server enable' # 关闭SFTP ] output = conn.send_config_set(commands) logging.info(f"SSH配置完成:\n{output}") def configure_console(conn): """配置Console口参数""" commands = [ 'user-interface con 0', 'idle-timeout 15 0', # 15分钟超时 'authentication-mode password' # 密码认证模式 ] output = conn.send_config_set(commands) logging.info(f"Console配置完成:\n{output}") def configure_tacacs(conn, tacacs_config): """配置TACACS认证""" commands = [ f'tacacs scheme {tacacs_config["scheme_name"]}', f'primary authentication server-address {tacacs_config["server_ip"]}', f'primary authorization server-address {tacacs_config["server_ip"]}', f'key authentication cipher {tacacs_config["key"]}', f'user-interface vty {tacacs_config["vty_range"]}', 'authentication-mode scheme' # 应用TACACS认证 ] output = conn.send_config_set(commands) logging.info(f"TACACS配置完成:\n{output}") def configure_vlan(conn, vlan_config): """创建VLAN并配置接口IP""" commands = [ f'vlan {vlan_config["vlan_id"]}', f'interface Vlan-interface {vlan_config["vlan_id"]}', f'ip address {vlan_config["vlan_ip"]} {vlan_config["subnet_mask"]}' ] output = conn.send_config_set(commands) logging.info(f"VLAN配置完成:\n{output}") def configure_dhcp(conn, dhcp_config): """配置DHCP地址池""" commands = [ 'dhcp enable', # 全局启用DHCP f'dhcp server ip-pool {dhcp_config["name"]}', f'network {dhcp_config["network"]} mask {dhcp_config["mask"]}', f'gateway-list {dhcp_config["gateway"]}', f'dns-list {dhcp_config["dns"]}', f'expired day 7', # 租期7天 f'forbidden-ip {dhcp_config["range_start"]} to {dhcp_config["range_end"]}' ] output = conn.send_config_set(commands) logging.info(f"DHCP配置完成:\n{output}") def configure_trunk_ports(conn, trunk_ports): """配置Trunk接口""" for port in trunk_ports: commands = [ f'interface {port}', 'port link-type trunk', 'port trunk permit vlan all', # 允许所有VLAN 'port trunk pvid vlan 1' # 默认PVID ] output = conn.send_config_set(commands) logging.info(f"接口{port} Trunk配置完成:\n{output}") def configure_port_security(conn, ports): """配置端口安全检测""" for port in ports: commands = [ f'interface {port}', 'port-security enable', # 启用端口安全 'port-security intrusion-mode disable-port' # 非法接入时禁用端口 ] output = conn.send_config_set(commands) logging.info(f"端口{port}安全配置完成:\n{output}") def configure_mirror_port(conn, source_port, dest_port): """配置端口镜像""" commands = [ 'mirroring-group 1 local', f'mirroring-group 1 mirroring-port {source_port} both', # 双向流量 f'mirroring-group 1 monitor-port {dest_port}' ] output = conn.send_config_set(commands) logging.info(f"镜像口配置完成:\n{output}") def save_configuration(conn): """保存配置到设备""" output = conn.save_config() # Netmiko内置保存方法 logging.info(f"配置已保存:\n{output}") # ===================== 主执行逻辑 ===================== def main(): # 配置日志记录 logging.basicConfig( filename='h3c_config.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s' ) try: # 建立SSH连接 with ConnectHandler(**SWITCH) as conn: logging.info(f"成功连接到交换机 {SWITCH['ip']}") # 按顺序执行配置任务 configure_ssh(conn) configure_console(conn) configure_tacacs(conn, TACACS_CONFIG) configure_vlan(conn, VLAN_CONFIG) configure_dhcp(conn, DHCP_POOL) configure_trunk_ports(conn, INTERFACE_CONFIG['trunk_ports']) configure_port_security(conn, INTERFACE_CONFIG['trunk_ports']) configure_mirror_port(conn, INTERFACE_CONFIG['mirror_source'], INTERFACE_CONFIG['mirror_dest']) # 保存配置 save_configuration(conn) logging.info("所有配置任务完成!") print("配置成功完成!详细日志请查看 h3c_config.log") except NetmikoAuthenticationException: logging.error("认证失败:请检查用户名/密码") print("错误:认证失败,请检查凭据") except NetmikoTimeoutException: logging.error("连接超时:无法访问设备") print("错误:设备不可达或IP地址错误") except Exception as e: logging.error(f"未预期错误:{str(e)}") print(f"配置失败:{str(e)}") if __name__ == "__main__": main() 整理成文章发布。
最新发布
06-19
在华为路由器上,使用VRP命令配置系统视图并设置consolevty登录认证与超时是一个涉及多个步骤的过程。首先,您需要通过控制台连接到路由器,并进入系统视图,这可以通过在用户视图下输入命令行提示符(system-view)来完成。然后,您将能够进行进一步的配置。 参考资源链接:[华为ENSP-VRP命令操作指南](https://wenku.youkuaiyun.com/doc/i5h21r7qks) 在系统视图下,设置console线路的登录认证,您需要先进入到console线路视图,使用命令line console 0,然后为该线路设置密码,使用命令local-user admin password cipher 密码。完成console线路的配置后,同样可以通过命令line vty 0 4进入vty线路视图,并为vty线路设置登录密码,使用service-type telnet来支持通过telnet登录。 为了确保设备的安全性,您还可以设置超时时间,防止未授权的使用。在系统视图下,使用命令line console 0来进入console线路视图,然后设置超时时间命令为idle-timeout timeout_value。对于vty线路,进入vty线路视图后,使用同样的命令来设置超时时间。 此外,如果您希望管理命令历史记录的保存,可以在系统视图下使用命令display history-size来查看当前保存的命令历史记录条数,使用命令undo history enable来禁用命令历史记录的保存,以保护隐私安全。 以上操作完成后,建议您使用命令save或write来保存配置,以确保重启后配置依然有效。通过这些步骤,您将能够有效地配置管理华为路由器的登录认证超时设置,确保网络设备的安全性。如果您希望深入了解更多关于VRP命令的具体细节更多配置选项,可以参考《华为ENSP-VRP命令操作指南》这份资源,它提供了详细的操作指导实验,将帮助您更好地理解掌握路由器的配置与管理。 参考资源链接:[华为ENSP-VRP命令操作指南](https://wenku.youkuaiyun.com/doc/i5h21r7qks)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值