VsFTPd的配置

运维 系统运维
vsftpd是Linux发行版中最为推崇的FTP服务器程序,vsftpd的特点是小巧轻快,安全易用。那么该如何配置vsftpd呢?本文讲述的就是vsftpd的配置

VsFTPd配置:vsFTPd的运行有两种模式,一种是standalone "initd"模式,另外一种是xinetd模式。

  两种模式运行机制不是相同的,stardard initd模式,适合专业FTP,且FTP总是一直有人访问,占用资源也是比较大,如果您的FTP总是有人访问和登入。就要用这种模式。如果您的FTP访问人数比较小,建议您用xinetd模式。xinetd模式,是当用户请求时,vsFTPd才会启动。

  不同的环境,当然得用不同的启动模式。

  1] 我们主要把vsFTPd的配置文件改一下就行了。配制文件在/etc/vsftpd/vsftpd.conf,用您喜欢的编辑器打开。请参考下面的配置文件。

  1.   # Example config file /etc/vsftpd.conf  
  2.  
  3.   #  
  4.  
  5.   # The default compiled in settings are very paranoid. This sample file  
  6.  
  7.   # loosens things up a bit, to make the ftp daemon more usable.  
  8.  
  9.   #  
  10.  
  11.   # Allow anonymous FTP?  
  12.  
  13.   anonymous_enable=YES 
  14.  
  15.   #  
  16.  
  17.   # Uncomment this to allow local users to log in.  
  18.  
  19.   local_enable=YES 
  20.  
  21.   #  
  22.  
  23.   # Uncomment this to enable any form of FTP write command.  
  24.  
  25.   write_enable=YES 
  26.  
  27.   #  
  28.  
  29.   # Default umask for local users is 077. You may wish to change this to 022,  
  30.  
  31.   # if your users expect that (022 is used by most other ftpd's)  
  32.  
  33.   local_umask=022 
  34.  
  35.   #  
  36.  
  37.   # Uncomment this to allow the anonymous FTP user to upload files. This only  
  38.  
  39.   # has an effect if the above global write enable is activated. Also, you will  
  40.  
  41.   # obviously need to create a directory writable by the FTP user.  
  42.  
  43.   #anon_upload_enable=YES 
  44.  
  45.   #  
  46.  
  47.   # Uncomment this if you want the anonymous FTP user to be able to create  
  48.  
  49.   # new directories.  
  50.  
  51.   #anon_mkdir_write_enable=YES 
  52.  
  53.   #  
  54.  
  55.   # Activate directory messages - messages given to remote users when they  
  56.  
  57.   # go into a certain directory.  
  58.  
  59.   dirmessage_enable=YES 
  60.  
  61.   #  
  62.  
  63.   # Activate logging of uploads/downloads.  
  64.  
  65.   xferlog_enable=YES 
  66.  
  67.   #  
  68.  
  69.   # Make sure PORT transfer connections originate from port 20 (ftp-data).  
  70.  
  71.   connect_from_port_20=YES 
  72.  
  73.   #  
  74.  
  75.   # If you want, you can arrange for uploaded anonymous files to be owned by  
  76.  
  77.   # a different user. Note! Using "root" for uploaded files is not  
  78.  
  79.   # recommended!  
  80.  
  81.   #chown_uploads=YES 
  82.  
  83.   #chown_username=whoever 
  84.  
  85.   #  
  86.  
  87.   # You may override where the log file goes if you like. The default is shown  
  88.  
  89.   # below.  
  90.  
  91.   #xferlog_file=/var/log/vsftpd.log  
  92.  
  93.   #  
  94.  
  95.   # If you want, you can have your log file in standard ftpd xferlog format  
  96.  
  97.   xferlog_std_format=YES 
  98.  
  99.   #  
  100.  
  101.   # You may change the default value for timing out an idle session.  
  102.  
  103.   #idle_session_timeout=600 
  104.  
  105.   #  
  106.  
  107.   # You may change the default value for timing out a data connection.  
  108.  
  109.   #data_connection_timeout=120 
  110.  
  111.   #  
  112.  
  113.   # It is recommended that you define on your system a unique user which the  
  114.  
  115.   # ftp server can use as a totally isolated and unprivileged user.  
  116.  
  117.   #nopriv_user=ftpsecure 
  118.  
  119.   #  
  120.  
  121.   # Enable this and the server will recognise asynchronous ABOR requests. Not  
  122.  
  123.   # recommended for security (the code is non-trivial). Not enabling it,  
  124.  
  125.   # however, may confuse older FTP clients.  
  126.  
  127.   #async_abor_enable=YES 
  128.  
  129.   #  
  130.  
  131.   # By default the server will pretend to allow ASCII mode but in fact ignore  
  132.  
  133.   # the request. Turn on the below options to have the server actually do ASCII  
  134.  
  135.   # mangling on files when in ASCII mode.  
  136.  
  137.   # Beware that turning on ascii_download_enable enables malicious remote parties  
  138.  
  139.   # to consume your I/O resources, by issuing the command "SIZE /big/file" in  
  140.  
  141.   # ASCII mode.  
  142.  
  143.   # These ASCII options are split into upload and download because you may wish  
  144.  
  145.   # to enable ASCII uploads (to prevent uploaded scripts etc. from breaking),  
  146.  
  147.   # without the DoS risk of SIZE and ASCII downloads. ASCII mangling should be  
  148.  
  149.   # on the client anyway..  
  150.  
  151.   #ascii_upload_enable=YES 
  152.  
  153.   #ascii_download_enable=YES 
  154.  
  155.   #  
  156.  
  157.   # You may fully customise the login banner string:  
  158.  
  159.   #ftpd_banner=Welcome to blah FTP service.  
  160.  
  161.   #  
  162.  
  163.   # You may specify a file of disallowed anonymous e-mail addresses. Apparently  
  164.  
  165.   # useful for combatting certain DoS attacks.  
  166.  
  167.   #deny_email_enable=YES 
  168.  
  169.   # (default follows)  
  170.  
  171.   #banned_email_file=/etc/vsftpd.banned_emails  
  172.  
  173.   #  
  174.  
  175.   # You may specify an explicit list of local users to chroot() to their home  
  176.  
  177.   # directory. If chroot_local_user is YES, then this list becomes a list of  
  178.  
  179.   # users to NOT chroot().  
  180.  
  181.   #chroot_list_enable=YES 
  182.  
  183.   # (default follows)  
  184.  
  185.   #chroot_list_file=/etc/vsftpd.chroot_list  
  186.  
  187.   #  
  188.  
  189.   # You may activate the "-R" option to the builtin ls. This is disabled by  
  190.  
  191.   # default to avoid remote users being able to cause excessive I/O on large  
  192.  
  193.   # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume  
  194.  
  195.   # the presence of the "-R" option, so there is a strong case for enabling it.  
  196.  
  197.   #ls_recurse_enable=YES 
  198.  
  199.   pam_service_name=vsftpd 
  200.  
  201.   userlist_enable=YES 
  202.  
  203.   #enable for standalone mode  
  204.  
  205.   listen=YES 
  206.  
  207.   tcp_wrappers=YES 
  208.  

