zoukankan      html  css  js  c++  java
  • 开启远程 SFTP 连接服务

    开启远程 SFTP 连接服务:

    1、创建用户组 sftp
    groupadd sftp

    2、创建用户 xinxin02
    useradd -G sftp -s /sbin/nologin xinxin02

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

    3、创建密码
    passwd xinxin02

    4、修改配置文件 sshd_config
    vim /etc/ssh/sshd_config

    将下面这行注释
    # Subsystem sftp /usr/libexec/openssh/sftp-server

    然后在末行加入:

    Subsystem sftp internal-sftp
    Match Group sftp
    ChrootDirectory /home/xinxin02
    X11Forwarding no
    AllowTcpForwarding no
    #ChrootDirectory %h
    ForceCommand internal-sftp

    systemctl restart sshd

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

    5、设置目录权限
    chown root:sftp /home/xinxin02
    chgrp -R sftp /home/xinxin02
    chmod -R 755 /home/xinxin02

    # 设置用户可以上传的目录, 该用户下允许用户上传删除修改文件及文件夹
    mkdir /home/xinxin02/prod
    mkdir /home/xinxin02/test

    chown -R xinxin02:sftp /home/xinxin02/prod
    chown -R xinxin02:sftp /home/xinxin02/test
    chmod -R 755 /home/xinxin02/prod
    chmod -R 755 /home/xinxin02/test


    6、解决报错问题
    修改 /etc/selinux/config 中SELINUX 为 disabled

    7、使用sftp客户端连接服务器
    使用第三方客户端连接sftp服务器, 或者使用Python中的paramiko模块连接

    linux下测试:
    sftp -P 66992 xinxin02@10.10.11.11
    ls
    cd ..
    put /root/test.txt
    rm test.txt
    ?
    bye

    多用户,多目录的权限配置:

    vi /etc/ssh/sshd_config

    Subsystem sftp internal-sftp
    Match User test01
    ChrootDirectory /home/test01
    X11Forwarding no
    AllowTcpForwarding no
    #ChrootDirectory %h
    ForceCommand internal-sftp

    #Subsystem sftp internal-sftp
    Match User test02
    ChrootDirectory /home/test02
    PasswordAuthentication yes


    #X11Forwarding no
    #AllowTcpForwarding no
    #ChrootDirectory %h
    #ForceCommand internal-sftp

    systemctl restart sshd

    测试:

    sftp  test01@1.1.1.1

    sftp  test02@1.1.1.1

  • 相关阅读:
    为了你,我一定要写诗
    哈佛成功金句25则(看一遍,都会很有收获!)
    成功者的十三个“百万元习惯”
    商业领袖的7大人脉宝典
    我为你疯狂
    秋收,为何我收获的只有泪水
    又逢中秋月
    今宵谁与共
    26句话,让你豁然开朗
    田彩蝶(帮别人名字作诗)
  • 原文地址:https://www.cnblogs.com/walkersss/p/13927086.html
Copyright © 2011-2022 走看看