Spring学习系列: 环境搭建(vsftpd)

来源:互联网 发布:金十数据官方网站 编辑:程序博客网 时间:2024/06/13 17:41

简介

vsftpd 是用于类unix系统上的文件服务器,包括linux,支持Ipv6和SSL,支持显式的和隐式的FTPS,也是linux众多发行版例如Unbuntu, CentOS, Fedora, NimbleX, Slackware等等的默认服务器。

以上摘自维基百科

下载安装

在centos下:
检查是否已经安装

rpm -qa | grep vsftpd

如果没有安装,则进行安装:

yum -y install vsftpd  //安装,默认安装在/etc/vsftpdchkconfig vsftpd on     //设置开机自动启动,可选项,非必须

其他发行版都可以找到相应的命令。这样就安装完成了,很简单,主要的配置方面比较麻烦。

配置

接下来就要创建一个虚拟账户用于登录ftp服务器了。

 useradd yeonon -s /sbin/nologin             //创建用户passwd yeonon                                //为用户设置密码chown -R yeonon.yeonon /produce/ftpfile/    //赋予yeonon用户组下的yeonon用户 /produce/ftpfile的访问权限,这里的路径要和下面配置中local_root属性一致,否则容易出现500错误。vim /etc/vsftpd/vsftpd.conf                 //打开配置文件

接下来就是配置文件的属性配置了

# Please see vsftpd.conf.5 for all compiled in defaults.## READ THIS: This example file is NOT an exhaustive list of vsftpd options.# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's# capabilities.## Allow anonymous FTP? (Beware - allowed by default if you comment this out).anonymous_enable=NO## Uncomment this to allow local users to log in.local_enable=YES## Uncomment this to enable any form of FTP write command.write_enable=YES## Default umask for local users is 077. You may wish to change this to 022,# if your users expect that (022 is used by most other ftpd's)local_umask=022## 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.#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## Activate directory messages - messages given to remote users when they# go into a certain directory.dirmessage_enable=YES## The target log file can be vsftpd_log_file or xferlog_file.# This depends on setting xferlog_std_format parameterxferlog_enable=YES## Make sure PORT transfer connections originate from port 20 (ftp-data).connect_from_port_20=YES## If you want, you can arrange for uploaded anonymous files to be owned by# a different user. Note! Using "root" for uploaded files is not# recommended!#chown_uploads=YES#chown_username=whoever## The name of log file when xferlog_enable=YES and xferlog_std_format=YES# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log#xferlog_file=/var/log/xferlog## Switches between logging into vsftpd_log_file and xferlog_file files.# NO writes to vsftpd_log_file, YES to xferlog_filexferlog_std_format=YES## You may change the default value for timing out an idle session.#idle_session_timeout=600## You may change the default value for timing out a data connection.#data_connection_timeout=120## It is recommended that you define on your system a unique user which the# ftp server can use as a totally isolated and unprivileged user.#nopriv_user=ftpsecure## Enable this and the server will recognise asynchronous ABOR requests. Not# recommended for security (the code is non-trivial). Not enabling it,# however, may confuse older FTP clients.#async_abor_enable=YES## By default the server will pretend to allow ASCII mode but in fact ignore# the request. Turn on the below options to have the server actually do ASCII# mangling on files when in ASCII mode.# Beware that on some FTP servers, ASCII support allows a denial of service# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd# predicted this attack and has always been safe, reporting the size of the# raw file.# ASCII mangling is a horrible feature of the protocol.#ascii_upload_enable=YES#ascii_download_enable=YES## You may fully customise the login banner string:ftpd_banner=Welcome to yeonon FTP service.local_root=/produce/ftpfile/anon_root=/produce/ftpfile/use_localtime=yes## You may specify a file of disallowed anonymous e-mail addresses. Apparently# useful for combatting certain DoS attacks.#deny_email_enable=YES# (default follows)#banned_email_file=/etc/vsftpd/banned_emails## You may specify an explicit list of local users to chroot() to their home# directory. If chroot_local_user is YES, then this list becomes a list of# users to NOT chroot().#chroot_local_user=YESchroot_list_enable=YES# (default follows)chroot_list_file=/etc/vsftpd/chroot_list## You may activate the "-R" option to the builtin ls. This is disabled by# default to avoid remote users being able to cause excessive I/O on large# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume# the presence of the "-R" option, so there is a strong case for enabling it.#ls_recurse_enable=YES## When "listen" directive is enabled, vsftpd runs in standalone mode and# listens on IPv4 sockets. This directive cannot be used in conjunction# with the listen_ipv6 directive.listen=YES## This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6# sockets, you must run two copies of vsftpd with two configuration files.# Make sure, that one of the listen options is commented !!#listen_ipv6=YESpam_service_name=vsftpduserlist_enable=YEStcp_wrappers=YESpasv_min_port=61001pasv_max_port=62000

上面#开头的就是被注释的无效的配置,这里我们主要关注几个配置就行了,

  1. local_root = /produce/ftpfile/ //根目录
  2. anon_root = /produce/ftpfile/ //匿名根目录
  3. use_localtime=yes //使用本地时间
  4. pasv_min_port=61001 //使用端口的最小值
  5. pasv_max_port=62000 //使用端口的的最大值(同最小值结合表示使用端口范围)
  6. chroot_list_enable=YES //使能chroot_list
  7. chroot_list_file=/etc/vsftpd/chroot_list //chroot_list 文件路径,这个文件就是存放刚刚创建的虚拟用户名字的集合
  8. anonymous_enable=NO //是否允许匿名访问,可自行决定,推荐非匿名

为了配合chroot_list,我们需要在/etc/vsftpd目录下创建一个chroot_list文件,然后写入刚刚创建的用户(这里使用的是yeonon),配置完后就可以进入文件系统了,输入ftp:127.0.0.1:21 就可以访问文件系统了。

常见错误

问: 能登录文件系统了,但是完全看不到有任何文件,在本地系统中确实是放入了文件的,怎么回事?

答: 这八成就是防火墙的问题,在网上搜索一下修改防火墙设置,然后开放20,21端口就行了。

问: 字符界面如何访问ftp文件服务系统?

答: 在centos下可以先安装ftp命令,关于如何使用,可网上搜索,很容易就搜索到了。

问: 不能登录文件系统,提示500错误?

答: 注意虚拟用户赋予权限的路径和根目录路径的一致性。

问: 404错误

答: 认真检查一下路径。