#p#

  2]更改完配置文件后,我们可以用下面的命令来重启vsFTPd服务器

  1.   [root@linuxsir001 root]# /etc/init.d/vsftpd restart  
  2.  

  关闭 vsftpd: [ 确定 ]

  为 vsftpd 启动 vsftpd: [ 确定 ]

  1.   [root@linuxsir001 root]#  
  2.  

  3]以匿名方式来访问测试,在text模式下:

  注意:在text模式下,要用用户名ftp,密码ftp来访问,这才是在text中匿名访问FTP。看如下的操作:

  1.   [root@linuxsir001 root]# ftp 192.168.0.1  
  2.  
  3.   Connected to 192.168.0.1.  
  4.  
  5.   220 (vsFTPd 1.1.3)  
  6.  
  7.   530 Please login with USER and PASS.  
  8.  
  9.   530 Please login with USER and PASS.  
  10.  
  11.   KERBEROS_V4 rejected as an authentication type  
  12.  
  13.   Name (192.168.0.1:root): ftp 这里写上ftp  
  14.  
  15.   331 Please specify the password.  
  16.  
  17.   Password:[这里添写ftp的密码],匿名登入密码也是ftp  
  18.  
  19.   230 Login successful. Have fun.  
  20.  
  21.   Remote system type is UNIX.  
  22.  
  23.   Using binary mode to transfer files.  
  24.  
  25.   ftp> ls  
  26.  
  27.   227 Entering Passive Mode (192,168,0,1,137,151)  
  28.  
  29.   150 Here comes the directory listing.  
  30.  
  31.   drwxr-xr-x 6 0 0 4096 May 25 13:54 RedHat90  
  32.  
  33.   drwxr-xr-x 2 0 0 4096 Feb 28 19:21 pub  
  34.  
  35.   226 Directory send OK.  
  36.  
  37.   ftp> 
  38.  

  那匿名用户所访问的是哪个目录?是/var/ftp这个目录

  出现问题的解决:有时出错,是因为没有ftp和nobody用户,所以要在系统中添加这两个用户,一般的情况下,这两个用户在系统中是存在的。看下面的操作。

  1.   [root@linuxsir001 root]# adduser ftp  
  2.  
  3.   adduser: user ftp exists  
  4.  
  5.   [root@linuxsir001 root]# adduser nobody  
  6.  
  7.   adduser: user nobody exists  
  8.  

  从上面的操作中可知ftp和nobody用户是存在的,所以没有必要添加ftp和nobody用户了。如果不存在,一定要添加这两个用户,否则会出现匿名用户不能访问的情况。

  4]如果要以系统中存在的普通用户登入FTP,也没有什么可以设置的,添加一个用户就行。比如我要添加beinan这个用户,就要用下面的办法

  1.   [root@linuxsir001 root]# adduser beinan  
  2.  
  3.   [root@linuxsir001 root]# passwd beinan  
  4.  
  5.   Changing password for user beinan.  
  6.  
  7.   New password:  
  8.  
  9.   BAD PASSWORD: it does not contain enough DIFFERENT characters  
  10.  
  11.   Retype new password:  
  12.  
  13.   passwd: all authentication tokens updated successfully.  
  14.  
  15.   [root@linuxsir001 root]#  
  16.  

  这样的话,就在/home目录中出现一个beinan的用户目录:如下:

  1.   [root@linuxsir001 root]# ls /home/  
  2.  
  3.   beinan  
  4.  

  如果我们想让beinan这个用户作为虚拟用户,也就是说,beinan这个用户是不能登入系统的,只能是登入FTP。 那这样的用户应该如何添加呢??

  1.   [root@linuxsir001 backupNow]# adduser -g ftp -s /sbin/nologin beinan  
  2.  
  3.   [root@linuxsir001 backupNow]# passwd beinan  
  4.  
  5.   Changing password for user beinan.  
  6.  
  7.   New password:  
  8.  
  9.   Retype new password:  
  10.  
  11.   passwd: all authentication tokens updated successfully.  
  12.  
  13.   [root@linuxsir001 backupNow]#  
  14.  

  注:这仅仅是vsFTPd添加虚拟用户的一个方法,还有更好的办法需要我们去学习!另外的办法也在测试之中。严格上来说,这种办法不能算虚拟用户。还有另外的一个办法,就是通过pam认证,用db_load来添加用户,目前我也弄成功了,不过相对要复杂一点。正在测试之中。

  如果我们想把用户目录定位到别的目录应该怎么办呢??这个也比较简单,看一下useradd就比较明白了。比如我想添加beinan这个用户,并把目录放在/opt目录中:如下操作:

  1.   [root@linuxsir001 root]# adduser -d /opt/beinan beinan  
  2.  
  3.   [root@linuxsir001 root]# passwd beinan  
  4.  
  5.   Changing password for user beinan.  
  6.  
  7.   New password:  
  8.  
  9.   Retype new password:  
  10.  
  11.   passwd: all authentication tokens updated successfully.  
  12.  

  如果是添加虚拟用户,也就是不让用户登入系统,只能登入FTP的用户。如果我们想把beinan这个用户目录定位在/opt/beinan这个目录中,根据上面的方法。我们应该如下操作

  1.   [root@linuxsir001 backupNow]# adduser -d /opt/beinan -g ftp -s /sbin/nologin beinan  
  2.  
  3.   [root@linuxsir001 backupNow]# passwd beinan  
  4.  
  5.   Changing password for user beinan.  
  6.  
  7.   New password:  
  8.  
  9.   Retype new password:  
  10.  
  11.   passwd: all authentication tokens updated successfully.  
  12.  
  13.   [root@linuxsir001 backupNow]#  
  14.  

  看一下是不是已经成功添加到了beinan这个用户,并把beinan的家目录放在了/opt目录中呢??

  1.   [root@linuxsir001 root]# ls /opt/  
  2.  
  3.   beinan  
  4.  

  证明已经成功。

