在centos下安装vsftpd的过程

1、查看是否安装vsftp

 [root@hsy 下载]# rpm -qa | grep vsftpd

2、yum安装vsftp

 [root@hsy 下载]# yum -y install vsftpd
    Loaded plugins: fastestmirror, refresh-packagekit, security
    Loading mirror speeds from cached hostfile
     * base: mirrors.stuhome.net
     * epel: mirrors.neusoft.edu.cn
     * extras: mirror.neu.edu.cn
     * updates: mirrors.stuhome.net
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package vsftpd.x86_64 0:2.2.2-11.el6_4.1 will be installed
    --> Finished Dependency Resolution

    Dependencies Resolved

    ================================================================================
     Package         Arch            Version                    Repository     Size
    ================================================================================
    Installing:
     vsftpd          x86_64          2.2.2-11.el6_4.1           base          151 k

    Transaction Summary
    ================================================================================
    Install       1 Package(s)

    Total download size: 151 k
    Installed size: 331 k
    Downloading Packages:
    vsftpd-2.2.2-11.el6_4.1.x86_64.rpm                       | 151 kB     00:00     
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing : vsftpd-2.2.2-11.el6_4.1.x86_64                               1/1 
      Verifying  : vsftpd-2.2.2-11.el6_4.1.x86_64                               1/1 

    Installed:
      vsftpd.x86_64 0:2.2.2-11.el6_4.1                                              

    Complete!
    [root@hsy 下载]# 
    [root@hsy 下载]# chkconfig vsftpd on
    [root@hsy 下载]# rpm -qa | grep vsftpd
    vsftpd-2.2.2-11.el6_4.1.x86_64
    [root@hsy 下载]# 

3、基于虚拟用户的FTP架设
所谓虚拟用户就是没有使用真实的帐户,只是通过某种手段达到映射帐户和设置权限的目的。
1) 我们在安装目录下面的/vsftpd/vsftpd.conf中做如下CentOS FTP服务配置:
查看是否存在该文件:

 [root@hsy 下载]# cd vsftpd-3.0.2
    [root@hsy vsftpd-3.0.2]# ls
    access.c     ftpcmdio.h     opts.h            REWARD            sysstr.c
    access.h     ftpcodes.h     parseconf.c       secbuf.c          sysstr.h
    ascii.c      ftpdataio.c    parseconf.h       secbuf.h          sysutil.c
    ascii.h      ftpdataio.h    port              seccompsandbox.c  sysutil.h
    AUDIT        ftppolicy.c    postlogin.c       seccompsandbox.h  tcpwrap.c
    banner.c     ftppolicy.h    postlogin.h       SECURITY          tcpwrap.h
    banner.h     hash.c         postprivparent.c  secutil.c         TODO
    BENCHMARKS   hash.h         postprivparent.h  secutil.h         tunables.c
    BUGS         INSTALL        prelogin.c        session.h         tunables.h
    builddefs.h  ipaddrparse.c  prelogin.h        SIZE              TUNING
    Changelog    ipaddrparse.h  privops.c         SPEED             twoprocess.c
    COPYING      LICENSE        privops.h         ssl.c             twoprocess.h
    COPYRIGHT    logging.c      privsock.c        ssl.h             utility.c
    defs.h       logging.h      privsock.h        sslslave.c        utility.h
    dummyinc     ls.c           ptracesandbox.c   sslslave.h        vsf_findlibs.sh
    EXAMPLE      ls.h           ptracesandbox.h   standalone.c      vsftpd.8
    FAQ          main.c         README            standalone.h      vsftpd.conf
    features.c   Makefile       README.security   str.c             vsftpd.conf.5
    features.h   netstr.c       README.ssl        str.h             vsftpver.h
    filesize.h   netstr.h       readwrite.c       strlist.c         xinetd.d
    filestr.c    oneprocess.c   readwrite.h       strlist.h
    filestr.h    oneprocess.h   RedHat            sysdeputil.c
    ftpcmdio.c   opts.c         REFS              sysdeputil.h


    [root@hsy vsftpd-3.0.2]# vi vsftpd.conf
