1)CentOS release 6.5 (Final)
2)本例采用YUM安装,需要先配置好YUM源
3)为了实验的顺利,这里关闭防火墙和selinux
二、安装部署
1)配置vsftpd
[root@linuxidc ~]# yum install -y vsftpdLoaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-24.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================
Package Arch Version Repository Size
===============================================================================================
Installing:
vsftpd x86_64 2.2.2-24.el6 base 156 k
Transaction Summary
===============================================================================================
Install 1 Package(s)
Total download size: 156 k
Installed size: 340 k
Downloading Packages:
vsftpd-2.2.2-24.el6.x86_64.rpm | 156 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : vsftpd-2.2.2-24.el6.x86_64 1/1
Verifying : vsftpd-2.2.2-24.el6.x86_64 1/1
Installed:
vsftpd.x86_64 0:2.2.2-24.el6
Complete!
[root@linuxidc ~]# cd /etc/vsftpd/
[root@linuxidc vsftpd]# cp vsftpd.conf vsftpd.conf-bak
[root@linuxidc vsftpd]# vim vsftpd.conf
修改如下内容:
anonymous_enable=YES --->anonymous_enable=NO
#chroot_list_enable=YES ---> chroot_list_enable=YES
#chroot_list_file=/etc/vsftpd/chroot_list ---> chroot_list_file=/etc/vsftpd/chroot_list
假定我们需要登录的用户为linuxidc,需要上传下载的目录为/data
[root@linuxidc vsftpd]# mkdir /data
[root@linuxidc vsftpd]# useradd -d /data linuxidc
useradd: warning: the home directory already exists. #此报错提示可以忽略,因为上面已经新建了linuxidc的家目录
Not copying any file from skel directory into it.
[root@linuxidc vsftpd]# chsh -s /sbin/nologin linuxidc
Changing shell for linuxidc.
Shell changed.
[root@linuxidc data]# echo RedHat |passwd --stdin linuxidc
Changing password for user linuxidc.
passwd: all authentication tokens updated successfully.
[root@linuxidc vsftpd]# cat /etc/passwd
linuxidc:x:500:500::/data:/sbin/nologin
[root@linuxidc vsftpd]# vim /etc/vsftpd/chroot_list
linuxidc #保存
[root@linuxidc vsftpd]# service vsftpd restart
Shutting down vsftpd: [FAILED]
Starting vsftpd for vsftpd: [ OK ]
三、测试
[root@linuxidc vsftpd]# cd /data/
[root@linuxidc data]# touch aa bb cc
[root@linuxidc data]# service vsftpd restart
此时我们可以正常从ftp服务器上面下载文件,但是上传文件会有如下报错:
解决方法:
[root@linuxidc data]# ll -d /data
drwxr-xr-x. 2 root root 4096 Nov 10 14:24 /data #该目录权限是属于root用户,root组
修改目录权限如下
[root@linuxidc data]# chown linuxidc:root /data
[root@linuxidc data]# service vsftpd restart
再次测试,已经可以正常上传到/data目录下文件了,至此vsftpd服务器搭建完成。(同样适用于CentOS 7.x)