#p#

  我们可以在text模式下以beinan用户登入,然后来访问ftp。

  1.   [root@linuxsir001 root]# ftp 192.168.0.1  
  2.  
  3.   Connected to 192.168.0.1.  
  4.  
  5.   220 (vsFTPd 1.1.3)  
  6.  
  7.   530 Please login with USER and PASS.  
  8.  
  9.   530 Please login with USER and PASS.  
  10.  
  11.   KERBEROS_V4 rejected as an authentication type  
  12.  
  13.   Name (192.168.0.1:root): beinan  
  14.  
  15.   331 Please specify the password.  
  16.  
  17.   Password:  
  18.  
  19.   230 Login successful. Have fun.  
  20.  
  21.   Remote system type is UNIX.  
  22.  
  23.   Using binary mode to transfer files.  
  24.  
  25.   ftp> 
  26.  

  是不是成功了呢?

  我们也可以用gftp来访问beinan用户,并上传相应的东西,所传上的东西就放在beinan用户所在的家目录中,普通用户的家目录在哪里,写您所用的添加用户的方法有关。我在前面已经说了两种办法,一种是默认的添加方法,就是放在/home目录中。

  在本例中,我是采用默认的添加用户的方法。也就是不特别指定用户用户,这样的话,用户目录就在/home目录中。比如用beinan登入FTP时,访问的就是/home/beinan这个目录。让传的东西也在这个目录中。匿名用户所访问是:/var/ftp这个目录。

