34-SSH典型配置舉例
本章節下載: 34-SSH典型配置舉例 (775.00 KB)
資料版本:6W100-20190628
Copyright © 2019 bobty下载软件 版權所有,保留一切權利。
非經本公司書麵許可,任何單位和個人不得擅自摘抄、複製本文檔內容的部分或全部,並不得以任何形式傳播。
除bobty下载软件 的商標外,本手冊中出現的其它公司的商標、產品標識及商品名稱,由各自權利人擁有。
本文檔中的信息可能變動,恕不另行通知。
目 錄
4 設備作為Stelnet服務器配置舉例(password認證)
5 設備作為Stelnet服務器配置舉例(publickey認證)
6 設備作為Stelnet客戶端配置舉例(password認證)
本章介紹了使用SSH(Secure Shell,安全外殼)功能實現安全的遠程訪問或文件管理的典型配置舉例。
本文檔中的配置均是在實驗室環境下進行的配置和驗證,配置前設備的所有參數均采用出廠時的缺省配置。如果您已經對設備進行了配置,為了保證配置效果,請確認現有配置和以下舉例中的配置不衝突。
本文假設您已了解SSH特性。
舉例中的設備運行於非FIPS模式下。若設備運行於FIPS模式下:
· 相關的配置和顯示信息會有所變化,請以設備的實際情況為準。
· 設備作為服務器僅支持RSA和ECDSA密鑰對,且RSA密鑰對的模數隻能為2048比特。
如圖1所示,網絡管理員需要通過Internet遠程登錄到校園網的網關設備(Device)上對其進行相關配置。為了提高對Device進行管理的安全性,可將Device配置為Stelnet服務器,並在Host上運行Stelnet客戶端軟件,在二者之間建立SSH連接。要求:
· Device通過SSH的password認證方式對客戶端進行認證,認證過程在Device本地完成;
· 網絡管理員Host的登錄用戶名為client001,密碼為aabbcc,登錄設備後可以正常使用所有命令。
圖1 設備作為Stelnet服務器配置組網圖
· 為了使SSH的版本協商和算法協商過程正常運行,且為了保證客戶端對連接的服務器的認證正常進行,請在服務器端生成RSA、DSA和ECDSA密鑰對。
· 為了采用本地認證的方式認證用戶,需要在本地服務器Device上創建相應的本地用戶,並在本地用戶視圖下配置密碼。
· Stelnet客戶端通過VTY用戶線訪問設備。因此,需要配置登錄用戶線的認證方式為scheme方式。
· 為了使Stelnet用戶登錄設備後能正常使用所有命令,將用戶角色設置為network-admin,缺省情況下本地用戶的用戶角色為network-operator。
本舉例是在S6890-CMW710-R2712版本上進行配置和驗證的。
缺省情況下,S6890係列交換機的接口處於ADM(Administratively Down)狀態,請根據實際需要在對應接口視圖下使用undo shutdown命令開啟接口。
# 生成RSA密鑰對。
<Device> system-view
[Device] public-key local create rsa
The range of public key modulus is (512 ~ 2048).
If the key modulus is greater than 512, it will take a few minutes.
Press CTRL+C to abort.
Input the modulus length [default = 1024]:
Generating Keys...
..
Create the key pair successfully.
# 生成DSA密鑰對。
[Device] public-key local create dsa
The range of public key modulus is (512 ~ 2048).
If the key modulus is greater than 512, it will take a few minutes.
Press CTRL+C to abort.
Input the modulus length [default = 1024]:
Generating Keys...
......
Create the key pair successfully.
# 生成ECDSA密鑰對。
[Device] public-key local create ecdsa secp256r1
Generating Keys...
.
Create the key pair successfully.
# 使能SSH服務器功能。
[Device] ssh server enable
# 創建VLAN 2,並將Ten-GigabitEthernet1/0/2加入VLAN 2。
[Device] vlan 2
[Device-vlan2] port ten-gigabitethernet 1/0/2
[Device-vlan2] quit
# 配置VLAN接口2的IP地址,客戶端將通過該地址連接Stelnet服務器。
[Device] interface vlan-interface 2
[Device-Vlan-interface2] ip address 192.168.1.40 255.255.255.0
[Device-Vlan-interface2] quit
# 設置Stelnet客戶端登錄用戶界麵的認證方式為scheme。
[Device] line vty 0 63
[Device-line-vty0-63] authentication-mode scheme
[Device-line-vty0-63] quit
# 創建本地用戶client001,並設置用戶密碼、服務類型和用戶角色。
[Device] local-user client001 class manage
New local user added.
[Device-luser-manage-client001] password simple aabbcc
[Device-luser-manage-client001] service-type ssh
[Device-luser-manage-client001] authorization-attribute user-role network-admin
[Device-luser-manage-client001] quit
Stelnet客戶端軟件有很多,例如PuTTY、OpenSSH等。本文中僅以客戶端軟件PuTTY0.60為例,說明Stelnet客戶端的配置方法。
# 安裝PuTTY0.60軟件。
# 打開PuTTY.exe程序,點擊“Session”功能區,出現如圖2所示的客戶端配置界麵。
· 在“Host Name(or IP address)”文本框中輸入Stelnet服務器的IP地址為192.168.1.40。
· 在“Port”文本框中輸入SSH協議端口號22。
· 在“Connection type”區域選擇SSH協議。
圖2 Stelnet客戶端配置界麵
# 在圖2界麵中,單擊<Open>按鈕。彈出“PuTTY Security Alert”對話框。
圖3 Stelnet客戶端登錄界麵(一)
# 單擊“是(Y)”按鈕,並輸入用戶名“client001”和密碼“aabbcc”,即可成功登錄設備使用所有命令。
login as: client001
[email protected]'s password:
******************************************************************************
*Copyright (c) 2004-2018 New H3C Technologies Co., Ltd. All rights reserved.*
* Without the owner's prior written consent, *
* no decompiling or reverse-engineering shall be allowed. *
******************************************************************************
<Device>
#
vlan 2
#
interface Vlan-interface2
ip address 192.168.1.40 255.255.255.0
#
interface Ten-GigabitEthernet1/0/2
port link-mode bridge
port access vlan 2
#
line vty 0 63
authentication-mode scheme
#
ssh server enable
#
local-user client001 class manage
password hash $h$6$CqMnWdX6LIW/hz2Z$4+0Pumk+A98VlGVgqN3n/mEi7hJka9fEZpRZIpSNi9b
cBEXhpvIqaYTvIVBf7ZUNGnovFsqW7nYxjoToRDvYBg==
service-type ssh
authorization-attribute user-role network-admin
authorization-attribute user-role network-operator
#
如圖4所示,網絡管理員需要通過Internet遠程登錄到校園網的網關設備(Device)上對其進行相關配置。為了提高對Device進行管理的安全性和認證強度,將Device配置為Stelnet服務器,要求:
· Device通過publickey認證方式對Stelnet客戶端進行認證,使用的公鑰算法為RSA。
· 網絡管理員Host的登錄用戶名為client001,登錄設備後可以正常使用所有命令。
· 服務器端通過從公鑰文件中導入的方式來配置客戶端的公鑰。
圖4 設備作為Stelnet服務器配置組網圖
· 在服務器的配置過程中需要指定客戶端的公鑰信息,因此需要首先完成客戶端密鑰對的配置,再進行服務器的配置。
· 服務器在采用publickey方式驗證客戶端身份時,首先要比較客戶端發送的Stelnet用戶名、主機公鑰是否與本地配置的SSH用戶名以及相應的客戶端主機公鑰一致,在確認用戶名和客戶端主機公鑰正確後,再利用數字簽名對客戶端進行驗證,而該簽名是客戶端利用主機公鑰對應的私鑰計算出的。因此,需要在服務器端配置客戶端的RSA主機公鑰,並在客戶端為該SSH用戶指定與主機公鑰對應的RSA主機私鑰。
· 如果SSH服務器采用publickey方式認證客戶端,必須在服務器上創建相應的SSH用戶,以及同名的本地用戶(用於下發授權屬性:工作目錄、用戶角色)。
· Stelnet客戶端通過VTY用戶線訪問設備。因此,需要配置登錄用戶線的認證方式為scheme方式。
· 為了使Stelnet用戶登錄設備後要能正常使用所有命令,將用戶的用戶角色設置為network-admin,缺省情況下本地用戶的用戶角色為network-operator。
本舉例是在S6890-CMW710-R2712版本上進行配置和驗證的。
· FIPS模式下,設備作為SSH服務器不支持publickey認證方式。
· 雖然一個客戶端隻會采用RSA、DSA或ECDSA公鑰算法中的一種來認證服務器,但是由於不同客戶端支持的公鑰算法不同,為了確保客戶端能夠成功登錄服務器,請在服務器上同時生成RSA、DSA和ECDSA密鑰對。
· 缺省情況下,S6890係列交換機的接口處於ADM(Administratively Down)狀態,請根據實際需要在對應接口視圖下使用undo shutdown命令開啟接口。
客戶端軟件有很多,例如PuTTY、OpenSSH等。本文中僅以客戶端軟件PuTTY0.60為例,說明Stelnet客戶端的配置方法。
# 在客戶端運行PuTTYGen.exe,在參數欄中選擇“SSH-2 RSA”,點擊<Generate>,產生客戶端密鑰對。
圖5 生成客戶端密鑰(1)
# 在產生密鑰對的過程中需不停地移動鼠標,鼠標移動僅限於圖6藍色框中除綠色標記進程條外的地方,否則進程條會停止顯示,密鑰對將停止產生。
# 密鑰對產生後,點擊<Save public key>,輸入存儲公鑰的文件名key.pub,點擊<保存>按鈕將公鑰文件保存在D盤。
圖7 生成客戶端密鑰(3)
# 點擊<Save private key>存儲私鑰,選擇保存的路徑(例如D:\),並輸入私鑰文件名為private.ppk,點擊保存。
# 創建VLAN 2,並將Ten-GigabitEthernet1/0/2加入VLAN 2。
<Device> system-view
[Device] vlan 2
[Device-vlan2] port ten-gigabitethernet 1/0/2
[Device-vlan2] quit
# 配置VLAN接口2的IP地址。
[Device] interface vlan-interface 2
[Device-Vlan-interface2] ip address 192.168.1.40 255.255.255.0
[Device-Vlan-interface2] quit
# 在Device上創建一個ftp類型的本地用戶,並設置密碼為明文ftp,服務類型為FTP,用戶角色為network-admin,工作目錄為flash:/。
[Device] local-user ftp class manage
New local user added.
[Device-luser-manage-ftp] password simple ftp
[Device-luser-manage-ftp] authorization-attribute user-role network-admin
[Device-luser-manage-ftp] authorization-attribute work-directory flash:/
[Device-luser-manage-ftp] service-type ftp
[Device-luser-manage-ftp] quit
# 開啟Device 的FTP服務器功能。
[Device] ftp server enable
[Device] quit
# Host通過FTP登錄並上傳公鑰文件key.pub到Device。
<Host>ftp 192.168.1.40
Press CTRL+C to abort.
Connected to 192.168.1.40 (192.168.1.40).
220 FTP service ready.
User (192.168.1.56:(none)): ftp
331 Password required for ftp.
Password:
230 User logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> put flash:/key.pub
227 Entering Passive Mode (192,168,1,40,41,116)
150 Accepted data connection
226 File successfully transferred
301 bytes sent in 0.000 seconds (1.05 Mbytes/s)
ftp> quit
221-Goodbye. You uploaded 1 and downloaded 0 kbytes.
221 Logout.
# 生成RSA密鑰對。
[Device] public-key local create rsa
The range of public key modulus is (512 ~ 2048).
If the key modulus is greater than 512, it will take a few minutes.
Press CTRL+C to abort.
Input the modulus length [default = 1024]:
Generating Keys...
...
Create the key pair successfully.
# 生成DSA密鑰對。
[Device] public-key local create dsa
The range of public key modulus is (512 ~ 2048).
If the key modulus is greater than 512, it will take a few minutes.
Press CTRL+C to abort.
Input the modulus length [default = 1024]:
Generating Keys...
....
Create the key pair successfully.
# 生成ECDSA密鑰對。
[Device] public-key local create ecdsa secp256r1
Generating Keys...
.
Create the key pair successfully.
# 使能SSH服務器功能。
[Device] ssh server enable
# 設置Stelnet客戶端登錄用戶界麵的認證方式為scheme。
[Device] line vty 0 63
[Device-line-vty0-63] authentication-mode scheme
[Device-line-vty0-63] quit
# 從文件key.pub中導入客戶端的公鑰,並命名為devicekey。
[Device] public-key peer devicekey import sshkey key.pub
# 設置SSH用戶client001的認證方式為publickey,並指定公鑰為devicekey。
[Device] ssh user client001 service-type stelnet authentication-type publickey assign publickey devicekey
# 創建本地用戶client001,並設置服務類型為SSH,用戶角色為network-admin。
[Device] local-user client001 class manage
New local user added.
[Device-luser-manage-client001] service-type ssh
[Device-luser-manage-client001] authorization-attribute user-role network-admin
[Device-luser-manage-client001] quit
# 客戶端打開PuTTY.exe程序,點擊“Session”功能區,出現如圖8所示的客戶端配置界麵。
· 在“Host Name(or IP address)”文本框中輸入Stelnet服務器的IP地址為192.168.1.40。
· 在“Port”文本框中輸入SSH協議端口號22。
· 在“Connection type”區域選擇SSH協議。
圖8 Stelnet客戶端配置界麵(1)
# 單擊左側導航欄“Connection->SSH”,出現如圖9的界麵。選擇“Preferred SSH protocol version”為“2”。
圖9 Stelnet客戶端配置界麵(2)
# 單擊左側導航欄“Connection->SSH”下麵的“Auth”(認證),出現如圖10的界麵。單擊<Browse…>按鈕,彈出文件選擇窗口。選擇與配置到服務器端的公鑰對應的私鑰文件private.ppk。
圖10 Stelnet客戶端配置界麵(3)
# 單擊<Open>按鈕。彈出“PuTTY Security Alert”對話框。
圖11 Stelnet客戶端登錄界麵(一)
# 單擊“是(Y)”按鈕,按提示輸入用戶名client001,即可進入Device的配置界麵,用戶角色為network-admin。
login as: client001
Authenticating with public key ”rsa-key-20140726”
******************************************************************************
* Copyright (c) 2004-2018 New H3C Technologies Co., Ltd. All rights reserved.*
* Without the owner's prior written consent, *
* no decompiling or reverse-engineering shall be allowed. *
******************************************************************************
<Device>
#
vlan 2
#
interface Vlan-interface2
ip address 192.168.1.40 255.255.255.0
#
interface Ten-GigabitEthernet1/0/2
port link-mode bridge
port access vlan 2
#
line vty 0 63
authentication-mode scheme
#
ssh server enable
ssh user client001 service-type stelnet authentication-type publickey assign publickey devicekey
#
local-user client001 class manage
service-type ssh
authorization-attribute user-role network-operator
authorization-attribute user-role network-admin
#
public-key peer Devicekey
public-key-code begin
30819D300D06092A864886F70D010101050003818B0030818702818100A2DBC1FD76A837BEF5D322598442D6753B2E8F7ADD6D6209C80843B206B309078AFE2416CB4FAD496A6627243EAD766D57AEA70B901B4B4566D9A651B133BAE34E9B9F04E542D64D0E9814D7E3CBCDBCAF28FF21EE4EADAE6DF52001944A40414DFF280FF043B14838288BE7F9438DC71ABBC2C28BF78F34ADF3D1C912579A19020125
public-key-code end
peer-public-key end
#
local-user ftp
password cipher $c$3$sg9WgqO1w8vnAv2FKGTOYgFJm3nn2w==
authorization-attribute work-directory flash:/
authorization-attribute user-role network-operator
service-type ftp
#
ftp server enable
#
如圖12所示,Device A作為Stelnet客戶端,采用SSH協議遠程登錄到Device B上。要求:
· Device B采用本地認證的方式認證用戶,Stelnet服務器采用的認證方式為password認證。
· 登錄用戶名為client001,密碼為aabbcc,用戶登錄設備後可以正常使用所有命令。
· 為提高安全性,需要以Stelnet客戶端保存的主機公鑰來驗證Stelnet服務器,Stelnet客戶端隻信任通過驗證的Stelnet服務器並繼續訪問該服務器。
圖12 設備作為Stelnet客戶端配置組網圖
· 為了使SSH的版本協商和算法協商過程正常運行,且為了保證客戶端對連接的服務器的認證正常進行,請在服務器端生成RSA、DSA或ECDSA密鑰對。
· Stelnet客戶端通過VTY用戶線訪問設備。因此,需要配置登錄用戶線的認證方式為scheme方式。
· 為了采用本地認證的方式認證用戶,需要在Stelnet服務器上創建相應的本地用戶,並在本地用戶視圖下配置密碼。
· 為了使Stelnet用戶登錄設備後能正常使用所有命令,將用戶的用戶角色設置為network-admin,缺省情況下本地用戶的用戶角色為network-operator。
· 因為需要以Stelnet客戶端保存的主機公鑰來驗證Stelnet服務器,所以需要先將Stelnet服務器主機公鑰配置在Stelnet客戶端上。
本舉例是在S6890-CMW710-R2712版本上進行配置和驗證的。
缺省情況下,S6890係列交換機的接口處於ADM(Administratively Down)狀態,請根據實際需要在對應接口視圖下使用undo shutdown命令開啟接口。
# 生成RSA密鑰對。
<DeviceB> system-view
[DeviceB] public-key local create rsa
The range of public key modulus is (512 ~ 2048).
If the key modulus is greater than 512, it will take a few minutes.
Press CTRL+C to abort.
Input the modulus length [default = 1024]:
Generating Keys...
...
Create the key pair successfully.
# 生成DSA密鑰對。
[DeviceB] public-key local create dsa
The range of public key modulus is (512 ~ 2048).
If the key modulus is greater than 512, it will take a few minutes.
Press CTRL+C to abort.
Input the modulus length [default = 1024]:
Generating Keys...
...
Create the key pair successfully.
# 生成ECDSA密鑰對。
[DeviceB] public-key local create ecdsa secp256r1
Generating Keys...
.
Create the key pair successfully.
# 使能SSH服務器功能。
[DeviceB] ssh server enable
# 創建VLAN 2,並將Ten-GigabitEthernet1/0/2加入VLAN 2。
[DeviceB] vlan 2
[DeviceB-vlan2] port ten-gigabitethernet 1/0/2
[DeviceB-vlan2] quit
# 配置VLAN接口2的IP地址,客戶端將通過該地址連接Stelnet服務器。
[DeviceB] interface vlan-interface 2
[DeviceB-Vlan-interface2] ip address 192.168.1.40 255.255.255.0
[DeviceB-Vlan-interface2] quit
# 設置Stelnet客戶端登錄用戶界麵的認證方式為scheme。
[DeviceB] line vty 0 63
[DeviceB-line-vty0-63] authentication-mode scheme
[DeviceB-line-vty0-63] quit
# 創建本地用戶client001,並設置密碼為明文aabbcc,服務類型為SSH,用戶角色為network-admin。
[DeviceB]local-user client001 class manage
New local user added.
[DeviceB-luser-manage-client001] password simple aabbcc
[DeviceB-luser-manage-client001]service-type ssh
[DeviceB-luser-manage-client001] authorization-attribute user-role network-admin
[DeviceB-luser-manage-client001]quit
# 顯示服務器端DSA公鑰內容。
[DeviceB] display public-key local dsa public
=====================================================
Key name: dsakey (default)
Key type: DSA
Time when key pair created: 11:02:10 2016/07/07
Key code:
308201B73082012C06072A8648CE3804013082011F02818100D757262C4584C44C211F18BD
96E5F061C4F0A423F7FE6B6B85B34CEF72CE14A0D3A5222FE08CECE65BE6C265854889DC1E
DBD13EC8B274DA9F75BA26CCB987723602787E922BA84421F22C3C89CB9B06FD60FE01941D
DD77FE6B12893DA76EEBC1D128D97F0678D7722B5341C8506F358214B16A2FAC4B36895038
7811C7DA33021500C773218C737EC8EE993B4F2DED30F48EDACE915F0281810082269009E1
4EC474BAF2932E69D3B1F18517AD9594184CCDFCEAE96EC4D5EF93133E84B47093C52B20CD
35D02492B3959EC6499625BC4FA5082E22C5B374E16DD00132CE71B020217091AC717B6123
91C76C1FB2E88317C1BD8171D41ECB83E210C03CC9B32E810561C21621C73D6DAAC028F4B1
585DA7F42519718CC9B09EEF03818400028180077F06B3E343CAE9988F4BE3F76FACBAB565
AB73D4BA295C52BA92428B1F2DA1E6DD652413DD3AFE0C5A4FCF365100CBE34CECA55A2C30
A2A9FF7E899628557E39CE8FC615F53193A7E200B4B1CB21E3F1091D595716D229DDED6872
061F9B4B08301ADC81F7EC1501FFB863C0009536596CCB508596C3325892DC6D8C5C35B5
# 創建VLAN 2,並將Ten-GigabitEthernet1/0/2加入VLAN 2。
<DeviceA> system-view
[DeviceA] vlan 2
[DeviceA-vlan2] port ten-gigabitethernet 1/0/2
[DeviceA-vlan2] quit
# 配置VLAN接口2的IP地址。
[DeviceA] interface vlan-interface 2
[DeviceA-Vlan-interface2] ip address 192.168.1.56 255.255.255.0
[DeviceA-Vlan-interface2] quit
# 指定服務器端的主機公鑰名稱為key1,並進入公鑰視圖。
[DeviceA] public-key peer key1
Enter public key view. Return to system view with "peer-public-key end" command.
# 在客戶端配置服務器端的主機公鑰(由於客戶端缺省采用DSA主機公鑰認證服務器,因此這裏輸入的是在在服務器端通過display public-key local dsa public命令顯示公鑰內容。)
# 退出公鑰視圖,並保存用戶輸入的公鑰。
[DeviceA-pkey-public-key-key1] peer-public-key end
[DeviceA] return
# 建立到服務器192.168.1.40的SSH連接,並指定服務器端的主機公鑰key1。輸入正確的用戶名和密碼之後,即可成功登錄到Device B上,用戶角色為network-admin。
<DeviceA> ssh2 192.168.1.40 publickey key1
login as: client001
[email protected]'s password:
******************************************************************************
* Copyright (c) 2004-2018 New H3C Technologies Co., Ltd. All rights reserved.*
* Without the owner's prior written consent, *
* no decompiling or reverse-engineering shall be allowed. *
******************************************************************************
<DeviceB>
· DeviceA
#
vlan 2
#
interface Vlan-interface2
ip address 192.168.1.56 255.255.255.0
#
interface Ten-GigabitEthernet1/0/2
port link-mode bridge
port access vlan 2
#
public-key peer key1
public-key-code begin
308201B73082012C06072A8648CE3804013082011F02818100D757262C4584C44C211F18BD
96E5F061C4F0A423F7FE6B6B85B34CEF72CE14A0D3A5222FE08CECE65BE6C265854889DC1E
DBD13EC8B274DA9F75BA26CCB987723602787E922BA84421F22C3C89CB9B06FD60FE01941D
DD77FE6B12893DA76EEBC1D128D97F0678D7722B5341C8506F358214B16A2FAC4B36895038
7811C7DA33021500C773218C737EC8EE993B4F2DED30F48EDACE915F0281810082269009E1
4EC474BAF2932E69D3B1F18517AD9594184CCDFCEAE96EC4D5EF93133E84B47093C52B20CD
35D02492B3959EC6499625BC4FA5082E22C5B374E16DD00132CE71B020217091AC717B6123
91C76C1FB2E88317C1BD8171D41ECB83E210C03CC9B32E810561C21621C73D6DAAC028F4B1
585DA7F42519718CC9B09EEF03818400028180077F06B3E343CAE9988F4BE3F76FACBAB565
AB73D4BA295C52BA92428B1F2DA1E6DD652413DD3AFE0C5A4FCF365100CBE34CECA55A2C30
A2A9FF7E899628557E39CE8FC615F53193A7E200B4B1CB21E3F1091D595716D229DDED6872
061F9B4B08301ADC81F7EC1501FFB863C0009536596CCB508596C3325892DC6D8C5C35B5
public-key-code end
peer-public-key end
#
· DeviceB
#
vlan 2
#
interface Vlan-interface2
ip address 192.168.1.40 255.255.255.0
#
interface Ten-GigabitEthernet1/0/2
port link-mode bridge
port access vlan 2
#
line vty 0 63
authentication-mode scheme
#
ssh server enable
#
local-user client001
password cipher $c$3$o71Exx1XIKs9gJoxqSodHGl1uT9rlZEd4w==
authorization-attribute user-role network-operator
authorization-attribute user-role network-admin
service-type ssh
#
如圖13所示,Device A和Device B之間建立SSH連接,Device A作為SFTP客戶端登錄到Device B,進行文件管理和文件傳送等操作。要求:
· 為了保證高安全性和認證強度,要求Device B通過password-publickey認證方式對客戶端進行認證,公鑰算法為RSA。
· 登錄用戶名為client001,密碼為aabbcc,用戶登錄設備後可以正常使用所有命令。
· 服務器端通過從公鑰文件中導入的方式來配置客戶端的公鑰。
圖13 設備作為SFTP客戶端配置組網圖
· 為了采用本地認證認證用戶,需在本地SFTP服務器DeviceB上創建相應的本地用戶,並在本地用戶視圖下配置密碼。
· 服務器在采用publickey方式驗證客戶端身份時,首先要比較客戶端發送的SSH用戶名、主機公鑰是否與本地配置的SSH用戶名以及相應的客戶端主機公鑰一致,在確認用戶名和客戶端主機公鑰正確後,再對客戶端發送的數字簽名進行驗證,而該簽名是客戶端利用主機公鑰對應的私鑰計算出的。因此,需要在服務器端配置客戶端的RSA主機公鑰,並在客戶端為該SSH用戶指定與主機公鑰對應的RSA主機私鑰(在向服務器發起連接時通過identity-key關鍵字指定公鑰算法來實現)。
· 如果SSH服務器采用publickey方式認證客戶端,必須在SFTP服務器上創建相應的SSH用戶,以及同名的本地用戶(用於下發授權屬性:工作目錄、用戶角色)。
· 在服務器的配置過程中需要指定客戶端的公鑰信息,因此需要首先完成客戶端密鑰對的配置,再進行服務器的配置。
· 因為SFTP用戶登錄設備後要能正常使用所有命令,所以將用戶的用戶角色設置為network-admin,缺省情況下本地用戶的用戶角色為network-operator。
本舉例是在S6890-CMW710-R2712版本上進行配置和驗證的。
· FIPS模式下,設備作為SSH服務器不支持publickey認證方式。
· 雖然一個客戶端隻會采用RSA、DSA或ECDSA公鑰算法中的一種來認證服務器,但是由於不同客戶端支持的公鑰算法不同,為了確保客戶端能夠成功登錄服務器,建議在服務器上同時生成RSA、DSA和ECDSA密鑰對。
· 缺省情況下,S6890係列交換機的接口處於ADM(Administratively Down)狀態,請根據實際需要在對應接口視圖下使用undo shutdown命令開啟接口。
# 創建VLAN 2,並將Ten-GigabitEthernet1/0/2加入VLAN 2。
<DeviceA> system-view
[DeviceA] vlan 2
[DeviceA-vlan2] port ten-gigabitethernet 1/0/2
[DeviceA-vlan2] quit
# 配置VLAN接口2的IP地址。
[DeviceA] interface vlan-interface 2
[DeviceA-Vlan-interface2] ip address 192.168.0.2 255.255.255.0
[DeviceA-Vlan-interface2] quit
# 生成RSA密鑰對。
[DeviceA] public-key local create rsa
The range of public key modulus is (512 ~ 2048).
If the key modulus is greater than 512, it will take a few minutes.
Press CTRL+C to abort.
Input the modulus length [default = 1024]:
Generating Keys...
...
Create the key pair successfully.
# 將生成的RSA主機公鑰導出到指定文件key.pub中。
[DeviceA] public-key local export rsa ssh2 key.pub
[DeviceA] quit
# 創建VLAN 2,並將Ten-GigabitEthernet1/0/2加入VLAN 2。
<DeviceB> system-view
[DeviceB] vlan 2
[DeviceB-vlan2] port ten-gigabitethernet 1/0/2
[DeviceB-vlan2] quit
# 配置VLAN接口2的IP地址。
[DeviceB] interface vlan-interface 2
[DeviceB-Vlan-interface2] ip address 192.168.0.1 255.255.255.0
[DeviceB-Vlan-interface2] quit
# 在Device上創建一個ftp類型的本地用戶,並設置密碼為明文ftp,服務類型為FTP,用戶角色為network-admin,工作目錄為flash:/。
[DeviceB] local-user ftp class manage
New local user added.
[DeviceB-luser-manage-ftp] password simple ftp
[DeviceB-luser-manage-ftp] authorization-attribute user-role network-admin
[DeviceB-luser-manage-ftp] authorization-attribute work-directory flash:/
[DeviceB-luser-manage-ftp] service-type ftp
[DeviceB-luser-manage-ftp] quit
# 開啟Device 的FTP服務器功能。
[DeviceB] ftp server enable
[DeviceB] quit
# DeviceA通過FTP登錄並上傳flash:/路徑下的公鑰文件key.pub到Device。
<DeviceA>ftp 192.168.0.1
Press CTRL+C to abort.
Connected to 192.168.0.1 (192.168.0.1).
220 FTP service ready.
User (192.168.0.2:(none)): ftp
331 Password required for ftp.
Password:
230 User logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> put flash:/key.pub
227 Entering Passive Mode (192,168,0,1,41,116)
150 Accepted data connection
226 File successfully transferred
301 bytes sent in 0.000 seconds (1.05 Mbytes/s)
ftp> quit
221-Goodbye. You uploaded 1 and downloaded 0 kbytes.
221 Logout.
# 生成RSA密鑰對。
<DeviceB> system-view
[DeviceB] public-key local create rsa
The range of public key modulus is (512 ~ 2048).
If the key modulus is greater than 512, it will take a few minutes.
Press CTRL+C to abort.
Input the modulus length [default = 1024]:
Generating Keys...
...
Create the key pair successfully.
# 生成DSA密鑰對。
[DeviceB] public-key local create dsa
The range of public key modulus is (512 ~ 2048).
If the key modulus is greater than 512, it will take a few minutes.
Press CTRL+C to abort.
Input the modulus length [default = 1024]:
Generating Keys...
...
Create the key pair successfully.
# 生成ECDSA密鑰對。
[DeviceB] public-key local create ecdsa secp256r1
Generating Keys...
.
Create the key pair successfully.
# 啟動SFTP服務器。
[DeviceB] sftp server enable
# 從文件key.pub中導入遠端的公鑰,並命名為devicekey。
[DeviceB] public-key peer devicekey import sshkey key.pub
# 設置SSH用戶client001的服務類型為SFTP,認證方式為password-publickey,並指定公鑰為devicekey。
[DeviceB] ssh user client001 service-type sftp authentication-type password-publickey assign publickey devicekey
# 創建設備管理類本地用戶client001,並設置密碼為明文aabbcc,服務類型為SSH,用戶角色為network-admin,工作目錄為flash:/。
[DeviceB] local-user client001 class manage
New local user added.
[DeviceB-luser-manage-client001] password simple aabbcc
[DeviceB-luser-manage-client001] service-type ssh
[DeviceB-luser-manage-client001] authorization-attribute user-role network-admin work-directory flash:/
[DeviceB-luser-manage-client001] quit
# 與遠程SFTP服務器建立連接。
<DeviceA >sftp 192.168.0.1 identity-key rsa
Username: client001
Press CTRL+C to abort.
Connecting to 192.168.0.1 port 22.
The server is not authenticated. Continue? [Y/N]:y
Do you want to save the server public key? [Y/N]:n
[email protected]'s password:
# 輸入用戶密碼aabbcc後進入SFTP客戶端視圖。
sftp>
# 顯示服務器的當前目錄,刪除文件z,並檢查此文件是否刪除成功。
sftp> dir -l
-rwxrwxrwx 1 1 1 1759 Aug 23 06:52 config.cfg
-rw-rw---- 1 1 1 301 Aug 7 16:52 key.pub
-rwxrwxrwx 1 1 1 0 Sep 01 06:22 new
-rwxrwxrwx 1 1 1 225 Sep 01 06:55 pub
-rwxrwxrwx 1 1 1 225 Aug 24 08:01 pubkey2
-rwxrwxrwx 1 1 1 0 Sep 01 08:00 z
sftp> delete z
Removing /z
sftp> dir -l
-rwxrwxrwx 1 1 1 1759 Aug 23 06:52 config.cfg
-rw-rw---- 1 1 1 301 Aug 7 16:52 key.pub
-rwxrwxrwx 1 1 1 0 Sep 01 06:22 new
-rwxrwxrwx 1 1 1 225 Sep 01 06:55 pub
-rwxrwxrwx 1 1 1 225 Aug 24 08:01 pubkey2
# 新增目錄new1,並檢查新目錄是否創建成功。
sftp> mkdir new1
sftp> dir -l
-rwxrwxrwx 1 1 1 1759 Aug 23 06:52 config.cfg
-rw-rw---- 1 1 1 301 Aug 7 16:52 key.pub
-rwxrwxrwx 1 1 1 0 Sep 01 06:22 new
drwxrwxrwx 1 1 1 0 Sep 02 06:30 new1
-rwxrwxrwx 1 1 1 225 Sep 01 06:55 pub
-rwxrwxrwx 1 1 1 225 Aug 24 08:01 pubkey2
# 將目錄名new1更名為new2,並查看是否更名成功。
sftp> rename new1 new2
sftp> dir -l
-rwxrwxrwx 1 1 1 1759 Aug 23 06:52 config.cfg
-rw-rw---- 1 1 1 301 Aug 7 16:52 key.pub
-rwxrwxrwx 1 1 1 0 Sep 01 06:22 new
drwxrwxrwx 1 1 1 0 Sep 02 06:33 new2
-rwxrwxrwx 1 1 1 225 Sep 01 06:55 pub
-rwxrwxrwx 1 1 1 225 Aug 24 08:01 pubkey2
# 從服務器上下載文件pubkey2到本地,並更名為public。
sftp> get pubkey2 public
Fetching /pubkey2 to public
/public 100% 301 0.3KB/s 00:00
# 將本地文件public上傳到服務器上,並查看上傳是否成功。
sftp> put public
Uploading public to /public
public 100% 301 0.3KB/s 00:00
sftp> dir -l
-rwxrwxrwx 1 1 1 1759 Aug 23 06:52 config.cfg
-rw-rw---- 1 1 1 301 Aug 7 16:52 key.pub
-rwxrwxrwx 1 1 1 0 Sep 01 06:22 new
drwxrwxrwx 1 1 1 0 Sep 02 06:33 new2
-rwxrwxrwx 1 1 1 225 Sep 01 06:55 pub
-rwxrwxrwx 1 1 1 225 Aug 24 08:01 pubkey2
-rwxrwxrwx 1 1 1 301 Jul 30 16:21 public
sftp>
# 退出SFTP客戶端視圖。
sftp> quit
<DeviceA>
· DeviceA
#
vlan 2
#
interface Vlan-interface2
ip address 192.168.0.2 255.255.255.0
#
interface Ten-GigabitEthernet1/0/2
port link-mode bridge
port access vlan 2
#
· DeviceB
#
vlan 2
#
interface Vlan-interface2
ip address 192.168.0.1 255.255.255.0
#
interface Ten-GigabitEthernet1/0/2
port link-mode bridge
port access vlan 2
#
sftp server enable
ssh user client001 service-type sftp authentication-type password-publickey assign publickey devicekey
#
local-user client001 class manage
service-type ssh
password cipher $c$3$o71Exx1XIKs9gJoxqSodHGl1uT9rlZEd4w==
authorization-attribute user-role network-operator
authorization-attribute user-role network-admin
#
#
local-user ftp class manage
password simple ftp
service-type ftp
authorization-attribute user-role network-admin
authorization-attribute user-role network-operator
#
public-key peer devicekey
public-key-code begin
30819F300D06092A864886F70D010101050003818D00308189
1BD316C0DBB9009503E78F31947B651F9950E9A6E9E256E1E
public-key-code end
peer-public-key end
#
如圖14所示,Device A作為SCP客戶端,Device B作為SCP服務器。要求:
· 采用password認證方式對SCP客戶端進行遠程認證,用戶能夠通過Device A安全地登錄到Device B上。
· 采用RADIUS服務器對登錄Device B的SCP用戶Device A進行認證和授權,登錄用戶名為hello@bbb,密碼為aabbcc,Device A登錄Device B後可以正常使用所有命令;
· Device B向RADIUS服務器發送的用戶名帶域名。
圖14 SCP文件傳輸配置組網圖
· 為了使SSH的版本協商和算法協商過程正常運行,且為了保證客戶端對連接的服務器的認證正常進行,請在服務器端生成RSA、DSA或ECDSA密鑰對。
· 采用RADIUS服務器對登錄Device B的SCP用戶Device A進行認證,需要在RADIUS服務器上添加用戶名和密碼。
· 為保證RADIUS客戶端和RADIUS服務器之間信息交互的安全性,且為了防止用戶密碼在不安全的網絡上傳遞時被竊取,需要在Device B和RADIUS服務器上設置相同的共享密鑰。
· 為了使Device A登錄Device B後可以正常使用所有命令,在RADIUS服務器上設置用戶角色為network-admin。
· 為了實現通過RADIUS來進行認證和授權,需要在Device B上配置RADIUS方案指定相應的認證和授權服務器,並配置認證SSH用戶的ISP域。
本舉例是在S6890-CMW710-R2712版本上進行配置和驗證的。
缺省情況下,S6890係列交換機的接口處於ADM(Administratively Down)狀態,請根據實際需要在對應接口視圖下使用undo shutdown命令開啟接口。
本文以iMC為例(使用iMC版本為:iMC PLAT 7.0(E0102)、iMC EIA 7.0(E0201)),說明該例中RADIUS服務器的基本配置。
# 登錄進入iMC管理平台,選擇“用戶”頁簽,單擊導航樹中的[接入策略管理/接入設備管理/接入設備配置]菜單項,進入接入設備配置頁麵,在該頁麵中單擊“增加”按鈕,進入增加接入設備頁麵。
· 設置認證及計費的端口號分別為“1812”(RADIUS服務器的認證端口為UDP端口1812)和“1813”(RADIUS服務器的計費端口為UDP端口1813);
· 選擇業務類型為“設備管理業務”;
· 選擇接入設備類型為“H3C(General)”;
· 設置與Device交互報文時使用的認證和授權共享密鑰為“expert”;
· 選擇或手工增加接入設備,添加IP地址為10.1.1.2的接入設備;
· 其它參數采用缺省值,並單擊<確定>按鈕完成操作。
圖15 增加接入設備
# 選擇“用戶”頁簽,單擊導航樹中的[接入用戶管理視圖/設備管理用戶]菜單項,進入設備管理用戶列表頁麵,在該頁麵中單擊<增加>按鈕,進入增加設備管理用戶頁麵。
· 輸入用戶名“hello@bbb”和密碼“aabbcc”。
· 選擇服務類型為“SSH”。
· 輸入用戶角色名“network-admin”
· 添加所管理設備的IP地址,IP地址範圍為“10.1.1.0~10.1.1.255”。
· 單擊<確定>按鈕完成操作。
圖16 增加設備管理用戶
# 生成RSA密鑰對。
[DeviceB] public-key local create rsa
The range of public key modulus is (512 ~ 2048).
If the key modulus is greater than 512, it will take a few minutes.
Press CTRL+C to abort.
Input the modulus length [default = 1024]:
Generating Keys...
...
Create the key pair successfully.
# 生成DSA密鑰對。
[DeviceB] public-key local create dsa
The range of public key modulus is (512 ~ 2048).
If the key modulus is greater than 512, it will take a few minutes.
Press CTRL+C to abort.
Input the modulus length [default = 1024]:
Generating Keys...
...
Create the key pair successfully.
# 生成ECDSA密鑰對。
[DeviceB] public-key local create ecdsa secp256r1
Generating Keys...
.
Create the key pair successfully.
# 創建VLAN 2,並將Ten-GigabitEthernet1/0/2加入VLAN 2。
[DeviceB] vlan 2
[DeviceB-vlan2] port ten-gigabitethernet 1/0/2
[DeviceB-vlan2] quit
# 配置接口VLAN接口2的IP地址,SCP客戶端將通過該地址連接SCP服務器。
[DeviceB] interface vlan-interface 2
[DeviceB-Vlan-interface2] ip address 192.168.0.1 255.255.255.0
[DeviceB-Vlan-interface2] quit
# 創建VLAN 3,並將Ten-GigabitEthernet1/0/3加入VLAN 3。
[DeviceB] vlan 3
[DeviceB-vlan3] port ten-gigabitethernet 1/0/3
[DeviceB-vlan3] quit
# 配置VLAN接口3的IP地址,RADIUS客戶端通過該地址連接RADIUS服務器。
[DeviceB] interface vlan-interface 3
[DeviceB-Vlan-interface3] ip address 10.1.1.2 255.255.255.0
[DeviceB-Vlan-interface3] quit
# 使能SCP服務器功能。
# 創建RADIUS方案rad。
[DeviceB] radius scheme rad
# 配置主認證服務器的IP地址為10.1.1.1,認證端口號為1812。
[DeviceB-radius-rad] primary authentication 10.1.1.1 1812
# 配置主計費服務器的IP地址為10.1.1.1,計費端口號為1813。
[DeviceB-radius-rad] primary accounting 10.1.1.1 1813
# 配置與認證和計費服務器交互報文時的共享密鑰為明文expert。
[DeviceB-radius-rad] key authentication simple expert
[DeviceB-radius-rad] key accounting simple expert
# 配置向RADIUS服務器發送的用戶名要攜帶域名。
[DeviceB-radius-rad] user-name-format with-domain
[DeviceB-radius-rad] quit
# 創建ISP域bbb,為login用戶配置AAA認證方法為RADIUS認證、授權和計費。
[DeviceB] domain bbb
[DeviceB-isp-bbb] authentication login radius-scheme rad
[DeviceB-isp-bbb] authorization login radius-scheme rad
[DeviceB-isp-bbb] accounting login radius-scheme rad
[DeviceB-isp-bbb] quit
# 創建VLAN 2,並將Ten-GigabitEthernet1/0/2加入VLAN 2。
<DeviceA> system-view
[DeviceA] vlan 2
[DeviceA-vlan2] port ten-gigabitethernet 1/0/2
[DeviceA-vlan2] quit
# 配置接口VLAN 2的IP地址。
[DeviceA] interface vlan-interface 2
[DeviceA-Vlan-interface2] ip address 192.168.0.2 255.255.255.0
[DeviceA-Vlan-interface2] quit
[DeviceA] quit
# 與遠程SCP服務器建立連接,並下載遠端的remote.bin文件,下載到本地後更名為local.bin。
<DeviceA> scp 192.168.0.1 get remote.bin local.bin
Username: hello@bbb
Press CTRL+C to abort.
Connecting to 192.168.0.1 port 22.
The Server is not authenticated. Continue? [Y/N]:y
Do you want to save the server public key? [Y/N]:n
hello@[email protected]'s password:
remote.bin 100% 8275KB 318.3KB/s 00:26.
· DeviceA
#
vlan 2
#
interface Vlan-interface2
ip address 192.168.0.2 255.255.255.0
#
interface Ten-GigabitEthernet1/0/2
port link-mode bridge
port access vlan 2
#
· DeviceB
#
vlan 2 to 3
#
interface Vlan-interface2
ip address 192.168.0.1 255.255.255.0
#
interface Vlan-interface3
ip address 10.1.1.2 255.255.255.0
#
interface Ten-GigabitEthernet1/0/2
port link-mode bridge
port access vlan 2
#
interface Ten-GigabitEthernet1/0/3
port link-mode bridge
port access vlan 3
#
ssh server enable
#
radius scheme rad
primary authentication 10.1.1.1
primary accounting 10.1.1.1
key authentication cipher $c$3$63G7LzIQElGq4aFGTiYQafU+loQxS/cbLg==
key accounting cipher $c$3$tUIVlyGISJ5X/yiTFWrmh8nyjBIF+1LFzQ==
#
domain bbb
authentication login radius-scheme rad
authorization login radius-scheme rad
accounting login radius-scheme rad
#
· H3C S6890係列交換機 基礎配置指導(R27xx)
· H3C S6890係列交換機 基礎配置命令參考(R27xx)
不同款型規格的資料略有差異, 詳細信息請向具體銷售和400谘詢。H3C保留在沒有任何通知或提示的情況下對資料內容進行修改的權利!