Redhat/Centos7下指定ssh+ftp用户限制在特定目录下

好了,废话不多说。上头下来个需求,开个ftp+ssh账户,只能访问项目的目录,不能访问项目外的目录,就算cd切换目录也不行。

第一步 关闭selinux,防止ftp报500错误

vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
 SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

第二步 安装ftp,我用的是centos7,只需敲入命令

yum install vsftpd -y

chkconfig vsftpd on  #设置开机启动

systemctl stop firewalld   ###顺便关下防火墙

配置vsftp.conf

先备份好配置  cp vsftpd.conf vsftpd.conf_bak,然后修改下面3行代码,将注释去掉

 

为了防止报错,在文末加一行

allow_writeable_chroot=YES

然后再新建chroot_list文件,并添加需管控用户

 第三步 用户配置

创建目录(我这里用/home/data)

mkdir /home/data   ###创建目录

useradd -d /home/data -M admin   ##-d 目录 指定用户主目录,如果此目录不存在,则同时使用-M选项,不要自动建立用户的登入目录

Changing password for user admin.
New password: 
BAD PASSWORD: The password contains the user name in some form
Retype new password: 
passwd: all authentication tokens updated successfully.

chown -R admin:root /home/data

##chown  -R ftp用户名:root    项目目录


systemctl restart vsftpd
systemctl restart ssh

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

知名“矿工”

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值