vsftpd.conf的内容:
# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# 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=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
#
# 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
#
# Activate logging of uploads/downloads.
xferlog_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
#
# 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.
# Note that the default log file location is /var/log/xferlog in this case.
#xferlog_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 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().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
#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
#
# 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=YES

做如下修改:

anonymous_enable=NO 设定不允许匿名访问
local_enable=YES 设定本地用户可以访问。注:如使用虚拟宿主用户,在该项目设定为NO的情况下所有虚拟用户将无法访问。
chroot_list_enable=YES 使用户不能离开主目录
xferlog_file=/var/log/vsftpd.log 设定vsftpd的服务日志保存路径。注意,该文件默认不存在。必须要手动touch出来
ascii_upload_enable=YES
ascii_download_enable=YES 设定支持ASCII模式的上传和下载功能。
pam_service_name=vsftpd PAM认证文件名。PAM将根据/etc/pam.d/vsftpd进行认证
以下这些是关于Vsftpd虚拟用户支持的重要CentOS FTP服务配置项目。默认vsftpd.conf中不包含这些设定项目,需要自己手动添加CentOS FTP服务配置。 
guest_enable=YES 设定启用虚拟用户功能。
guest_username=ftp 指定虚拟用户的宿主用户。-CentOS中已经有内置的ftp用户了
user_config_dir=/etc/vsftpd/vuser_conf 设定虚拟用户个人vsftp的CentOS FTP服务文件存放路径。存放虚拟用户个性的CentOS FTP服务文件(配置文件名=虚拟用户名)

2)创建chroot list,将用户ftp加入其中:

 touch /etc/vsftpd/chroot_list
    echo ftp >> /etc/vsftpd/chroot_list

3)进行认证:
首先,安装Berkeley DB工具,很多人找不到db_load的问题就是没有安装这个包。

 yum install db4 db4-utils
然后,创建用户密码文本/etc/vsftpd/vuser_passwd.txt ,注意奇行是用户名,偶行是密码

[root@hsy ~]# yum install db4 db4-utils
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirror.neu.edu.cn
 * epel: ftp.sjtu.edu.cn
 * extras: mirror.neu.edu.cn
 * updates: mirror.neu.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package db4.x86_64 0:4.7.25-17.el6 will be updated
--> Processing Dependency: db4 = 4.7.25-17.el6 for package: db4-devel-4.7.25-17.el6.x86_64
---> Package db4.x86_64 0:4.7.25-18.el6_4 will be an update
---> Package db4-utils.x86_64 0:4.7.25-17.el6 will be updated
---> Package db4-utils.x86_64 0:4.7.25-18.el6_4 will be an update
--> Running transaction check
---> Package db4-devel.x86_64 0:4.7.25-17.el6 will be updated
---> Package db4-devel.x86_64 0:4.7.25-18.el6_4 will be an update
--> Processing Dependency: db4-cxx = 4.7.25-18.el6_4 for package: db4-devel-4.7.25-18.el6_4.x86_64
--> Running transaction check
---> Package db4-cxx.x86_64 0:4.7.25-17.el6 will be updated
---> Package db4-cxx.x86_64 0:4.7.25-18.el6_4 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch           Version                    Repository    Size
================================================================================
Updating:
 db4               x86_64         4.7.25-18.el6_4            base         563 k
 db4-utils         x86_64         4.7.25-18.el6_4            base         130 k
Updating for dependencies:
 db4-cxx           x86_64         4.7.25-18.el6_4            base         588 k
 db4-devel         x86_64         4.7.25-18.el6_4            base         6.6 M

Transaction Summary
================================================================================
Upgrade       4 Package(s)

Total download size: 7.8 M
Is this ok [y/N]: 

