CentOS 7 创建 sftp 帐号

1)创建用户 tomsftp 及其 home 目录 /home/tomsftp/,并设置用户密码,

$ su -
# useradd -d /home/tomsftp/ -s /sbin/nologin tomsftp
# passwd tomsftp

 

2) 编辑 /etc/ssh/sshd_config,文件末尾修订如下,

# override default of no subsystems
#Subsystem    sftp    /usr/libexec/openssh/sftp-server
Subsystem    sftp    internal-sftp

# Example of overriding settings on a per-user basis
#Match User anoncvs
#            X11Forwarding no
#            AllowTcpForwarding no
#            PermitTTY no
#            ForceCommand cvs server
Match User tomsftp
            X11Forwarding no
            AllowTcpForwarding no
            PermitTTY no
            ForceCommand internal-sftp

注意,使用 internal-sftp 带来两个好处:

(1)性能更好,在连接 sftp 的时候,系统不会 fork 出一个新的 sftp 进程;可使用 ps ax | grep sftp 命令查看 sftp 进程。

(2)可以在 ssh 的配置文件 /etc/ssh/sshd_config 中,使用 ChrootDirectory,Match,ForceCommand 等指令来限制登录 sftp 用户的行为。

 

3) 重启服务,

$ sudo systemctl restart sshd.service

4) 本地测试,

$ sftp -oPort=设置的ssh服务的port(默认22)  tomsftp@计算机名 
例如,
$ sftp -oPort=14920 tomsftp@burninsrv

 

参考网友博客: https://www.maixj.net/ict/ssh-sftp-21993

 

(完)

 

posted @ 2021-04-16 14:37  Anonymous596  阅读(413)  评论(0编辑  收藏  举报