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

  • 相关阅读:
    java 单元测试 No tests were found 和 org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
    Cesium 各种坐标转换
    windows express + https ssl 证书申请
    layui数据表格跨行自动合并
    mui中的遍历each()
    点击按钮,回到页面顶部的5种写法
    html中a标签中实现点击事件
    @-webkit-keyframes 动画 css3
    在手机上调试H5页面
    SQL Server 按某一字段分组取最大(小)值所在行的数据
  • 原文地址:https://www.cnblogs.com/walkersss/p/13927086.html
Copyright © 2011-2022 走看看