配置设备作为STelnet客户端登录其他设备示例
组网需求
如图5-4所示,用户希望在服务器端和客户端进行安全的数据交互,配置两个登录用户为client001和client002,分别使用password认证方式和dsa认证方式登录SSH服务器。
使用STelnet V1协议存在安全风险,建议使用STelnet V2登录设备。
配置思路
- 在SSH服务器端生成本地密钥对,实现在服务器端和客户端进行安全的数据交互。
- 在SSH服务器端配置SSH用户client001和client002分别使用不同的认证方式。
- 在SSH服务器端开启STelnet服务功能。
- 在SSH服务器端配置SSH用户client001和client002的服务方式为STelnet。
- 用户client001和client002分别以STelnet方式实现登录SSH服务器。
操作步骤
- 在服务器端生成本地密钥对
<HUAWEI> system-view [HUAWEI] sysname SSH Server [SSH Server] dsa local-key-pair create Info: The key name will be: SSH Server_Host_DSA. Info: The DSA host key named SSH Server_Host_DSA already exists. Info: The key modulus can be any one of the following : 1024, 2048. Info: If the key modulus is greater than 512, it may take a few minutes. Please input the modulus [default=2048]: Info: Generating keys........ Info: Succeeded in creating the DSA host keys.
- 在服务器端创建SSH用户
# 配置VTY用户界面。
[SSH Server] user-interface vty 0 4 [SSH Server-ui-vty0-4] authentication-mode aaa [SSH Server-ui-vty0-4] protocol inbound ssh [SSH Server-ui-vty0-4] quit
- 创建SSH用户client001。
# 新建用户名为client001的SSH用户,且认证方式为password。
[SSH Server] aaa [SSH Server-aaa] local-user client001 password irreversible-cipher Huawei@123 [SSH Server-aaa] local-user client001 privilege level 3 [SSH Server-aaa] local-user client001 service-type ssh [SSH Server-aaa] quit [SSH Server] ssh user client001 [SSH Server] ssh user client001 authentication-type password
- 创建SSH用户client002。
# 新建用户名为client002的SSH用户,且认证方式为dsa。
[SSH Server] ssh user client002 [SSH Server] ssh user client002 authentication-type dsa
# 在STelnet客户端Client002生成客户端的本地密钥对。
<HUAWEI> system-view [HUAWEI] sysname client002 [client002] dsa local-key-pair create Info: The key name will be: SSH Server_Host_DSA. Info: The DSA host key named SSH Server_Host_DSA already exists. Info: The key modulus can be any one of the following : 1024, 2048. Info: If the key modulus is greater than 512, it may take a few minutes. Please input the modulus [default=2048]: Info: Generating keys........ Info: Succeeded in creating the DSA host keys.
# 查看客户端上生成的DSA密钥对的公钥部分。
[client002] display dsa local-key-pair public ===================================================== Time of Key pair created: 2014-03-03 16:51:28-05:13 Key name: client002_Host Key modulus : 2048 Key type: DSA encryption Key Key fingerprint: c0:52:b0:37:4c:b2:64:d1:8f:ff:a1:42:87:09:8c:6f ===================================================== Key code: 30820109 02820100 CA97BCDE 697CEDE9 D9AB9475 9E004D15 C8B95116 87B79B0C 5698C582 69A9F4D0 45ED0E53 AF2EDEC1 A09DF4BE 459E34B6 6697B85D 2191A00E 92F3A5E7 FB0E73E7 F0212432 E898D979 8EAA491E E2B69727 4B51A2BE CD86A144 16748D1E 4847A814 3FE50862 6EB1AD81 EB49A05E 64F6D186 C4E94CDB 04C53074 B839305A 7F7BCE2C 606F6C91 EA958B6D AC46C12B 8C2B1E03 98F1C09D 3AF2A69D 6867F930 DF992692 9A921682 916273FC 4DD875D4 44BC371E DDBB8F6A C0A4CDB3 ADDAE853 DB86B9FA DB13CCA9 D8CF6EC1 530CC2F5 697C4707 90829982 4339507F F354FAF9 0F9CD2C2 F7D6FF3D 901D700F F0588104 856B9592 71D773E2 E76E8EEB 431FB60D 60ABC20B 0203 010001 Host public key for PEM format code: ---- BEGIN SSH2 PUBLIC KEY ---- AAAAB3NzaC1yc2EAAAADAQABAAABAQDKl7zeaXzt6dmrlHWeAE0VyLlRFoe3mwxW mMWCaan00EXtDlOvLt7BoJ30vkWeNLZml7hdIZGgDpLzpef7DnPn8CEkMuiY2XmO qkke4raXJ0tRor7NhqFEFnSNHkhHqBQ/5QhibrGtgetJoF5k9tGGxOlM2wTFMHS4 OTBaf3vOLGBvbJHqlYttrEbBK4wrHgOY8cCdOvKmnWhn+TDfmSaSmpIWgpFic/xN 2HXURLw3Ht27j2rApM2zrdroU9uGufrbE8yp2M9uwVMMwvVpfEcHkIKZgkM5UH/z VPr5D5zSwvfW/z2QHXAP8FiBBIVrlZJx13Pi526O60Mftg1gq8IL ---- END SSH2 PUBLIC KEY ---- Public key code for pasting into OpenSSH authorized_keys file : ssh-dsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDKl7zeaXzt6dmrlHWeAE0VyLlRFoe3mwxWmMWCaan00EXtDlOvLt7BoJ30vkWeNLZml7hdIZGgDpLzpef7DnPn8CEkMuiY2XmOqkke4raXJ0tRor7NhqFEFnSNHkhHqBQ/5QhibrGtgetJoF5k9tGGxOlM2wTFMHS4OTBaf3vOLGBvbJHqlYttrEbBK4wrHgOY8cCdOvKmnWhn+TDfmSaSmpIWgpFic/xN2HXURLw3Ht27j2rApM2zrdroU9uGufrbE8yp2M9uwVMMwvVpfEcHkIKZgkM5UH/zVPr5D5zSwvfW/z2QHXAP8FiBBIVrlZJx13Pi526O60Mftg1gq8IL dsa-key
# 将客户端上产生的DSA公钥配置到服务器端(上面display命令显示信息中黑体部分即为客户端产生的DSA公钥,将其拷贝粘贴至服务器端)。
[SSH Server] dsa peer-public-key dsakey001 encoding-type der [SSH Server-dsa-public-key] public-key-code begin Info: Enter "DSA key code" view, return the last view with "public-key-code end". [SSH Server-dsa-key-code] 30820109 [SSH Server-dsa-key-code] 2820100 [SSH Server-dsa-key-code] CA97BCDE 697CEDE9 D9AB9475 9E004D15 C8B95116 [SSH Server-dsa-key-code] 87B79B0C 5698C582 69A9F4D0 45ED0E53 AF2EDEC1 [SSH Server-dsa-key-code] A09DF4BE 459E34B6 6697B85D 2191A00E 92F3A5E7 [SSH Server-dsa-key-code] FB0E73E7 F0212432 E898D979 8EAA491E E2B69727 [SSH Server-dsa-key-code] 4B51A2BE CD86A144 16748D1E 4847A814 3FE50862 [SSH Server-dsa-key-code] 6EB1AD81 EB49A05E 64F6D186 C4E94CDB 04C53074 [SSH Server-dsa-key-code] B839305A 7F7BCE2C 606F6C91 EA958B6D AC46C12B [SSH Server-dsa-key-code] 8C2B1E03 98F1C09D 3AF2A69D 6867F930 DF992692 [SSH Server-dsa-key-code] 9A921682 916273FC 4DD875D4 44BC371E DDBB8F6A [SSH Server-dsa-key-code] C0A4CDB3 ADDAE853 DB86B9FA DB13CCA9 D8CF6EC1 [SSH Server-dsa-key-code] 530CC2F5 697C4707 90829982 4339507F F354FAF9 [SSH Server-dsa-key-code] 0F9CD2C2 F7D6FF3D 901D700F F0588104 856B9592 [SSH Server-dsa-key-code] 71D773E2 E76E8EEB 431FB60D 60ABC20B [SSH Server-dsa-key-code] 203 [SSH Server-dsa-key-code] 10001 [SSH Server-dsa-key-code] public-key-code end [SSH Server-dsa-public-key] peer-public-key end
# 在SSH服务器端为SSH用户client002绑定STelnet客户端的dsa公钥。
[SSH Server] ssh user client002 assign dsa-key dsakey001
- 创建SSH用户client001。
- SSH服务器端开启STelnet服务功能
# 开启STelnet服务功能。
[SSH Server] stelnet server enable
- 配置SSH用户client001、client002的服务方式为STelnet
[SSH Server] ssh user client001 service-type stelnet [SSH Server] ssh user client002 service-type stelnet
- STelnet客户端连接SSH服务器
# 第一次登录,需要使能SSH客户端首次认证功能。使能客户端Client001首次认证功能。
<HUAWEI> system-view [HUAWEI] sysname client001 [client001] ssh client first-time enable
使能客户端Client002首次认证功能。
[client002] ssh client first-time enable
# STelnet客户端Client001用password认证方式连接SSH服务器,输入配置的用户名和密码。
[client001] stelnet 10.1.1.1 Please input the username:client001 Trying 10.1.1.1 ... Press CTRL+K to abort Connected to 10.1.1.1 ... The server is not authenticated. Continue to access it? [Y/N] :y Save the server's public key? [Y/N] :y The server's public key will be saved with the name 10.1.1.1. Please wait... Please select public key type for user authentication [R for RSA; D for DSA; Enter for Skip publickey authentication; Ctrl_C for Can cel], Please select [R, D, Enter or Ctrl_C]:d Enter password:
输入密码,显示登录成功信息如下:
<SSH Server>
# STelnet客户端Clent002用dsa认证方式连接SSH服务器。
[client002] stelnet 10.1.1.1 user-identity-key dsa Please input the username:client002 Trying 10.1.1.1 ... Press CTRL+K to abort Connected to 10.1.1.1 ... Please select public key type for user authentication [R for RSA; D for DSA; Enter for Skip publickey authentication; Ctrl_C for Can cel], Please select [R, D, Enter or Ctrl_C]:d <SSH Server>
如果登录成功,用户将进入用户视图。如果登录失败,用户将收到Session is disconnected的信息。
- 验证配置结果
在SSH服务器端执行display ssh server status命令可以查看到STelnet服务已经使能。执行display ssh user-information命令可以查看服务器端SSH用户信息。
# 查看SSH状态信息。
[SSH Server] display ssh server status SSH version :2.0 SSH connection timeout :60 seconds SSH server key generating interval :0 hours SSH authentication retries :3 times SFTP server :Disable Stelnet server :Enable Scp server :Disable SSH server source :0.0.0.0 ACL4 number :0 ACL6 number :0
# 查看SSH用户信息。
[SSH Server] display ssh user-information User 1: User Name : client001 Authentication-type : password User-public-key-name : - User-public-key-type : - Sftp-directory : - Service-type : stelnet Authorization-cmd : No User 2: User Name : client002 Authentication-type : dsa User-public-key-name : dsakey001 User-public-key-type : dsa Sftp-directory : - Service-type : stelnet Authorization-cmd : No
配置文件
- SSH服务器的配置文件
# sysname SSH Server # dsa peer-public-key dsakey001 encoding-type der public-key-code begin 30820109 02820100 CA97BCDE 697CEDE9 D9AB9475 9E004D15 C8B95116 87B79B0C 5698C582 69A9F4D0 45ED0E53 AF2EDEC1 A09DF4BE 459E34B6 6697B85D 2191A00E 92F3A5E7 FB0E73E7 F0212432 E898D979 8EAA491E E2B69727 4B51A2BE CD86A144 16748D1E 4847A814 3FE50862 6EB1AD81 EB49A05E 64F6D186 C4E94CDB 04C53074 B839305A 7F7BCE2C 606F6C91 EA958B6D AC46C12B 8C2B1E03 98F1C09D 3AF2A69D 6867F930 DF992692 9A921682 916273FC 4DD875D4 44BC371E DDBB8F6A C0A4CDB3 ADDAE853 DB86B9FA DB13CCA9 D8CF6EC1 530CC2F5 697C4707 90829982 4339507F F354FAF9 0F9CD2C2 F7D6FF3D 901D700F F0588104 856B9592 71D773E2 E76E8EEB 431FB60D 60ABC20B 0203 010001 public-key-code end peer-public-key end # aaa local-user client001 password irreversible-cipher $1a$gRNl~ukoL~0.WU)C2]~2a}Cz/Y0-u8M{j@Ql6/xHryO-Y7m{=A>kWc.-q}>*$ local-user client001 privilege level 3 local-user client001 service-type ssh # stelnet server enable ssh user client001 ssh user client001 authentication-type password ssh user client001 service-type stelnet ssh user client002 ssh user client002 authentication-type dsa ssh user client002 assign dsa-key dsakey001 ssh user client002 service-type stelnet # user-interface vty 0 4 authentication-mode aaa # return
- SSH客户端Client001的配置文件
# sysname client001 # ssh client first-time enable # return
- SSH客户端Client002的配置文件
# sysname client002 # ssh client first-time enable # return