配置VSFTPD的方法及配置文件说明

1、首先查看系统是否已将安装了vsftp这个软件
  #rpm -qa |grep vsftpd
   vsftpd-1.1.3-8
  如果没有就找到RH9的第三张安装光盘,安装这个软件
  #rpm -ivh vsftpd-1.1.3-8.i386.rpm

  2、启动、停止、重启vsftp服务器
  #/etc/rc.d/init.d/vsftpd start/stop/restart

  3、开机时启动vsftp服务器(3种方法)
  方法一:#ntsysv  在终端输入ntsysv,利用上下方向键把光标移动到vsftp,在以空格选,最后利用Tab键把光标移动到确定,然后按enter就完成了。
  方法二:用图形化设置工具利用鼠标选择。主菜单->系统设置->服务器设置->服务选择vsftp,保存退出。
  方法三:#chkconfig --level 35 vsftpd on
         35的意思就是在启动的时候图形和文本模式都开

  4、测试vsftp服务器
  # telnet 127.0.0.1 21
  Trying 127.0.0.1...
  Connected to 127.0.0.1.
  Escape character is '^]'.
  220 ready, dude (vsFTPd 1.1.0:t me, break me)
  //从上面的内容可以确认vsftpd 已经被启动,按Ctrl+]中断会话
  ^]
  //按q 退出telnet
  telnet> q
  Connection closed.
  注意:防火墙要设置一下,把FTP允许

  5、vsftp相关配置文件说明
  􀂾 /etc/vsftpd/vsftpd.conf
  􀂾 /etc/vsftpd.ftpusers
  􀂾 /etc/vsftpd.user_list
  其中,/etc/vsftpd/vsftpd.conf 是主配置文件。/etc/vsftpd.ftpusers 中指定了哪些用户不能访问FTP服务器。/etc/vsftpd.user_list 中指定的用户默认情况( 即在/etc/vsftpd/vsftpd.con中设置了userlist_deny=YES)下也不能访问FTP 服务器,当在/etc/vsftpd/vsftpd.con中设置了userlist_deny=NO时,仅仅允许/etc/vsftpd.user_list 中指定的用户访问FTP 服务器。

  让我们来看看/etc/vsftp/vsftpd.conf,用你喜欢的编辑器打开。(注意首先要把这个文件做好备份,这样来个安全第一,万一出错了还可以恢复)
  # Example config file /etc/vsftpd.conf
  #
  # The default compiled in settings are very paranoid. This sample
  # file
  # loosens things up a bit, to make the ftp daemon more usable.
  #
  # Allow anonymous FTP?
  anonymous_enable=YES            ->是否允许匿名登入
  #
  # 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                ->是否允许用户在FTP服务器文件中有写的权限
  #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            ->设置本地用户的文件生成掩码为022
  #
  # Uncomment this to allow the anonymous FTP user to upload files.
  # This only
  # has an effect if the above global write enable isactivated.
  # 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   ->激活目录信息,当远程用户更改目录的时候,出现提示
  #
  # Activate logging of uploads/downloads.
  xferlog_enable=YES   ->启动上传和下载的日志功能
  #
  # Make sure PORT transfer connections originate from port 20 (ftp-data).
  connect_from_port_20=YES   ->启用FTP数据的端口的连接请求
  #
  # 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       ->改变上传文件的所有者为root
  #chown_username=whoever
  #
  # You may override where the log file goes if you like. The default is shown
  # below.
  #xferlog_file=/var/log/vsftpd.log  ->设置日志文件的路径和文件名
  #
  # If you want, you can have your log file in standard ftpd xferlog format
  xferlog_std_format=YES  ->是否使用标准的ftp xferlog日志文件格式
  #
  # You may change the default value for timing out an idle session.
  idle_session_timeout=60  ->设置空闲用户会话中断时间
  #
  # 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 turning on ascii_download_enable enables malicious remote parties
  # to consume your I/O resources, by issuing the command "SIZE /big/file" in
  # ASCII mode.
  # These ASCII options are split into upload and download because you may wish
  # to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),
  # without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be
  # on the client anyway..
  #ascii_upload_enable=YES    ->是否允许使用ASCII格式来上传和下载
  #ascii_download_enable=YES
  #
  # You may fully customise the login banner string:
  #ftpd_banner=Welcome to blah FTP service. ->设置欢迎信息
  #
  # 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_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
  pam_service_name=vsftpd   ->设置pam认证服务的配置文件名称
  userlist_enable=YES       ->用户列表中的用户是否允许登入FTP
  #enable for standalone mode
  listen=YES          -> 使用FTP处于独立模式
  tcp_wrappers=YES    ->使用tcp_wrappers作为主机访问控制方式

  默认配置:
  (1)允许匿名用户和本地用户登录;
  (2)匿名用户的登录名为ftp 或anonymous,口令为一个Email地址;
  (3)匿名用户不能离开匿名服务器目录/var/ftp,且只能下载不能上传;
  (4)本地用户的登录名为本地用户名,口令为此本地用户的口令;
  (5)本地用户可以离开自家目录切换至有权访问的其他目录,并在权限允许的情况下进行上传/下载;
  (6)写在文件/etc/vsftpd.ftpusers 中的本地用户禁止登录。
  在win下用ftp工具,或在浏览器也行ftp://192.168.0.2,因为可以匿名登入,当然就可以不用密码和用户名噢,匿名登入的目录是在/var/ftp。现在因为没有什么东西,所以看到是个空目录。

  默认配置当然不能满足我们需要,下面我们来进一步配置
  允许匿名用户上传(一个人始终是能力有限,好东西是要靠大家的,这个设置很重要噢)
  //修改vsftpd 的主配置文件/etc/vsftp/vsftpd.conf
  # vi /etc/vsftpd.conf
  //将如下两行前的#删除
  //① #anon_upload_enable=YES 􀃆 允许匿名用户上传
  //②#anon_mkdir_write_enable=YES 􀃆 开启匿名用户的写和创建目录的权限
  //若要以上两项设置生效,同时还要求:
  //(1) write_enable=YES
  //(2) 匿名用户对文件系统的上传目录具有写权限
  //添加如下的配置语句
  // anon_world_readable_only=NO
  //上面的配置语句用于放开匿名用户的浏览权限
  //修改后存盘退出vi
  //
  //创建匿名上传目录
  # mkdir /var/ftp/incoming
  # 修改上传目录的权限
  # chmod o+w /var/ftp/incoming/
  重启动服务器
  #/etc/rc.d/init.d/vsftpd restart
  注意(1)匿名用户对/var/ftp/incoming 目录而言是其他用户,所以
  必须为此目录添加对其他用户的可写权限才可上传,即此目录
  权限的数字表示是707。
  (2)只有设置anon_world_readable_only=NO 后,才能开放匿
  名用户的读权限,即:浏览此服务器中全部的内容。

  配置基本的性能和安全选项
  1. 设置空闲的用户会话的中断时间
  例如下面的配置:
  idle_session_timeout=600
  将在用户会话空闲10 分钟后被中断。
  2. 设置空闲的数据连接的的中断时间
  例如下面的配置:
  data_connection_timeout=120
  将在数据连接空闲2 分钟后被中断。
  3. 设置客户端空闲时的自动中断和激活连接的时间
  例如下面的配置:
  accept_timeout=60
  connect_timeout=60
  将使客户端空闲1 分钟后自动中断连接,并在中断1 分钟后自动激活连接。
  4. 设置最大传输速率限制
  例如下面的配置:
  local_max_rate=50000
  anon_max_rate=30000
  将使本地用户的最大传输速率为50kkbytes / sec,匿名用户的传输速率为30 kbytes / sec。
  5. 设置客户端连接时的端口范围
  例如下面的配置:
  pasv_min_port=50000
  pasv_max_port=60000
  将使客户端连接时的端口范围在50000 和60000 之间。这提高了系统的安全性。
  6. 设置chroot
  在默认配置中,本地用户可以切换到自家目录以外的目录进行浏览,并在权限许可的范围
  内进行下载和上传。这样的设置对于一个FTP 服务器来说是不安全的。
  如果希望用户登录后不能切换到自家目录以外的目录,则需要设置chroot 选项,涉及如
  下选项:
  chroot_local_user
  chroot_list_enable
  chroot_list_file
  有两种设置chroot 的方法:
  (1)设置所有的本地用户执行chroot
  只要将chroot_local_user 的值设为YES 即可,即:
  chroot_local_user=YES
  (2)设置指定的用户执行chroot
  需要如下的设置:
  chroot_local_user=NO
  chroot_list_enable=YES
  chroot_list_file= /etc/vsftpd.chroot_list
  这样,只有/etc/vsftpd.chroot_list 文件中指定的用户才执行chroot。

  配置基于本地用户的访问控制
  要配置基于本地用户的访问控制,可以通过修改vsftpd 的主配置文件/etc/vsftp/vsftpd.conf 来进
  行,有如下两种限制方法:
  1. 限制指定的本地用户不能访问,而其他本地用户可访问
  例如下面的设置:
  userlist_enable=NO
  userlist_deny=YES
  userlist_file= /etc/vsftpd.user_list
  使文件/etc/vsftpd.user_list 中指定的本地用户不能访问FTP 服务器,而其他本地用户可访
  问FTP 服务器。
  2. 限制指定的本地用户可以访问,而其他本地用户不可访问
  例如下面的设置:
  userlist_enable= YES
  userlist_deny= NO
  userlist_file= /etc/vsftpd.user_list
  使文件/etc/vsftpd.user_list 中指定的本地用户可以访问FTP 服务器,而其他本地用户不可
  以访问FTP 服务器。

  下面来个例子
  高安全级别匿名FTP 服务器的配置要求
  􀂾 仅仅允许匿名用户访问
  􀂾 不允许本地用户访问
  􀂾 关闭所有写权限
  􀂾 不允许匿名用户上传
  􀂾 设置客户端连接时的端口范围
  􀂾 设置 匿名用户的最大传输速率限制
  􀂾 设置空闲的数据连接的的中断时间
  􀂾 设置客户端空闲时的自动中断和激活连接的时间
  􀂾 配置每个主机的最大连接数
  􀂾 配置总的并发连接数
  􀂾 配置禁止访问的主机
  􀂾 配置安全日志
  # cat /etc/vsftp/vsftpd.conf
  # Access rights
  anonymous_enable=YES
  local_enable=NO
  write_enable=NO
  anon_upload_enable=NO
  anon_mkdir_write_enable=NO
  anon_other_write_enable=NO
  # Security
  anon_world_readable_only=YES
  connect_from_port_20=YES
  hide_ids=YES
  pasv_min_port=50000
  pasv_max_port=60000
  # Features
  xferlog_enable=YES
  ls_recurse_enable=NO
  ascii_download_enable=NO
  async_abor_enable=YES
  # Performance
  one_process_model=YES
  idle_session_timeout=120
  data_connection_timeout=300
  accept_timeout=60
  connect_timeout=60
  anon_max_rate=50000
  ftpd_banner=This FTP server is anonymous only.

  这里主要是限制主机访问规则
  # cat /etc/xinetd.d/vsftpd
  service ftp
  {
  disable = no
  socket_type = stream
  wait = no
  user = root
  server = /usr/local/sbin/vsftpd
  per_source = 5
  instances = 200
  no_access = 192.168.1.3
  banner_fail = /etc/vsftpd.busy_banner
  log_on_success += PID HOST DURATION
  log_on_failure += HOST
  }
  重启动服务器
  #/etc/rc.d/init.d/vsftpd restart
  完成了,现在你可以试试看是不是和上面说的限制一样了。

  很多FTP服务器都要密码和用户才能下到你要的好东西,你是不是也想要过下这个隐呢?给别人一个用户名和密码,这个配置其实也很简单。
  虚拟用户(virtual users)的FTP 服务器的配置。虚拟用户只能访问为其提供的FTP 服务,虚拟用户不能像本地的实用户那样登录系统而访问系统的其他资源。若用户对FTP
  服务器站内具有写权限并且不允许访问系统的其他资源,则该用户应该使用虚拟用户才能提高系统的安全性。传统的FTP 服务器采用如下的方法实现虚拟用户:
  1、 在本地建立普通用户账号并设置密码
  2、将其登录shell 设为不可登录
  3、由passwd/shadow 口令系统进行认证
  vsftpd 的虚拟用户采用了不与系统账户口令文件合二为一的方法,也就是说,为了认证这
  些虚拟用户vsftpd 使用单独的口令库文件(pam_userdb),由可插拔认证模块(PAM)进行认证。使用这种方式更加安全,并且配置更灵活。

  配置简单的虚拟用户FTP 服务器
  1、生成虚拟用户口令库文件
  2、配置生成vsftpd 的认证文件
  3、建立虚拟用户所要访问的目录并设置相应权限
  4、建立配置文件
  //生成虚拟用户口令库文件,为了建立此口令库文件,先要生成一个文本文件
  # cat <<! >logins.txt
  > tom
  > foo
  > fred
  > bar
  > valid
  > lwd
  > dede
  > jy
  > !
  #
  //此文本文件的格式是:
  //单数行为用户名,偶数行为口令,
  //即:用户tom 的口令为foo;用户fred 的口令为bar
  //
  //下面使用db_load 命令生成口令库文件
  # db_load -T -t hash -f ~/logins.txt /etc/vsftpd_login.db
  //修改口令库文件的权限
  # chmod 600 /etc/vsftpd_login.db
  //下面编辑生成虚拟用户所需的PAM 配置文件
  # vi /etc/pam.d/ftp.vu
  //插入如下两行
  //auth required /lib/security/pam_userdb.so db=/etc/vsftpd_login
  //account required /lib/security/pam_userdb.so db=/etc/vsftpd_login
  //保存后退出vi
  //用户也可以用下面的命令从源代码分发包中复制此文件
  // cd /usr/local/src/vsftpd-1.1.3/EXAMPLE/
  // cp VIRTUAL_USERS/vsftpd.pam /etc/pam.d/ftp.vu
  #
  //下面建立虚拟用户所要访问的目录并设置仅virtual 用户访问的权限
  # useradd -d /home/ftpsite virtual
  # chmod 700 /home/ftpsite/
  #
  //在目录中生成测试文件
  # su - virtual -c "echo hello>/home/ftpsite/test_file"
  #
  //下面生成主配置文件
  # vi /etc/vsftpd.standalone.vu.conf
  //在此文件中插入下面的配置语句
  //listen=YES
  //anonymous_enable=NO
  //local_enable=YES
  //write_enable=NO
  //anon_upload_enable=NO
  //anon_mkdir_write_enable=NO
  //anon_other_write_enable=NO
  //chroot_local_user=YES
  //guest_enable=YES 􀃆 启用虚拟用户
  //guest_username=virtual 􀃆 将虚拟用户映射为本地virtual 用户
  // 这样虚拟用户登录后才能进入本地用户virtual 的目录/home/ftpsite/
  //pasv_min_port=30000
  //pasv_max_port=30999
  //ftpd_banner=This FTP server is virtual user only.
  //pam_service_name=ftp.vu 􀃆 指定PAM 配置文件为ftp.vu
  //插入完毕,保存退出。
  #
  //下面先关闭原来的服务,而后启动新的服务
  # killall vsftpd
  # /usr/local/sbin/vsftpd /etc/vsftpd.standalone.vu.conf &
  //配置结束
  配置好后,新的口令库中的所有用户就都可以登录此FTP 服务器了。

 

posted @ 2012-03-19 10:01  linux—jock  阅读(628)  评论(0编辑  收藏  举报