zoukankan      html  css  js  c++  java
  • Centos 7 设置 SFTP

    近期要给服务器设置一个SFTP用户,可以上传删除修改的SFTP,但是禁止该用户SSH登录。这里记录下来

    先升级


    yum update

    fox.风

    创建用户组 sftp

    用户组名为sftp

    groupadd sftp

    创建用户 test

    例如这个用户名为 test

    useradd -G sftp -s /sbin/nologin test 

    -s 禁止用户ssh登陆 
    -G 加入sftp 用户组

    创建密码

    passwd test 

    修改配置文件sshd_config

    vim /etc/ssh/sshd_config

    修改为如下

    ....
    ##下面这行注释掉
    #Subsystem sftp /usr/libexec/openssh/sftp-server
    ##后面加入
    Subsystem sftp internal-sftp
    #注意,以下要 放在 本文件的最后行,否则 root用户无法登陆
    Match Group sftp
    X11Forwarding no
    AllowTcpForwarding no
    ChrootDirectory %h                      
    ForceCommand internal-sftp

    说明 
    Match Group sftp 匹配sftp用户组中的用户 
    ChrootDirectory %h 只能访问默认的用户目录(自己的目录),例如 /home/test

    设置目录权限

    chown root:sftp /home/test
    chgrp -R sftp /home/test
    chmod -R 755 /home/test
    #设置用户可以上传的目录,改目录下允许用户上传删除修改文件及文件夹
    mkdir /home/test/upload
    chown -R test:sftp /home/test/upload
    chmod -R 755 /home/test/upload

    重启ssh

    systemctl restart sshd.service

    链接

    新建一个 终端链接,或者在 FTP 客户端中使用SFTP 模式链接(输入相关的IP用户名及端口)

    sftp test@192.1.1.1

    F&Q

    如果报类似以下错误

    sftp Connection to  closed by remote host.
    或者
    Write failed: Broken pipe 
    Couldn't read packet: Connection reset by peer 

  • 相关阅读:
    MyCAT常用分片规则之分片枚举
    MySQL参数
    CentOS 7下MySQL服务启动失败的解决思路
    ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    CHECK_NRPE: Received 0 bytes from daemon. Check the remote server logs for error messages.
    MyCAT实现MySQL的读写分离
    搭建Spark的单机版集群
    如何部署Icinga服务端
    MyCAT简易入门
    如何部署Icinga客户端
  • 原文地址:https://www.cnblogs.com/gz9218/p/85d25b3aeaea9b1f8455a889abedfdf2.html
Copyright © 2011-2022 走看看