CentOS7搭建匿名可访问的FTP服务器

所用版本:

  • CentOS7.9

  • vsftpd-3.0.2-25.e17.x86_64

概述

该文档主要为了实现用最简单的操作搭起windows平台和centos平台的FTP服务器,以便于两个平台间的文件传输操作。

实现步骤

第一步:检查是否已安装vsftpd

输入以下命令检查是否已安装vsftpd,显示结果有路径则为已安装,否则未安装。

    rpm -qa | grep vsftpd

第二步:关闭防火墙

为避免由于防火墙策略导致安装失败问题,需要先关闭防火墙,下面给出CentOS7版本下关闭防火墙的操作命令:

# Centos7 中使用 systemctl 命令来管理服务,命令格式如下
# systemctl [start 开启]|[stop 停止]|[restart 重启]|[status 状态][enable 开机启动]| [disable 禁止开机启动] 服务名称
[root@localhost ~]# systemctl start firewalld              # 开启防火墙
[root@localhost ~]# systemctl status firewalld             # 查看防火墙状态
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-08-08 09:18:09 CST; 24s ago           
         # active (running) 表示防火墙开启
     Docs: man:firewalld(1)
 Main PID: 21501 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─21501 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
 
Aug 08 09:18:07 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Aug 08 09:18:09 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
[root@localhost ~]# systemctl disable firewalld            # 永久关闭防火墙(重启生效)
[root@localhost ~]# systemctl stop firewalld               # 临时关闭防火墙(立即生效)
[root@localhost ~]# systemctl status firewalld             # 检查修改
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
         # inactive (dead) 表示防火墙关闭
     Docs: man:firewalld(1)

第三步:关闭Selinux

因为CentOS的所有访问权限都是由SELinux来管理的,为了避免我们安装中由于权限关系而导致的失败,需要先将其关闭,以后根据需要再进行重新管理。


[root@localhost ~]# getenforce                                         # 查看当前的 SELinux 状态
Enforcing
# setenforce 1 可以设置 SELinux 为 enforcing 模式
[root@localhost ~]# setenforce 0                                       # 将 SELinux 的状态临时设置为 Permissive 模式(立即生效)
[root@localhost ~]# getenforce                                         # 检查修改
Permissive
[root@localhost ~]# vim /etc/selinux/config                            
# 编辑 config 文件将 SELINUX=enforcing 修改为 SELINUX=disabled(重启生效)
[root@localhost ~]# cat /etc/selinux/config                            # 检查修改
 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
 
[root@localhost ~]# sestatus                                  # 查看 SELinux 当前的详细状态
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   permissive
Mode from config file:          disabled
Policy version:                 24
Policy from config file:        targeted

注意:使用 getenforce 命令获取当前 SELinux 的运行状态为 Permissive 或者 Disabled时均表示关闭。

第四步:修改vsftpd配置文件

修改vftpd配置文件,使其可以允许匿名访问。配置文件路径:/etc/vsftpd/vsftpd.conf

使用vi /etc/vsftpd/vsftpd.conf打开配置文件并将以下行取消注释:

#允许匿名访问
anonymous_enable=YES
#允许匿名用户上传文件
anon_upload_enable=YES
#允许匿名用户创建文件夹或文件
anon_mkdir_write_enable=YES
#设置匿名用户的登录目录(如需要,需自己添加并修改)
anon_root=/var/ftp/pub
#打开匿名用户删除和重命名的权限(如需要,需自己添加)
anon_other_write_enable=YES

第五步:赋权限给文件上传目录

必须赋予权限后才能上传下载文件,文件上传目录:/var/ftp/pub

chmod 777 /var/ftp/pub

第六步:重启vsftpd服务

#重启vftpd服务
systemctl restart vsftpd.service
#查看vftpd服务状态
systemctl status vsftpd.service

你可能感兴趣的:(CentOS7搭建匿名可访问的FTP服务器)