This section describes how to configure the FW as an SFTP server and how to download files from the FW through SFTP on a PC.
Networking Requirements
As shown in Figure 1, a PC is used to log in to the FW and download files from the FW through SFTP.
Figure 1 Networking diagram for logging in to the FW through SFTP (RSA authentication)
Data Planning
Item
|
Data
|
FW
|
SFTP administrator account: sftpadmin_a
Authentication type: RSA
Bound client public key: key_pc
Service type: SFTP
|
Administrator PC
|
SSH client software: PuTTY software (Windows 7 operating system). The PuTTY software contains the PuTTY client for the STelnet service, the SFTP client PSFTP, and key generation tool PuTTYgen.
Name of the public key in the local RSA key pair: public
Name of the private key in the local RSA key pair: private
SSH connection: ssh-rsa
|
Procedure
- Generate an RSA public key on the PC.
- Install the PuTTY software. Details are omitted.
- Use the PuTTYgen tool to generate a local RSA key pair (the following uses PuTTYgen0.60 as an example).
- Double-click PuTTYgen.exe. The interface shown in Figure 2 is displayed. In Parameters, set Type of key to generate to SSH-2 RSA. Click Generate. The PC starts to generate a local RSA key pair.
Figure 2 Selecting the SSH version for generating the local RSA key pair
- Figure 3 shows the interface for generating a local RSA key pair. You must move the mouse continuously during the generation of the local RSA key pair. Move the pointer only in the window other than the progress bar in green. Otherwise, the progress bar suspends, and the generation of the key pair stops.
Figure 3 Generating a local RSA key pair
- Figure 4 shows the generation of the local RSA key pair. Do as follows to save the RSA key pair in the specified format:
- OpenSSH: Copy the marked content in the Key text box.
- PEM: Click Save public key, enter public for the name of the public key file, and click Save. Click Save private key, enter private for the name of the private key file, and click Save.
To enhance security, you must enter a password in the Key passphrase text box and enter the password again in the Confirm passphrase text box to set a password for using this key pair.
Figure 4 Saving a local RSA key pair
- Configure the FW.
- Set an IP address for interface GigabitEthernet 0/0/3 and assign the interface to a security zone.
<FW> system-view
[FW] interface GigabitEthernet 0/0/3
[FW-GigabitEthernet0/0/3] ip address 10.3.0.1 24
[FW-GigabitEthernet0/0/3] service-manage enable
[FW-GigabitEthernet0/0/3] service-manage ssh permit
[FW-GigabitEthernet0/0/3] quit
[FW] firewall zone trust
[FW-zone-trust] add interface GigabitEthernet 0/0/3
[FW-zone-trust] quit
- Configure a security policy for the Local-Trust interzone to permit the SSH service.
[FW] security-policy
[FW-policy-security] rule name policy_sftp
[FW-policy-security-rule-policy_sftp] service ssh
[FW-policy-security-rule-policy_sftp] source-zone trust
[FW-policy-security-rule-policy_sftp] destination-zone local
[FW-policy-security-rule-policy_sftp] source-address 10.3.1.0 24
[FW-policy-security-rule-policy_sftp] action permit
[FW-policy-security-rule-policy_sftp] quit
[FW-policy-security] quit
- Enable the SFTP service.
[FW] sftp server enable
- Generate a local key pair.
[FW] rsa local-key-pair create
The key name will be: FW_Host
The range of public key size is (2048 ~ 2048).
NOTES: If the key modulus is greater than 512,
it will take a few minutes.
Input the bits in the modulus[default = 2048]:2048
Generating keys...
.+++++
........................++
....++++
...........++
- Save the RSA public key of the intranet PC. In this example, the RSA public key is saved in the OpenSSH coding format.
[FW] rsa peer-public-key key_pc encoding-type openssh
Enter "RSA public key" view, return system view with "peer-public-key end".
[FW-rsa-public-key] public-key-code begin
Enter "RSA key code" view, return last view with "public-key-code end".
[FW-rsa-key-code] ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIBwsFDGbVAbK35ecJqsioQ3BdTCa1+eU3i13YQBHvBltIdI9bOMKYEYJbjuY4UYXkdtwA2ar6LWTI8X1hHbtYGqPk2MvjSF0hXn1DBabNUXbLRyzWAhaopcsTbGboU88cQ6fe/DqE9jUpNLsPdg4EXz1LMyLNe134JCSe3Ufh7o/w== rsa-key-20140515
[FW-rsa-key-code] public-key-code end
[FW-rsa-public-key] peer-public-key end
- Configure the VTY UI.
[FW] user-interface vty 0 4
[FW-ui-vty0-4] authentication-mode aaa
[FW-ui-vty0-4] user privilege level 3
[FW-ui-vty0-4] protocol inbound all
[FW-ui-vty0-4] quit
- Create an SFTP administrator account and specify an authentication mode and a service type.
# Create SFTP administrator account sftpadmin_a and set the authentication mode to RSA, service type to SFTP, and service directory to hda1:.
[FW] aaa
[FW-aaa] manager-user sftpadmin_a
[FW-aaa-manager-user-sftpadmin_a] level 3
[FW-aaa-manager-user-sftpadmin_a] service-type ssh
[FW-aaa-manager-user-sftpadmin_a] quit
[FW-aaa] quit
- Set the authentication mode to RSA.
[FW] ssh user sftpadmin_a authentication-type rsa
- Bind an RSA public key to the SFTP account.
[FW] ssh user sftpadmin_a assign rsa-key key_pc
- Configure command-specific authorization for an SSH user.
[FW] ssh user sftpadmin_a authorization-cmd aaa
- Set the service type to SFTP for the SSH account.
[FW] ssh user sftpadmin_a service-type sftp
- Configure an SFTP service authorization directory for the SSH user.
[FW] ssh user sftpadmin_a sftp-directory hda1:
- Configure the administrator PC.
- Set the IP address and subnet mask of the administrator PC to 10.3.1.100/255.255.255.0.
- Install the PuTTY software. Details are omitted.
- Use the PuTTY to log in to the FW through SFTP (the following uses PuTTY0.60 as an example).
- Double-click PuTTY.exe. The interface shown in Figure 5 is displayed. Enter the IP address of the SSH server in the Host Name (or IP address) text box.
Figure 5 Entering the IP address of the SSH server
- Choose in the left Category navigation tree. The interface shown in Figure 6 is displayed. In the Protocol options area, set Preferred SSH protocol version to 2.
Figure 6 Setting the SSH protocol version
- Select Auth in SSH. The dialog box shown in Figure 7 is displayed. Click Browse, import the private key file private.ppk in the saved RSA key pair.
Figure 7 Importing the private key in the RSA key pair
- Click Session, enter ssh-rsa in the Saved Sessions text box, and click Save to save the SSH session, as shown in Figure 8.
Figure 8 Importing the private key in the RSA key pair
- Double-click PSFPT.exe, enter open ssh-rsa and press Enter (ssh-rsa is the name of the saved PyTTY session), and then enter SSH administrator account sshadmin_b and press Enter. You can access the file directory on FW, as shown in Figure 9.
Figure 9 SFTP login page
- Download files from the FW.
Figure 10 Downloading files from the FW
Configuration Scripts
#
sysname FW
#
rsa peer-public-key key_pc encoding-type openssh
public-key-code begin
ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIBwsFDGbVAbK35ecJqsioQ3BdTCa1+eU3i13YQBHvBltI
dI
9bOMKYEYJbjuY4UYXkdtwA2ar6LWTI8X1hHbtYGqPk2MvjSF0hXn1DBabNUXbLRyzWAhaopcsTbGbo
U8
8cQ6fe/DqE9jUpNLsPdg4EXz1LMyLNe134JCSe3Ufh7o/w== rsa-key
public-key-code end
peer-public-key end
#
aaa
manager-user sftpadmin_a
service-type ssh
level 3
#
interface GigabitEthernet0/0/3
ip address 10.3.0.1 255.255.255.0
service-manage enable
service-manage ssh permit
#
firewall zone trust
set priority 85
add interface GigabitEthernet0/0/3
#
sftp server enable
ssh user sftpadmin_a
ssh user sftpadmin_a authentication-type rsa
ssh user sftpadmin_a assign rsa-key key_pc
ssh user sftpadmin_a service-type sftp
ssh user sftpadmin_a sftp-directory hda1:
ssh user sftpadmin_a authorization-cmd aaa
#
user-interface vty 0 4
authentication-mode aaa
user privilege level 3
protocol inbound all
#
security-policy
rule name policy_sftp
source-zone trust
destination-zone local
service ssh
source-address 10.3.1.0 24
action permit