二、为每个虚拟用户定制权限
- 实现:magedu 可上传文件 marion 只有访问权限
- user_config_dir 指令 可以实现让我们指定一个目录,在这个目录中为每一个用户创建一个同名的配置文件,用于定义这个用户在访问目录的
- 时候自己所独有的权限
- #cd /etc/vsftpd
- #mkdir virusers //创建一个目录,而后为用户建立对应的文件
- #cd virusers
- #vim magedu
- 添加
- anon_upload_enable=YES
- anon_mkdir_write_enable=NO
- anon_other_write_enable=NO 有上传权限没有删除权限
- #vim marion
- 添加
- anon_upload_enable=NO
- anon_mkdir_write_enable=NO
- anon_other_write_enable=NO
- 编辑 /etc/vsftpd/vsftpd.conf
- 添加
- user_config_dir=/etc/vsftpd/virusers
- 测试:
- #ftp localhost
- Name (localhost:root): magedu
- 331 Please specify the password.
- Password:
- 230 Login successful.
- Remote system type is UNIX.
- Using binary mode to transfer files.
- ftp> put inittab
- local: inittab remote: inittab
- 227 Entering Passive Mode (127,0,0,1,250,166)
- 150 Ok to send data.
- 226 File receive OK.
- 1666 bytes sent in 0.017 seconds (98 Kbytes/s) //上传成功
- ftp> ls
- 227 Entering Passive Mode (127,0,0,1,46,110)
- 150 Here comes the directory listing.
- -rw------- 1 503 503 608 Aug 04 10:22 fstab
- -rw------- 1 503 503 1666 Aug 04 10:55 inittab
- 226 Directory send OK.
- ftp> get fstab
- local: fstab remote: fstab
- 227 Entering Passive Mode (127,0,0,1,223,8)
- 550 Failed to open file. //不可以下载
- ftp> bye
- 同样方法测试mrion用户
- 不可以删除、上传
三、系统用户和虚拟用户同时可以访问 useradd -r -M gentoo
- #useradd -r gentoo
- #passwd gentoo
- RedHat //密码为redhat
- #ftp localhost //用gentoo登陆 失败
- # tail -1 /var/log/secure
- Aug 4 19:08:20 station11 vsftpd: pam_MySQL - SELECT returned no result.
- //到mysql中去找了,当然找不到了 系统用户用的是/etc/pam.d/vsftpd 虚拟用户用的是/etc/pam.d/vsftpd.my 将两个文件整合都一起
- #vim /etc/vsftpd/vsftpd
- 将内容改为如下形式,将/etc/pam.d/vsftpd.my中的内容添加到此文件中
- #session optional pam_keyinit.so force revoke
- auth sufficient /lib/security/pam_mysql.so user=vsftpd passwd=123456 host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2
- auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
- auth required pam_shells.so
- auth include system-auth
- account sufficient /lib/security/pam_mysql.so user=vsftpd passwd=123456 host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2
- account include system-auth
- session include system-auth
- session required pam_loginuid.so
- 而后编辑配置文件/etc/vsftpd/vsftpd.conf
- 将pam_service_name=vsftpd.my 改为 pam_service_name=vsftpd
- 重启服务
- #service vsftpd restart
- 测试:
- [root@sut20 ~]# ftp localhost
- Connected to localhost.localdomain.
- 220 (vsFTPd 2.0.5)
- 530 Please login with USER and PASS.
- 530 Please login with USER and PASS.
- KERBEROS_V4 rejected as an authentication type
- Name (localhost:root): magedu //虚拟用户登陆
- 331 Please specify the password.
- Password:
- 230 Login successful.
- Remote system type is UNIX.
- Using binary mode to transfer files.
- ftp> ls
- 227 Entering Passive Mode (127,0,0,1,239,100)
- 150 Here comes the directory listing.
- -rw------- 1 503 503 608 Aug 04 10:22 fstab
- -rw------- 1 503 503 1666 Aug 04 10:55 inittab
- 226 Directory send OK.
- [root@sut20 ~]# ftp localhost
- Connected to localhost.localdomain.
- 220 (vsFTPd 2.0.5)
- 530 Please login with USER and PASS.
- 530 Please login with USER and PASS.
- KERBEROS_V4 rejected as an authentication type
- Name (localhost:root): gentoo //系统用户登陆
- 331 Please specify the password.
- Password:
- 230 Login successful.
- Remote system type is UNIX.
- Using binary mode to transfer files.
- ftp> ls
- 227 Entering Passive Mode (127,0,0,1,239,100)
- 150 Here comes the directory listing.
- -rw------- 1 503 503 608 Aug 04 10:22 fstab
- -rw------- 1 503 503 1666 Aug 04 10:55 inittab
- 226 Directory send OK.
四、FTP服务器的访问控制
例如:禁止vsftp为172.16.100.200访问
- #vim /etc/hosts.deny
- 添加
- vsftpd: ALL EXCEPT 172.16. EXCEPT 172.16.100.150
- 测试机地址为172.16.100.150
- ftp 172.16.20.1
- 421 Service not available
- User <172.16.20.1:<none>>; //访问失败
综上:实现了基于mysql数据库架设FTP服务器的相关配置
