需求:

1.建立三个sftp帐号,admin,test1,test2
2.三个帐号分别在/home/sftp下拥有相应的目录
3.test1和test2只能进入自己的目录,admin可以进入三个目录(chown,chmod和ACL)
4.各自目录所有者和所有者组权限继承
5.test1和test2进入自己目录后可以进行读写操作,但是不能删除;admin进入三个目录都可以进行读写和删除操作(删除权限可以使用chattr +a或者设置sticky bit,但是并不能完全满足需求)

首先要升级OpenSSH的版本。只有4.8p1及以上版本才支持Chroot
1.查验openssh版本
[root@localhost ~]# ssh -V
OpenSSH_6.6.1p1, OpenSSL 1.0.1e-fips 11 Feb 2013

2.建立相应目录
[root@localhost ~]# mkdir /home/sftp
[root@localhost ~]# mkdir /home/sftp/admin
[root@localhost ~]# mkdir /home/sftp/test1
[root@localhost ~]# mkdir /home/sftp/test2

3.创建帐号和组,同时修改密码
[root@localhost ~]# groupadd sftp
[root@localhost ~]# useradd -d /home/sftp/test1 -M -s /sbin/false test1
[root@localhost ~]# useradd -d /home/sftp/test2 -M -s /sbin/nologin test2
[root@localhost ~]# useradd -d /home/sftp/admin -M -s /sbin/nologin -g sftp admin
[root@localhost ~]# usermod -a -G sftp test1
[root@localhost ~]# usermod -a -G sftp test2
[root@localhost ~]# passwd admin
[root@localhost ~]# passwd test1
[root@localhost ~]# passwd test2

-d是把用户目录限制的自定义的目录,-M是不自动创建用户目录,-s是进行登录shell指定(/bin/false和sbin/nologin的区别暂不得知)

4.修改配置文件,同时重启ssh服务让其生效
[root@localhost ~]# vim /etc/ssh/sshd_config
Subsystem sftp internal-sftp
Match User admin,test1,test2
ChrootDirectory /home/sftp
AllowTcpForwarding no
X11Forwarding no
ForceCommand internal-sftp
[root@localhost ~]# systemctl reload sshd.service

5.设置/home/sftp的权限
[root@localhost ~]# chown root:root /home/sftp
[root@localhost ~]# chmod 755 /home/sftp

6.为三个文件夹设置所有者和组,已经设置权限(使得admin可以访问三个文件夹,test1和test2只能访问各自文件夹)
[root@localhost ~]# chown admin:sftp /home/sftp/test1
[root@localhost ~]# chown admin:sftp /home/sftp/test2
[root@localhost ~]# chown admin:sftp /home/sftp/admin
[root@localhost ~]# chmod 770 /home/sftp/test1
[root@localhost ~]# chmod 770 /home/sftp/test2
[root@localhost ~]# chmod 700 /home/sftp/admin

7.可以通过ACL限制权限(test2不能访问test1的文件夹,test1不能访问test2的文件夹)
[root@localhost ~]#setfacl -m u:test2:- /home/sftp/test1
[root@localhost ~]#setfacl -m u:test1:- /home/sftp/test2

8.关于删除权限,不使用脚本的情况下,有以下两种方案,但是仍无法完全满足需求
第一种方案(chattr +a)
chattr +a 文件夹名:只能增加数据,而不能删除
chattr +i 文件夹名:不能被删除、改名、设定连结也无法写入或新增数据

第二种方案(chmod o+t)
chmod o+t 文件夹名:添加sticky-bit,使得这个文件只可以由超级管理员,该目录的所有者,该文件的所有者删除

9.如果需要实现admin可以对三个文件夹进行删除操作,test1和test2不能删除的话,需要使用脚本

a.首先设置文件可执行
chmod a+x test1.sh
chmod a+x test1.sh

b.然后分别设置脚本文件如下
test1.sh
#!/bin/sh
while inotifywait -e create /home/sftp/test1;do
chown -R admin:sftp /home/sftp/test1
chmod -R 1770 /home/sftp/test1
done

test2.sh
#!/bin/sh
while inotifywait -e create /home/sftp/test2;do
chown -R admin:sftp /home/sftp/test2
chmod -R 1770 /home/sftp/test2
done

c.后台运行shell同时忽略shell退出
nohup ./test1.sh &
nohup ./test2.sh &

10.使用inotify的方式,有个很致命的缺陷,无法监控子目录的任何操作,所以后面进行修改为如下脚本(定时执行chmod和chown)

#!/bin/sh
while [ true ]; do
sleep 1
chown -R admin:sftp /home/sftp/test1
chmod -R 1770 /home/sftp/test1
chown -R admin:sftp /home/sftp/test2
chmod -R 1770 /home/sftp/test2
done

