1.安装vsftpd
//关闭防火墙,selinux
[root@zzg ~]# systemctl stop firewalld
[root@zzg ~]# setenforce 0
//安装ftp服务
[root@zzg ~]# rpm -qa |grep vsftpd
[root@zzg ~]# yum -y install vsftpd
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-22.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================
Package Arch Version Repository Size
===========================================================================
Installing:
vsftpd x86_64 3.0.2-22.el7 zz 169 k
Transaction Summary
===========================================================================
Install 1 Package
Total download size: 169 k
Installed size: 348 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : vsftpd-3.0.2-22.el7.x86_64 1/1
Verifying : vsftpd-3.0.2-22.el7.x86_64 1/1
Installed:
vsftpd.x86_64 0:3.0.2-22.el7
Complete!
//启动ftp服务
[root@zzg ~]# systemctl start vsftpd
[root@zzg pub]# systemctl enable vsftpd
2.配置匿名用户ftp
//配置vsftp配置文件
[root@zzg ~]# vim /etc/vsftpd/vsftpd.conf
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
anon_upload_enable=YES (去掉注释,允许匿名用户上传)
#
# 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 (加此行,允许匿名用户创建删除)
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
-- INSERT -- 34,28 10%
//重新启动服务
[root@zzg pub]# systemctl restart vsftpd
[root@zzg pub]# pwd
/var/ftp/pub
[root@zzg ftp]# chmod 777 pub/
[root@zzg ftp]# cd pub/
[root@zzg pub]# touch zzg
//验证,在客户机上
[root@zzg ~]# lftp -u ftp 192.168.220.40
Password:
lftp ftp@192.168.220.40:~> ls
drwxrwxrwx 3 0 0 17 Feb 18 08:01 pub
lftp ftp@192.168.220.40:/> cd pub/
lftp ftp@192.168.220.40:/pub> ls
drwxrwxrwx 2 0 0 6 Feb 18 08:01 zzg
lftp ftp@192.168.220.40:/pub> mirror zzg
Total: 1 directory, 0 files, 0 symlinks
lftp ftp@192.168.220.40:/pub> exit
[root@zzg ~]# ls
anaconda-ks.cfg zzg
xftp验证
初始
下载
上传
3.配置虚拟用户ftp
//创建文本格式的用户名、密码列表,例如若要添加两个用户tom、jerry,密码分别为123、456
[root@zzg ~]# cd /etc/vsftpd/
[root@zzg vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
[root@zzg vsftpd]# vim vu.list
[root@zzg vsftpd]# tail vu.list
tom
123
jerry
456
//安装db4工具
[root@zzg vsftpd]# yum -y install db4*
//将刚创建的文本格式用户名、密码文件使用db4工具转换成数据库文件
[root@zzg vsftpd]# db_load -T -t hash -f /etc/vsftpd/vu.list /etc/vsftpd/vu.db
上面的-T表示转换,-t表示加密方式使用hash算法加密
[root@zzg vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh vu.db vu.list
//为提高虚拟用户帐号文件的安全性,应将文件权限设置为600,以避免数据外泄
[root@zzg vsftpd]# chmod 600 /etc/vsftpd/vu.*
//添加虚拟用户的映射帐号、创建ftp根目录。例如要将使用的ftp根目录设置为/var/ftproot, \
映射帐号的名称为vftp,可以执行以下操作
[root@zzg vsftpd]# useradd -d /var/ftproot -s /sbin/nologin vftp
[root@zzg vsftpd]# chmod -R 755 /var/ftproot
[root@zzg vsftpd]# ll -d /var/ftproot/
drwxr-xr-x. 2 vftp vftp 62 Feb 18 01:56 /var/ftproot/
//为虚拟用户建立PAM认证
[root@zzg ~]# cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak
[root@zzg ~]# vim /etc/pam.d/vsftpd
[root@zzg ~]# tail /etc/pam.d/vsftpd
#%PAM-1.0
auth required pam_userdb.so db=/etc/vsftpd/vu
account required pam_userdb.so db=/etc/vsftpd/vu
//修改vsftpd配置文件,添加虚拟用户支持
[root@zzg ~]# vim /etc/vsftpd/vsftpd.conf
[root@zzg ~]# tail -2 /etc/vsftpd/vsftpd.conf
guest_username=vftp
guest_enable=YES (加两行)
//为不同的虚拟用户建立独立的配置文件
[root@zzg ~]# tail -2 /etc/vsftpd/vsftpd.conf
user_config_dir=/etc/vsftpd/vusers_dir
allow_writeable_chroot=YES(加两行)
//有了上述配置后,就可以在/etc/vsftpd/vusers_dir目录中为每个虚拟用户分别建立配置文件了。 \
//例如,若要使用虚拟用户tom能够上传文件、创建目录,而jerry只有默认的下载权限, \
//可以执行以下操作
[root@zzg ~]# mkdir /etc/vsftpd/vusers_dir
[root@zzg ~]# ll /etc/vsftpd/
total 36
-rw-------. 1 root root 125 Mar 23 2017 ftpusers
-rw-------. 1 root root 361 Mar 23 2017 user_list
-rw-------. 1 root root 5162 Feb 18 02:12 vsftpd.conf
-rwxr--r--. 1 root root 338 Mar 23 2017 vsftpd_conf_migrate.sh
-rw-------. 1 root root 12288 Feb 18 01:51 vu.db
-rw-------. 1 root root 19 Feb 18 01:45 vu.list
drwxr-xr-x. 2 root root 6 Feb 18 02:16 vusers_dir
//设置tom用户可上传文件、创建目录
[root@zzg ~]# cd /etc/vsftpd/vusers_dir/
[root@zzg vusers_dir]# vim tom
[root@zzg vusers_dir]# tail tom
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
[root@zzg vusers_dir]#
//设置jerry用户只有默认的下载权限,只需要创建一个名为jerry的空文件即可
[root@zzg vusers_dir]# touch jerry
//注意:虚拟用户是通过匿名访问的,所以必须开启匿名访问功能!!!
//启动服务
[root@zzg vusers_dir]# systemctl restart vsftpd
// 客户机验证
[root@zzg ~]# lftp -u tom 192.168.220.40
Password:
lftp tom@192.168.220.40:~> ls
-rw------- 1 1000 1000 0 Feb 18 07:23 zx
drwx------ 2 1000 1000 6 Feb 18 07:23 zzg
lftp tom@192.168.220.40:/> mkdir 1
mkdir ok, `1' created
lftp tom@192.168.220.40:/> ls
drwx------ 2 1000 1000 6 Feb 18 07:32 1
-rw------- 1 1000 1000 0 Feb 18 07:23 zx
drwx------ 2 1000 1000 6 Feb 18 07:23 zzg
lftp tom@192.168.220.40:/> rm -rf 1
rm ok, `1' removed
lftp tom@192.168.220.40:/> ls
-rw------- 1 1000 1000 0 Feb 18 07:23 zx
drwx------ 2 1000 1000 6 Feb 18 07:23 zzg
[root@zzg ~]# lftp -u jerry 192.168.220.40
Password:
lftp jerry@192.168.220.40:~> ls
-rw------- 1 1000 1000 0 Feb 18 07:23 zx
drwx------ 2 1000 1000 6 Feb 18 07:23 zzg
lftp jerry@192.168.220.40:/> mkdir 1
mkdir: Access failed: 550 Permission denied. (1)
lftp jerry@192.168.220.40:/>
xftp验证
用tom验证 原本为空,创建目录zzg,文件zx
用jerry验证,删除文件zx
无法删除
4.配置系统用户ftp
//恢复配置文件
[root@zzg ~]# vim /etc/vsftpd/vsftpd.conf
//创建用户zx 密码为123456
[root@zzg ~]# useradd zx
[root@zzg ~]# echo "123456" | passwd --stdin zx
客户端验证
[root@zzg ~]# lftp -u zx 192.168.220.40
Password:
lftp zx@192.168.220.40:~> ls
lftp zx@192.168.220.40:~> mkdir a
mkdir ok, `a' created
lftp zx@192.168.220.40:~> ls
drwxr-xr-x 2 1003 1003 6 Feb 18 08:44 a
lftp zx@192.168.220.40:~> rm -rf a
rm ok, `a' removed
lftp zx@192.168.220.40:~> ls
lftp zx@192.168.220.40:~> mkdir a
mkdir ok, `a' created
lftp zx@192.168.220.40:~> mirror a
Total: 1 directory, 0 files, 0 symlinks
lftp zx@192.168.220.40:~> exit
[root@zzg ~]# ls
a anaconda-ks.cfg zzg
验证
创建目录zzg
删除目录zzg