Use SFTP to Upload and Download CFS File System Data
This guide explains how to use SFTP to upload and download data on the CFS file system.
Prerequisites
In the region where the CFS file system is located, you have already purchased a Baidu Cloud Compute (BCC) instance (this guide uses the CentOS operating system as an example). For details, please refer to [Creating a BCC Instance](BCC/Operation guide/Instance/Create instance/Create Instance via Purchase Page.md).
Background
The speed of SFTP transfers depends on the Internet bandwidth of the BCC. Please configure the network bandwidth appropriately based on your business needs.
Operation steps
- Sign in to Baidu Cloud Compute (BCC)
-
Modify the configuration file /etc/ssh/sshd_config
-
Comment out the Subsystem line in the sshd_config file, and add a new line: Subsystem sftp internal-sftp
Plain Text1# override default of no subsystems 2#Subsystem sftp /usr/libexec/openssh/sftp-server 3Subsystem sftp internal-sftp -
Add the following content at the end of the sshd_config file. Here, /usr/sftp is the SFTP root directory; modify it according to your actual situation
Plain Text1X11Forwarding no 2AllowTcpForwarding no 3ForceCommand internal-sftp 4ChrootDirectory /usr/sftp
-
-
Set relevant permissions
-
3.1 Execute the following command to add a user group.
Plain Text1groupadd sftp -
3.2 Execute the following command to add a user and set it as an SFTP group.
Plain Text1useradd -g sftp -s /sbin/nologin -M sftp -
3.3 Execute the following command to set the password for the SFTP user.
Plain Text1passwd sftp -
3.4 Create the root directory, owner, and group for the SFTP user, and modify the permissions (set to 755).
Plain Text1 cd /usr 2 mkdir sftp 3 chown root:sftp sftp 4 chmod 755 sftp
-
- Create a CFS mount directory in the SFTP directory and modify permissions
1cd sftp/
2mkdir mnt
3chown sftp:sftp mnt
- Execute the following command to mount the CFS file system to the
/usr/sftp/mntdirectory
1mount -t nfs4 -o minorversion=1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport cfs-q2BPKzxxxx.lb-5179xxxx.cfs.bj.baidubce.com:/ /usr/sftp/mnt
- Execute the following command to restart the sshd service
1service sshd restart
- Sign in to the SFTP service to upload and download files
The account and password mentioned are the ones configured in Step 3. This guide uses the Cyberduck client as an example, but you can choose any client supporting the SFTP protocol based on your requirements.

