CentOS7下搭建FTP服务器

- 日理万妓 2022-05-20 01:40 417阅读 0赞

1、安装vsftpd

首先查看你是否安装了vsftpd

  1. [root@localhost ~]# rpm -q vsftpd
  2. [root@localhost ~]# vsftpd-3.0.2-10.el7.x86_64 (显示也就安装成功了!)

如果没有则安装vsftpd

  1. [root@localhost ~]# yum install -y vsftpd

安装完成后可以查看到安装的目录

  1. [root@localhost ~]# whereis vsftpd
  2. [root@localhost ~]# vsftpd: /usr/sbin/vsftpd /etc/vsftpd /usr/share/man/man8/vsftpd.8.gz

查看vsftpd服务的状态

  1. [root@localhost ~]# systemctl status vsftpd.service

开启vsftpd服务

  1. [root@localhost ~]# systemctl start vsftpd.service

设置vsftpd服务开机自启

  1. [root@localhost ~]# systemctl enable vsftpd.service
  2. (或者:[root@localhost ~]# chkconfig vsftpd on

2、配置vsftpd.conf文件

[root@localhost ~]# vi /etc/vsftpd/vsftpd.conf

  1. # Example config file /etc/vsftpd/vsftpd.conf
  2. #
  3. # The default compiled in settings are fairly paranoid. This sample file
  4. # loosens things up a bit, to make the ftp daemon more usable.
  5. # Please see vsftpd.conf.5 for all compiled in defaults.
  6. #
  7. # READ THIS: This example file is NOT an exhaustive list of vsftpd options.
  8. # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
  9. # capabilities.
  10. #
  11. # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
  12. anonymous_enable=NO
  13. #
  14. # Uncomment this to allow local users to log in.
  15. # When SELinux is enforcing check for SE bool ftp_home_dir
  16. local_enable=YES
  17. #
  18. # Uncomment this to enable any form of FTP write command.
  19. write_enable=YES
  20. #
  21. # Default umask for local users is 077. You may wish to change this to 022,
  22. # if your users expect that (022 is used by most other ftpd's)
  23. local_umask=022
  24. # Uncomment this to allow the anonymous FTP user to upload files. This only
  25. # has an effect if the above global write enable is activated. Also, you will
  26. # obviously need to create a directory writable by the FTP user.
  27. # When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
  28. #anon_upload_enable=YES
  29. #
  30. # Uncomment this if you want the anonymous FTP user to be able to create
  31. # new directories.
  32. #anon_mkdir_write_enable=YES
  33. #
  34. # Activate directory messages - messages given to remote users when they
  35. # go into a certain directory.
  36. dirmessage_enable=YES
  37. #
  38. # Activate logging of uploads/downloads.
  39. xferlog_enable=YES
  40. #
  41. # Make sure PORT transfer connections originate from port 20 (ftp-data).
  42. connect_from_port_20=YES
  43. #
  44. # If you want, you can arrange for uploaded anonymous files to be owned by
  45. # a different user. Note! Using "root" for uploaded files is not
  46. # recommended!
  47. #chown_uploads=YES
  48. #chown_username=whoever
  49. #
  50. # You may override where the log file goes if you like. The default is shown
  51. # below.
  52. #xferlog_file=/var/log/xferlog
  53. #
  54. # If you want, you can have your log file in standard ftpd xferlog format.
  55. # Note that the default log file location is /var/log/xferlog in this case.
  56. xferlog_std_format=YES
  57. #
  58. # You may change the default value for timing out an idle session.
  59. idle_session_timeout=600
  60. #
  61. # You may change the default value for timing out a data connection.
  62. data_connection_timeout=120
  63. #
  64. # It is recommended that you define on your system a unique user which the
  65. # ftp server can use as a totally isolated and unprivileged user.
  66. #nopriv_user=ftpsecure
  67. #
  68. # Enable this and the server will recognise asynchronous ABOR requests. Not
  69. # recommended for security (the code is non-trivial). Not enabling it,
  70. # however, may confuse older FTP clients.
  71. #async_abor_enable=YES
  72. #
  73. # By default the server will pretend to allow ASCII mode but in fact ignore
  74. # the request. Turn on the below options to have the server actually do ASCII
  75. # mangling on files when in ASCII mode.
  76. # Beware that on some FTP servers, ASCII support allows a denial of service
  77. # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
  78. # predicted this attack and has always been safe, reporting the size of the
  79. # raw file.
  80. # ASCII mangling is a horrible feature of the protocol.
  81. ascii_upload_enable=YES
  82. ascii_download_enable=YES
  83. #
  84. # You may fully customise the login banner string:
  85. ftpd_banner=Welcome to blah FTP service.
  86. #
  87. # You may specify a file of disallowed anonymous e-mail addresses. Apparently
  88. # useful for combatting certain DoS attacks.
  89. #deny_email_enable=YES
  90. # (default follows)
  91. #banned_email_file=/etc/vsftpd/banned_emails
  92. #
  93. # You may specify an explicit list of local users to chroot() to their home
  94. # directory. If chroot_local_user is YES, then this list becomes a list of
  95. # users to NOT chroot().
  96. # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
  97. # the user does not have write access to the top level directory within the
  98. # chroot)
  99. chroot_local_user=YES
  100. #chroot_list_enable=YES
  101. # (default follows)
  102. #chroot_list_file=/etc/vsftpd/chroot_list
  103. #
  104. # You may activate the "-R" option to the builtin ls. This is disabled by
  105. # default to avoid remote users being able to cause excessive I/O on large
  106. # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
  107. # the presence of the "-R" option, so there is a strong case for enabling it.
  108. ls_recurse_enable=YES
  109. #
  110. # When "listen" directive is enabled, vsftpd runs in standalone mode and
  111. # listens on IPv4 sockets. This directive cannot be used in conjunction
  112. # with the listen_ipv6 directive.
  113. listen=YES
  114. #
  115. # This directive enables listening on IPv6 sockets. By default, listening
  116. # on the IPv6 "any" address (::) will accept connections from both IPv6
  117. # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
  118. # sockets. If you want that (perhaps because you want to listen on specific
  119. # addresses) then you must run two copies of vsftpd with two configuration
  120. # files.
  121. # Make sure, that one of the listen options is commented !!
  122. #listen_ipv6=YES
  123. pam_service_name=vsftpd
  124. userlist_enable=YES
  125. userlist_deny=NO
  126. local_root=/var/public_root
  127. tcp_wrappers=YES
  128. use_localtime=YES
  129. allow_writeable_chroot=YES

3、添加FTP账户

这里设置的账户名为“test”,密码为“123456” (貌似最新的不能配置这种若类型密码了!!!)

当然你也可以通过 userdel -r test 删除用户

  1. [root@localhost ~]# useradd test -s /sbin/nologin
  2. [root@localhost ~]# passwd test

4、编辑user_list文件,允许test用户访问FTP

  1. [root@localhost ~]# vi /etc/vsftpd/user_list
  2. # vsftpd userlist
  3. # If userlist_deny=NO, only allow users in this file
  4. # If userlist_deny=YES (default), never allow users in this file, and
  5. # do not even prompt for a password.
  6. # Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
  7. # for users that are denied.
  8. root
  9. bin
  10. daemon
  11. adm
  12. lp
  13. sync
  14. shutdown
  15. halt
  16. mail
  17. news
  18. uucp
  19. operator
  20. games
  21. nobody
  22. test
  23. ~
  24. ~
  25. ~
  26. "/etc/vsftpd/user_list" 21L, 366C

5、建根目录,并设置访问权限

  1. [root@localhost ~]# mkdir /var/public_root
  2. [root@localhost ~]# chown -R test /var/public_root
  3. [root@localhost ~]# chmod -R 755 /var/public_root

6、防火墙设置

如果系统启用了防火墙和SELinux,那么还要做以下配置(默认情况下CentOS7是使用firewall和selinux的,不在使用iptables)

防火墙添加FTP服务

  1. [root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=ftp
  2. [root@localhost ~]# firewall-cmd --reload

设置SELinux

  1. [root@localhost ~]# getsebool -a | grep ftp
  2. [root@localhost ~]# setsebool -P ftpd_full_access on

或者修改配置文件彻底关闭selinux,需要重启机器(或者执行: setenforce 0)

  1. [root@localhost ~]# vi /etc/selinux/config
  2. # This file controls the state of SELinux on the system.
  3. # SELINUX= can take one of these three values:
  4. # enforcing - SELinux security policy is enforced.
  5. # permissive - SELinux prints warnings instead of enforcing.
  6. # disabled - No SELinux policy is loaded.
  7. SELINUX=disabled
  8. # SELINUXTYPE= can take one of three two values:
  9. # targeted - Targeted processes are protected,
  10. # minimum - Modification of targeted policy. Only selected processes are protected.
  11. # mls - Multi Level Security protection.
  12. #SELINUXTYPE=targeted

7、重启vsftpd服务器

  1. [root@localhost ~]# systemctl stop vsftpd.service
  2. [root@localhost ~]# systemctl start vsftpd.service
  3. [root@localhost ~]# systemctl status vsftpd.service

卸载vsftpd的方法

如果配置出错需要卸载vsftpd,在卸载之前先停止vsftpd

  1. [root@localhost ~]# rpm -aq vsftpd
  • 用rpm -e 查找结果 进行删除就ok了

    [root@localhost ~]# rpm -e vsftpd-3.0.2-21.el7.x86_64
    [root@localhost ~]# rpm remove vsftpd-3.0.2-21.el7.x86_64

8、 后记

最后我的不想吐槽 FileZilla—-真心不咋样,竟然不能下载,还以为我配置不行,用chinaftp没啥问题。蛋疼!

发表评论

表情:
评论列表 (有 0 条评论,417人围观)

还没有评论,来说两句吧...

相关阅读