好了,废话不多说。上头下来个需求,开个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