centos v7.0配置sftp的更多相关文章

  1. Linux(CentOS)上配置 SFTP(附解决Write failed: Broken pipe Couldn't read packet: Connection reset by peer)

    #创建sftp组: groupadd sftp #创建一个用户sftpuser: useradd -g sftp -s /bin/false sftpuser #提示: /etc/group 文件包含 ...

  2. centos v7.0解决乱码

    [root@localhost ~]# ll 鎬荤敤閲4-rw-------. 1 root root 1045 8鏈 24 21:17 anaconda-ks.cfg [root@localhost ...

  3. CentOS 7.0 配置防火墙

    停用了 iptables. systemctl stop iptables.service 然后来启动 firewalld 吧 systemctl start firewalld.service 给我 ...

  4. CentOS 7 配置SFTP

    目前越来越多的FTP客户端软件开始支持SSH协议上传和下载文件,这种协议方式就是SFTP. SFTP的优势主要有两点,一是不需要再配置个FTP服务端:二是SSH协议是安全传输,上传和下载是经过加密的. ...

  5. asp.net core 简单部署之FTP配置(CentOS 7.0安装配置Vsftp服务器)

    配置过程原文地址:http://www.osyunwei.com/archives/9006.html 坑和结果 正确的跟着这个内容走,是靠谱的. 我自己给自己踩了个坑,请参照文章的朋友注意第七条:七 ...

  6. CentOS 7.0系统安装配置步骤详解

    CentOS 7.0系统是一个很新的版本哦,很多朋友都不知道CentOS 7.0系统是怎么去安装配置的哦,因为centos7.0与以前版本是有很大的改进哦. 说明: 截止目前CentOS 7.x最新版 ...

  7. CentOS 7.0安装配置Vsftp服务器

    一.配置防火墙,开启FTP服务器需要的端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...

  8. CentOS 7.0 安装配置LAMP服务器方法(Apache+PHP+MariaDB)

    一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: #停止firewall服务 sys ...

  9. CentOS 7.0下配置MariaDB数据库

    刚刚配置了下CentOS 7.0版本的服务器,配置数据库时发现# mysql_secure_installation命令用不了,之后网上查了一下发现CentOS 7.0版本用MariaDB替换了mys ...

随机推荐

  1. python3之selenium.webdriver 库练习自动化谷歌浏览器打开百度自动百度关键字

    import os,time,threading from selenium import webdriver from selenium.webdriver.common.keys import K ...

  2. python算数、逻辑运算,位运算

    算术运算符 对变量和数组进行算术运算. 算术运算符:+,-,*,/,% +:将连个或者多个数值相加 -:将两个数值相减 *:将两个数值相乘 /:将两个数值相除 %:取相除的余数 赋值运算符 将右边的值 ...

  3. python中list.sort()与sorted()的区别

    list.sort()和sorted()都是python的内置函数,他们都用来对序列进行排序,区别在于 list.sort()是对列表就地(in-place)排序,返回None:sorted()返回排 ...

  4. DataGridView增加右键取消操作

    ) { dgvinfo.Rows[e.RowIndex].Selected = true; Point point = dgvinfo.PointToClient(Cursor.Position); ...

  5. mysql自动化审核工具Yearning

    mysql自动化审核工具Yearning cd /opt/wget https://github-production-release-asset-2e65be.s3.amazonaws.com/10 ...

  6. Qt之去除窗口的标题栏、通过鼠标移动窗口

    设置标题栏图标,位置与大小示例 #include<QApplication> #include<QWidget> #include<QDebug> #include ...

  7. sublime text 编辑器的操作

    我一直在用的代码编辑器是sublime text,然后总结了一些相关的操作方法. 一 环境操作 1.放大显示比例:Ctrl+ 2.缩小显示比例:Ctrl- 3.分屏:Alt+ Shift +数字    ...

  8. 计算机网络(十),HTTP的关键问题

    目录 1.在浏览器地址栏键入URL,按下回车之后经历的流程 2.HTTP状态码 3.GET请求和POST请求的区别 4.Cookie和Session的区别 5.IPV4和IPV6 十.HTTP的关键问 ...

  9. UVa 1595 Symmetry (set && math)

    题意:给出n个在直角坐标系上的点,问你能不能找出一条竖轴(即垂直于x的轴)使得所有的点根据这条轴对称,能则输出YES,否则输出NO 分析:首先需要找到对称轴的值,将所有n个点的x轴的值加起来然后去除以 ...

  10. A. Even Substrings

    A. Even Substrings time limit per test 0.5 seconds memory limit per test 256 megabytes input standar ...