Is this ok [y/N]: y
Downloading Packages:
(1/4): db4-4.7.25-18.el6_4.x86_64.rpm                    | 563 kB     00:00     
(2/4): db4-cxx-4.7.25-18.el6_4.x86_64.rpm                | 588 kB     00:00     
(3/4): db4-devel-4.7.25-18.el6_4.x86_64.rpm              | 6.6 MB     00:00     
(4/4): db4-utils-4.7.25-18.el6_4.x86_64.rpm              | 130 kB     00:00     
--------------------------------------------------------------------------------
Total                                           3.7 MB/s | 7.8 MB     00:02     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : db4-4.7.25-18.el6_4.x86_64                                   1/8 
  Updating   : db4-cxx-4.7.25-18.el6_4.x86_64                               2/8 
  Updating   : db4-devel-4.7.25-18.el6_4.x86_64                             3/8 
  Updating   : db4-utils-4.7.25-18.el6_4.x86_64                             4/8 
  Cleanup    : db4-devel-4.7.25-17.el6.x86_64                               5/8 
  Cleanup    : db4-utils-4.7.25-17.el6.x86_64                               6/8 
  Cleanup    : db4-4.7.25-17.el6.x86_64                                     7/8 
  Cleanup    : db4-cxx-4.7.25-17.el6.x86_64                                 8/8 
  Verifying  : db4-cxx-4.7.25-18.el6_4.x86_64                               1/8 
  Verifying  : db4-devel-4.7.25-18.el6_4.x86_64                             2/8 
  Verifying  : db4-utils-4.7.25-18.el6_4.x86_64                             3/8 
  Verifying  : db4-4.7.25-18.el6_4.x86_64                                   4/8 
  Verifying  : db4-4.7.25-17.el6.x86_64                                     5/8 
  Verifying  : db4-cxx-4.7.25-17.el6.x86_64                                 6/8 
  Verifying  : db4-devel-4.7.25-17.el6.x86_64                               7/8 
  Verifying  : db4-utils-4.7.25-17.el6.x86_64                               8/8 

Updated:
  db4.x86_64 0:4.7.25-18.el6_4        db4-utils.x86_64 0:4.7.25-18.el6_4       

Dependency Updated:
  db4-cxx.x86_64 0:4.7.25-18.el6_4      db4-devel.x86_64 0:4.7.25-18.el6_4     

Complete!
[root@hsy ~]#

然后,创建用户密码文本/etc/vsftpd/vuser_passwd.txt ,注意奇行是用户名,偶行是密码

wyq
123
cd
123
student
123

接着,生成虚拟用户认证的db文件

  db_load -T -t hash -f /etc/vsftpd/vuser_passwd.txt /etc/vsftpd/vuser_passwd.db

随后,编辑认证文件/etc/pam.d/vsftpd,全部注释掉原来语句,再增加以下两句:

 auth required pam_userdb.so db=/etc/vsftpd/vuser_passwd
    account required pam_userdb.so db=/etc/vsftpd/vuser_passwd

最后,创建虚拟用户个性CentOS FTP服务文件

 mkdir /etc/vsftpd/vuser_conf/
    vi /etc/vsftpd/vuser_conf/wyq

(注:文件名等于vuser_passwd.txt里面的账户名,否则下面设置无效)
注:有几个用户就建立几个对应的文件,否则有些用户登录不了的。
内容如下:
local_root=/etc/vsftpd/vsftpd_conf/wyq/ 虚拟用户的根目录(自己随意修改,但必须保证这个东西一定存在,而且这是个文件夹)

 write_enable=YES 可写
    anon_umask=022 掩码
    anon_world_readable_only=NO 
    anon_upload_enable=YES 
    anon_mkdir_write_enable=YES
    anon_other_write_enable=YES

4、启动vsftp服务器

mkdir /var/www/html/ftp
chmod –R 755 /var/www/html
chmod –R 777/var/www/html/ftp

最新的vsftpd要求对主目录不能有写的权限所以html为755 主目录下面的子目录再设置777权限

 [root@hsy ~]# service vsftpd restart

关闭 vsftpd:                                              [失败]
为 vsftpd 启动 vsftpd:500 OOPS: bad bool value in config file for: guest_enable
                                                           [失败]
    [root@hsy ~]# service vsftpd restart

关闭 vsftpd:                                              [失败]
为 vsftpd 启动 vsftpd:                                    [确定]

vsftpd 启动 报错:vsftpd:500 OOPS: bad bool value in config file for: anonymous_enable

处理办法:vi /etc/vsftpd.conf 时,:每行的值都不要有空格,否则启动时会出现错误,举个例子,假如我在listen=YES后多了个空格,那我启动时就出现…

