[root@server pub]# vim /etc/vsftpd/vsftpd.conf # Uncomment this if you want the anonymous FTP user to be able to create # new directories. anon_mkdir_write_enable=YES anon_other_write_enable=YES //在这里添加一条信息 [root@server pub]# systemctl restart vsftpd
[root@server ~]# useradd user1 [root@server ~]# useradd user2 [root@server ~]# useradd user3 [root@server ~]# for i in user{1..3} > do echo redhat | passwd --stdin $i > done Changing password for user user1. passwd: all authentication tokens updated successfully. Changing password for user user2. passwd: all authentication tokens updated successfully. Changing password for user user3. passwd: all authentication tokens updated successfully.
[root@server ~]# vim /etc/vsftpd/vsftpd.conf //FTP服务器端 # the user does not have write access to the top level directory within the # chroot) chroot_local_user=YES //将#删除,禁止所有用户离开自己的家目录 [root@server ~]# systemctl restart vsftpd
[root@client ~]# lftp 192.168.100.111 //client客户端 lftp 192.168.100.111:~> user user1 Password: lftp user1@192.168.100.111:~> cd .. cd `..' [Sending commands...] Interrupt lftp user1@192.168.100.111:~> ls //此时ls命令不能用了 Interrupt //inside chroot()从2.3.5之后,vsftpd增强了安全检查, 如果用户被限定在了其主目录下,则该用户的主目录不能再具有写权限了! 如果检查发现还有写权限,就会报该错误
//解决方法: [root@server ~]# vim /etc/vsftpd/vsftpd.conf # Make sure, that one of the listen options is commented !! listen_ipv6=YES
[root@server ~]# vim /etc/vsftpd/vsftpd.conf # the user does not have write access to the top level directory within the # chroot) #chroot_local_user=YES //这里加#注释掉 chroot_list_enable=YES //这里将#删除 # (default follows) chroot_list_file=/etc/vsftpd/chroot_list //这里将#删除 [root@server ~]# cd /etc/vsftpd/ [root@server vsftpd]# ls //这里面没有chroot_list文件 ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh [root@server vsftpd]# vim chroot_list 创建并写入 //在里面写入 user1 user2 [root@server vsftpd]# !sys systemctl restart vsftpd
lftp user1@192.168.100.111:/> cd .. lftp user1@192.168.100.111:/> ls //user1只能在自己的家目录 -rw-r--r-- 1 0 0 0 Jul 23 13:07 file123 lftp user1@192.168.100.111:/> user user2 Password: lftp user2@192.168.100.111:/> cd .. lftp user2@192.168.100.111:/> ls //user2也只能在家目录 Interrupt //这里是因为user2家目录里没有任何文件 lftp user2@192.168.100.111:/> user user3 Password: lftp user3@192.168.100.111:~> cd / //user3就能离开自己的家目录 cd ok, cwd=/ lftp user3@192.168.100.111:/> ls dr-xr-xr-x 2 0 0 6 May 16 2022 afs lrwxrwxrwx 1 0 0 7 May 16 2022 bin -> usr/bin dr-xr-xr-x 5 0 0 4096 Jul 10 11:29 boot drwxr-xr-x 19 0 0 3260 Jul 23 07:53 dev drwxr-xr-x 78 0 0 8192 Jul 23 12:41 etc drwxr-xr-x 6 0 0 55 Jul 23 12:40 home lrwxrwxrwx 1 0 0 7 May 16 2022 lib -> usr/lib lrwxrwxrwx 1 0 0 9 May 16 2022 lib64 -> usr/lib64 drwxr-xr-x 2 0 0 6 May 16 2022 media drwxr-xr-x 2 0 0 6 May 16 2022 mnt drwxr-xr-x 2 0 0 6 May 16 2022 opt dr-xr-xr-x 201 0 0 0 Jul 23 07:53 proc dr-xr-x--- 3 0 0 179 Jul 23 13:14 root drwxr-xr-x 22 0 0 640 Jul 23 07:53 run lrwxrwxrwx 1 0 0 8 May 16 2022 sbin -> usr/sbin drwxr-xr-x 2 0 0 6 May 16 2022 srv dr-xr-xr-x 13 0 0 0 Jul 23 07:53 sys drwxrwxrwt 4 0 0 175 Jul 23 13:09 tmp drwxr-xr-x 12 0 0 144 Jul 10 11:27 usr drwxr-xr-x 19 0 0 4096 Jul 10 11:31 var lftp user3@192.168.100.111:/>