Centos7 builds sftp service

 Create sftp transfer file location, add sftp group


mkdir -p /data/sftp               ##sftp的数据目录

chmod 755 -R /data/sftp           ##给ftp用户进入目录

chown root:root -R /data/sftp     ##需要使用chroot

groupadd sftp                     ##配置sftp群组

useradd -d /data/sftp/test -m -g sftp -s /sbin/nologin test ##创建用户并加入sftp组,指定家目录和不允许正常登录

echo '123456' | passwd --stdin test ##为test用户设置密码123456自行修改

 Modify sshd configuration

Remember: If you still want to use ssh connection, then the following configuration ForceCommand internal-sftp can not be written, if you do not need to establish remote ssh, then it is recommended to comment. If you forget where the ssh needs are, you can come back and read this sentence.       

vi /etc/ssh/sshd_config

#Subsystem  sftp  /usr/libexec/openssh/sftp-server #这行注释掉
GSSAPIAuthentication no #更改为no
UseDNS no #更改为no
X11Forwarding no #更改为no

#直接在文件最后面复制进去-> 添加
Subsystem sftp internal-sftp      ##sftp服务使用ssh服务提供的
ForceCommand internal-sftp        ##如果ssh 登录不了,请注释它
Match Group sftp                  ##匹配sftp组
ChrootDirectory  /data/sftp/%u    ##限制用户在自己家目录

Restart the sshd service after modification 

systemctl  restart sshd

 User Directory Authorization

mkdir /data/sftp/test/upload  -p
chown root:root /data/sftp/test
chmod 755 /data/sftp/test
chown test:sftp /data/sftp/test/upload -R  #只允许自己操作upload目录

CMD transmission test

First enter cmd and enter the command to connect to sftp

sftp 用户名@ip  #用户名替换为你创建的用户的用户名,例如我上面是test

 Prompt you to enter the password, just enter it normally, in hidden code form, for example, my above password is 123456, press Enter after entering

The connection is successful as follows:

upload

put 对应文件路径 /upload

download

get /upload/文件 #执行完毕后你cmd所在目录会拉取到这个文件

 Note: If you want to pull to the specified file directory here, you can cd to the directory you want in advance.

Guess you like

Origin blog.csdn.net/weixin_44285713/article/details/131212238