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

  • 相关阅读:
    Cocos游戏引擎,让小保安成就大梦想
    Android 高仿QQ5.2双向側滑菜单DrawerLayout实现源代码
    Java中字符串相等与大小比較
    Android四大基本组件之 Activity
    C++基础学习教程(五)
    HAWQ技术解析(八) —— 大表分区
    Jenkins 安装与使用--实例
    Android多点触控技术,实现对图片的放大缩小平移,惯性滑动等功能
    Mycat(4):消息表mysql数据库分表实践
    谋哥:《App自推广》开篇之回到远古人类
  • 原文地址:https://www.cnblogs.com/walkersss/p/13927086.html
Copyright © 2011-2022 走看看