Service building
CentOS comes with SSH service, you can configure it directly
SFTP configuration
1. Create user group sftp
groupadd sftp
2. Create a user
useradd -g sftp -s /sbin/nologin -d /home/sftp/ftpuser1 ftpuser1
-g join the sftp group
-s prohibit login
-d specifies the user's login directory
3. Set password
passwd ftpuser1
4. Create user ftp file directory
mkdir /home/sftp/ftpuser1
5. Modify folder owner
chown -R ftpuser1:sftp /home/sftp/ftpuser1
6. Modify the ssh configuration file
Modify sshd_config as follows:
Annotate the original Subsystem settings
#Subsystem sftp /usr/libexec/openssh/sftp-server
Enable internal-sftp
Subsystem sftp internal-sftp
Restrict user SFTP access to the root directory
Restrict the root directory of the ftpuser1 user
Match User ftpuser
ChrootDirectory /home/sftp
ForceCommand internal-sftp
7. Restart the SSH service
systemctl restart sshd
Precautions:
There are two main points in the permissions setting of the directory
The directory owner from the directory specified by ChrootDirectory up to the system root can only be root
The directory specified by ChrootDirectory cannot go up to the system root directory until the system root directory.
Modify file permissions
You can modify the directory's access permissions using code similar to the following:
chmod -R 544 /home/sftp/ftpuser1