Service configuration under Linux sftp

View version openssh using ssh -V command to see openssh version, the version must be greater than 4.8p1, lower than this version needs to be upgraded.

1. Create a user group sftp

groupadd sftp

2, create a user ftp

useradd -g sftp -s /sbin/nologin -M yanqi
passwd yanqi

3. Create a home directory and specify yanqi

Note: Change directory to the home owner and the owner's home directory authorization must be root, permissions can be 755 or 750

mkdir /opt/data -p
usermod -d /opt/data yanqi

chown root:root /opt/data
chmod 755 /opt/data

4. Create a writable directory

mkdir /opt/data/file -p
chown yanqi:sftp /opt/data/file

5, edit the configuration file / etc / ssh / sshd_config

Comment out X11Forwarding yes this sentence, probably in the 101 line 
commented out SFTP the Subsystem / usr / libexec / OpenSSH / sftp- Server words, about 132 line 

and add the following sentence at the end of the file: 
the Subsystem SFTP Internal - SFTP 
Match the User Yanqi 
the ChrootDirectory / opt / Data 
ForceCommand     Internal - SFTP 
AllowTcpForwarding NO 
X11Forwarding NO 

systemctl the restart the sshd

6. Verify

 

Note: You can only delete files to / opt / data under / file directory, upload and delete.

Guess you like

Origin www.cnblogs.com/huangyanqi/p/11304257.html