SFTP 搭建

groupadd sftp
cat /etc/group    --验证sftp  用户验证成功
useradd -g sftp -s /sbin/nologin test
passwd test       --设定用户密码

vim /etc/ssh/sshd_config 

修改配置

PasswordAuthentication yes

注释配置
# Subsystem sftp /usr/libexec/openssh/sftp-server

新增以下配置放在最后一行
Subsystem sftp internal-sftp
Match Group sftp
ChrootDirectory /data1/sftp/%u
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no

 

mkdir -p /data1/sftp/test
usermod -d /data1/sftp/test   test    --绑定用户根目录
chown root:sftp /data1/sftp/test
chmod 755 /data1/sftp/test
mkdir /data1/sftp/test/upload          --设定sftp 用户子目录
chown test:sftp /data1/sftp/test/upload      --修正属组
chmod 755 /data1/sftp/test/upload            --修正权限

 

 /usr/sbin/sshd -T        -- 检查之前修正的sshd_config 文件是否正确,无异常在重启

service sshd restart     --重启SSH

sftp  test@localhost    --登录验证(输入之前设定的test 用户的密码)

posted @ 2022-05-10 15:39  沧海一粟1996  阅读(226)  评论(0)    收藏  举报