===================================

启动报错:500 OOPS: tcp_wrappers is set to YES but no tcp wrapper support compiled in

处理办法:vi /etc/vsftpd/conf , 注销tcp_wrappers=YES

[root@hsy ~]# service vsftpd restart
关闭 vsftpd:                                              [确定]
为 vsftpd 启动 vsftpd:                                    [确定]
[root@hsy ~]# service vsftpd restart
关闭 vsftpd:                                              [确定]
为 vsftpd 启动 vsftpd:                                    [确定]
[root@hsy ~]# 

service vsftpd start   开启命令
service vsftpd restart 重启
service vsftpd stop   停止


[root@hsy ~]# netstat -nlput
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 127.0.0.1:10024             0.0.0.0:*                   LISTEN      17979/amavisd (mast 
tcp        0      0 127.0.0.1:10025             0.0.0.0:*                   LISTEN      1933/master         
tcp        0      0 0.0.0.0:587                 0.0.0.0:*                   LISTEN      1933/master         
tcp        0      0 127.0.0.1:9998              0.0.0.0:*                   LISTEN      17979/amavisd (mast 
tcp        0      0 0.0.0.0:110                 0.0.0.0:*                   LISTEN      1820/dovecot        
tcp        0      0 127.0.0.1:10031             0.0.0.0:*                   LISTEN      1837/perl           
tcp        0      0 0.0.0.0:143                 0.0.0.0:*                   LISTEN      1820/dovecot        
tcp        0      0 0.0.0.0:54159               0.0.0.0:*                   LISTEN      1568/rpc.statd      
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1439/rpcbind        
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      21413/vsftpd        
tcp        0      0 192.168.122.1:53            0.0.0.0:*                   LISTEN      2226/dnsmasq        
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1660/sshd           
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1670/cupsd          
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      1933/master         
tcp        0      0 0.0.0.0:4190                0.0.0.0:*                   LISTEN      1820/dovecot        
tcp        0      0 127.0.0.1:7777              0.0.0.0:*                   LISTEN      3424/python         
tcp        0      0 0.0.0.0:993                 0.0.0.0:*                   LISTEN      1820/dovecot        
tcp        0      0 0.0.0.0:995                 0.0.0.0:*                   LISTEN      1820/dovecot        
tcp        0      0 :::111                      :::*                        LISTEN      1439/rpcbind        
tcp        0      0 :::80                       :::*                        LISTEN      1978/httpd          
tcp        0      0 :::22                       :::*                        LISTEN      1660/sshd           
tcp        0      0 ::1:631                     :::*                        LISTEN      1670/cupsd          
tcp        0      0 :::44857                    :::*                        LISTEN      1568/rpc.statd      
tcp        0      0 :::443                      :::*                        LISTEN      1978/httpd          
udp        0      0 0.0.0.0:50383               0.0.0.0:*                               1550/avahi-daemon   
udp        0      0 0.0.0.0:5353                0.0.0.0:*                               1550/avahi-daemon   
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               1439/rpcbind        
udp        0      0 0.0.0.0:631                 0.0.0.0:*                               1670/cupsd          
udp        0      0 0.0.0.0:766                 0.0.0.0:*                               1439/rpcbind        
udp        0      0 0.0.0.0:896                 0.0.0.0:*                               1568/rpc.statd      
udp        0      0 0.0.0.0:783                 0.0.0.0:*                               1385/portreserve    
udp        0      0 0.0.0.0:45856               0.0.0.0:*                               1568/rpc.statd      
udp        0      0 192.168.122.1:53            0.0.0.0:*                               2226/dnsmasq        
udp        0      0 0.0.0.0:67                  0.0.0.0:*                               2226/dnsmasq        
udp        0      0 :::111                      :::*                                    1439/rpcbind        
udp        0      0 :::766                      :::*                                    1439/rpcbind        
udp        0      0 :::58283                    :::*                                    1568/rpc.statd      
[root@hsy ~]#

在浏览器里输入:ftp://ip,然后输入用户名和密码,就可以访问了

为了可以在局域网内访问,还需在系统——防火墙——设置信任ftp

到此为止,在centos上面安装vsftpd算是完全成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值