Linux Service:FTP
这里罗列在Linux中配置FTP服务需要注意的技术细节。
在Linux中,常用的FTP服务是由vsftp软件包提供的,但这不是配置FTP服务的唯一方式,你也可以下载其他的第三方的FTP厂商的产品部署。
本文以RHEL自带的vsftp为主。
查看系统是否安装了相应的软件包:
1 2 3 |
[root@rhel510 ~]# rpm -qa | grep --color vsftp vsftpd-2.0.5-28.el5 [root@rhel510 ~]# |
如果这里没有找到软件包,那么,你需要配置好YUM,然后通过:yum install -y vsftp*,来安装。
使用YUM主要是考虑到软件包的依赖性关系,对于vsftp来说没有额外的依赖包,所以,如果你把光盘挂载到了:/iso目录上,你也可以这么安装:
命令:rpm -ivh find /iso -name "vsftp*"
Shell:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@rhel510 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 15G 2.6G 12G 19% / /dev/sda1 289M 17M 258M 7% /boot tmpfs 2.0G 0 2.0G 0% /dev/shm /dev/sdb1 40G 6.2G 32G 17% /pxe_root [root@rhel510 ~]# [root@rhel510 ~]# mount /dev/sr0 /iso mount: block device /dev/sr0 is write-protected, mounting read-only [root@rhel510 ~]# [root@rhel510 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 15G 2.6G 12G 19% / /dev/sda1 289M 17M 258M 7% /boot tmpfs 2.0G 0 2.0G 0% /dev/shm /dev/sdb1 40G 6.2G 32G 17% /pxe_root /dev/sr0 4.1G 4.1G 0 100% /iso [root@rhel510 ~]# [root@rhel510 ~]# rpm -ivh `find /iso -name "vsftp*"` warning: /iso/Server/vsftpd-2.0.5-28.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] package vsftpd-2.0.5-28.el5.x86_64 is already installed [root@rhel510 ~]# |
安装成功了之后,来看看vsftp到底装了哪些内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
[root@rhel510 ~]# rpm -ql vsftpd /etc/logrotate.d/vsftpd.log /etc/pam.d/vsftpd /etc/rc.d/init.d/vsftpd /etc/vsftpd /etc/vsftpd/ftpusers /etc/vsftpd/user_list /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd_conf_migrate.sh /usr/sbin/vsftpd /usr/share/doc/vsftpd-2.0.5 /usr/share/doc/vsftpd-2.0.5/AUDIT /usr/share/doc/vsftpd-2.0.5/BENCHMARKS /usr/share/doc/vsftpd-2.0.5/BUGS /usr/share/doc/vsftpd-2.0.5/COPYING /usr/share/doc/vsftpd-2.0.5/Changelog /usr/share/doc/vsftpd-2.0.5/EXAMPLE /usr/share/doc/vsftpd-2.0.5/EXAMPLE/INTERNET_SITE /usr/share/doc/vsftpd-2.0.5/EXAMPLE/INTERNET_SITE/README /usr/share/doc/vsftpd-2.0.5/EXAMPLE/INTERNET_SITE/vsftpd.conf /usr/share/doc/vsftpd-2.0.5/EXAMPLE/INTERNET_SITE/vsftpd.xinetd /usr/share/doc/vsftpd-2.0.5/EXAMPLE/INTERNET_SITE/vsftpd.xinetd.dir /usr/share/doc/vsftpd-2.0.5/EXAMPLE/INTERNET_SITE_NOINETD /usr/share/doc/vsftpd-2.0.5/EXAMPLE/INTERNET_SITE_NOINETD/README /usr/share/doc/vsftpd-2.0.5/EXAMPLE/INTERNET_SITE_NOINETD/README.dir /usr/share/doc/vsftpd-2.0.5/EXAMPLE/INTERNET_SITE_NOINETD/vsftpd.conf /usr/share/doc/vsftpd-2.0.5/EXAMPLE/PER_IP_CONFIG /usr/share/doc/vsftpd-2.0.5/EXAMPLE/PER_IP_CONFIG/README /usr/share/doc/vsftpd-2.0.5/EXAMPLE/PER_IP_CONFIG/README.dir /usr/share/doc/vsftpd-2.0.5/EXAMPLE/PER_IP_CONFIG/hosts.allow /usr/share/doc/vsftpd-2.0.5/EXAMPLE/PER_IP_CONFIG/hosts.allow.dir /usr/share/doc/vsftpd-2.0.5/EXAMPLE/README /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_HOSTS /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_HOSTS/README /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_USERS /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_USERS/README /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_USERS/README.dir /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_USERS/logins.txt /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_USERS/vsftpd.conf /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_USERS/vsftpd.pam /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_USERS/vsftpd.pam.dir /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_USERS_2 /usr/share/doc/vsftpd-2.0.5/EXAMPLE/VIRTUAL_USERS_2/README /usr/share/doc/vsftpd-2.0.5/FAQ /usr/share/doc/vsftpd-2.0.5/INSTALL /usr/share/doc/vsftpd-2.0.5/LICENSE /usr/share/doc/vsftpd-2.0.5/README /usr/share/doc/vsftpd-2.0.5/README.security /usr/share/doc/vsftpd-2.0.5/REWARD /usr/share/doc/vsftpd-2.0.5/SECURITY /usr/share/doc/vsftpd-2.0.5/SECURITY/DESIGN /usr/share/doc/vsftpd-2.0.5/SECURITY/IMPLEMENTATION /usr/share/doc/vsftpd-2.0.5/SECURITY/OVERVIEW /usr/share/doc/vsftpd-2.0.5/SECURITY/TRUST /usr/share/doc/vsftpd-2.0.5/SIZE /usr/share/doc/vsftpd-2.0.5/SPEED /usr/share/doc/vsftpd-2.0.5/TODO /usr/share/doc/vsftpd-2.0.5/TUNING /usr/share/doc/vsftpd-2.0.5/vsftpd.xinetd /usr/share/man/man5/vsftpd.conf.5.gz /usr/share/man/man8/vsftpd.8.gz /var/ftp /var/ftp/pub [root@rhel510 ~]# [root@rhel510 ~]# |
主要装了这几个东西:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
服务: [root@rhel510 ~]# ls -ltr /etc/init.d/ | grep --color vsftpd -rwxr-xr-x 1 root root 1660 Sep 25 2012 vsftpd [root@rhel510 ~]# [root@rhel510 ~]# /etc/init.d/vsftpd -h Usage: /etc/init.d/vsftpd {start|stop|restart|condrestart|status} [root@rhel510 ~]# 配置文件: [root@rhel510 ~]# ll -d /etc/vsftpd/ drwxr-xr-x 2 root root 4096 Dec 18 07:35 /etc/vsftpd/ [root@rhel510 ~]# [root@rhel510 ~]# ls -ltr /etc/vsftpd/ total 20 -rwxr--r-- 1 root root 338 Sep 25 2012 vsftpd_conf_migrate.sh -rw------- 1 root root 4579 Sep 25 2012 vsftpd.conf -rw------- 1 root root 361 Sep 25 2012 user_list -rw------- 1 root root 125 Sep 25 2012 ftpusers [root@rhel510 ~]# 默认的FTP的Chroot目录: [root@rhel510 ~]# ll -d /var/ftp/ drwxr-xr-x 3 root root 4096 Dec 18 07:35 /var/ftp/ [root@rhel510 ~]# ls -ltr /var/ftp/ total 4 drwxr-xr-x 2 root root 4096 Sep 25 2012 pub [root@rhel510 ~]# ls -ltr /var/ftp/pub/ total 0 [root@rhel510 ~]# VSFTP的帮助文档: [root@rhel510 ~]# ls /usr/share/doc/vsftpd-2.0.5 AUDIT BUGS COPYING FAQ LICENSE README.security SECURITY SPEED TUNING BENCHMARKS Changelog EXAMPLE INSTALL README REWARD SIZE TODO vsftpd.xinetd [root@rhel510 ~]# |
下面具体来配置一下FTP服务。
主配置文件:/etc/vsftpd/vsftpd.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@rhel510 vsftpd]# cat vsftpd.conf | grep -v ^# | strings anonymous_enable=YES local_enable=YES write_enable=YES local_umask=022 dirmessage_enable=YES xferlog_enable=YES connect_from_port_20=YES xferlog_std_format=YES ftpd_banner=This is adamhuan's automatic FTP Service. listen=YES pam_service_name=vsftpd userlist_enable=YES userlist_deny=NO tcp_wrappers=YES [root@rhel510 vsftpd]# |
注意:
1.
userlist_enable=YES
userlist_deny=NO
表示只有/etc/vsftpd/user_list中的用户可以访问FTP服务
2.
anonymous_enable=YES
表示可以匿名访问FTP服务
vsftpd.conf中其他的有用的参数:
a.限制上传速度(单位:字节[Byte],故:1000 = 1k;):
单位计算:
1B=1024
1K=1024B
1M=1024K
1G=1024K
1T=1024G
或者:
1B=1000
1K=1000B
1M=1000K
1G=1000K
1T=1000G
匿名用户上传限速:anon_max_rate=5000
本地用户(全局)上传限速:local_max_rate=5000
针对不同的本地用户限速:
1.user_config_dir=/etc/vsftpd/userconf
2.在$user_conf_dir路径下创建与用户同名的文件,vi编辑文本“local_max_rate=25000”
即可。
b.设置服务器连接数:
最大总联机数:max_clients(0,不限制)
单个IP的联机数上线:max_per_ip(0,不限制)
————————————————————————————————
配置user_list和ftpuser。
备份和清空:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@rhel510 vsftpd]# pwd /etc/vsftpd [root@rhel510 vsftpd]# [root@rhel510 vsftpd]# ll total 20 -rw------- 1 root root 125 Sep 25 2012 ftpusers -rw------- 1 root root 361 Sep 25 2012 user_list -rw------- 1 root root 5143 Dec 19 04:07 vsftpd.conf -rwxr--r-- 1 root root 338 Sep 25 2012 vsftpd_conf_migrate.sh [root@rhel510 vsftpd]# [root@rhel510 vsftpd]# cp ftpusers old_20151219_ftpusers [root@rhel510 vsftpd]# cp user_list old_20151219_user_list [root@rhel510 vsftpd]# [root@rhel510 vsftpd]# echo "" > ftpusers [root@rhel510 vsftpd]# echo "" > user_list [root@rhel510 vsftpd]# |
注意,user_list与ftpusers中的用户,都需要在操作系统上真实存在,即:可以通过“id [用户名]”的方式查到用户信息。
如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
[root@rhel510 vsftpd]# cat old_20151219_user_list # vsftpd userlist # If userlist_deny=NO, only allow users in this file # If userlist_deny=YES (default), never allow users in this file, and # do not even prompt for a password. # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers # for users that are denied. root bin daemon adm lp sync shutdown halt mail news uucp operator games nobody [root@rhel510 vsftpd]# [root@rhel510 vsftpd]# cat old_20151219_ftpusers # Users that are not allowed to login via ftp root bin daemon adm lp sync shutdown halt mail news uucp operator games nobody [root@rhel510 vsftpd]# [root@rhel510 vsftpd]# [root@rhel510 vsftpd]# id mail uid=8(mail) gid=12(mail) groups=12(mail) [root@rhel510 vsftpd]# id news uid=9(news) gid=13(news) groups=13(news) [root@rhel510 vsftpd]# id uucp uid=10(uucp) gid=14(uucp) groups=14(uucp) [root@rhel510 vsftpd]# |
如果,user_list与ftpusers中定义的用户,在系统上其实并没有,那么将会导致客户端访问FTP的时候无法完成密码认证的过程:
1 2 3 4 5 6 7 8 9 10 11 |