【编辑推荐】

  1. vsftpd.conf 术语解释大全
  2. Vsftpd如何匿名访问
  3. Vsftpd如何实现虚拟路径
责任编辑:zhaolei 来源: CSDN
相关推荐

2011-03-02 11:32:55

vsftpd配置

2011-03-02 13:23:42

Vsftpd配置

2011-02-22 13:28:43

Linuxvsftpd配置

2011-03-02 10:19:44

2010-02-22 18:27:14

CentOS vsft

2011-03-02 16:11:38

vsftpd.conf配置

2011-02-23 15:50:04

Linuxvsftpd

2011-02-24 09:14:37

vsFTPd虚拟用户

2011-02-24 10:18:41

CentOS配置vsftpd

2011-03-02 10:41:41

Vsftpd安装

2011-02-23 17:23:35

linux vsftpd

2011-03-04 10:05:10

Vsftpd虚拟用户

2011-02-23 15:50:04

Linuxvsftpd

2011-03-01 09:44:04

ubuntuvsftpd

2011-03-02 13:28:33

Vsftpd配置

2011-03-02 13:12:37

vsftpd配置

2010-12-27 13:26:25

FreeBSDvsftpd虚拟用户

2011-03-02 11:25:10

vsftpd配置

2010-08-26 10:28:43

2010-01-13 13:50:53

CentOS Vsft
点赞
收藏

51CTO技术栈公众号