最近公司项目中需要搭建FTP文件服务器,主要是用来解决大文件上传问题。

注:以下命令都是在已经关闭防火墙的前提下进行的

1、安装vsftpd

    $ yum install vsftpd -y

2、开启服务

$ systemctl start vsftpd
$ systemctl enable vsftpd

3、修改配置文件

打开vsftpd的配置文件,配置文件所在目录: /etc/vsftpd/vsftpd.conf ,目录内容如下所示:

在配置文件中分别放开或者添加以下配置:

# Example config file /etc/vsftpd/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=NO
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
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.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#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/xferlog
#
# 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. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# 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. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=NOpam_service_name=vsftpd
userlist_enable=NO
allow_writeable_chroot=YES
tcp_wrappers=YES
guest_enable=YES
guest_username=ftp
user_config_dir=/etc/vsftpd/config
max_clients=300
pasv_enable=YES
pasv_min_port=9001
pasv_max_port=9001
port_enable=YES

修改用户的配置文件,配置文件所在路径: /etc/vsftpd/config/ftp,内容如下所示:

local_root=/home/ftp
write_enable=YES
anon_umask=022
# cmds_denied=PASV,PORT,TYPE
# anon_world_readable_only=NO
# anon_upload_enable=YES
# anon_mkdir_write_enable=YES
# anon_other_write_enable=YES
guest_username=ftp
# nopriv_user=ftp
# pam_service_name=vsftpd
# guest_enable=YES
virtual_use_local_privs=YES
allow_writeable_chroot=YES
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
# cmds_allowed=PWD,LIST,PORT,TYPE,DELE,CWD
cmds_denied=

建立虚拟用户文件,命令如下:

#创建编辑用户文件
vim /etc/vsftpd/virtusers#第一行为用户名,第二行为密码。不能使用root作为用户名
ftp
123456789

生成虚拟用户数据文件,命令如下:

#设定PAM验证文件,并指定对虚拟用户数据库文件进行读取
$ db_load -T -t hash -f /etc/vsftpd/virtusers /etc/vsftpd/virtusers.db
$ chmod 600 /etc/vsftpd/virtusers.db

修改完后保存配置文件,执行以下命令让配置生效:

    $ systemctl restart vsftpd

4、安装vsftpd客户端

我们为了能更方便的调试vsftpd服务端安装是否成功,所以我们把客户端也顺便安装一波,命令如下:

    $ yum install lftp -y

5、创建ftp用户

首先创建用户目录,命令如下:

$ mkdir -p /home/ftp
$ chmod 777 /home/ftp

然后创建用户组、用户,命令如下:

$ groupadd ftp
$ useradd -g ftp -d /home/ftp ftp
$ usermod -s /sbin/login ftp

查看用户是否创建成功,命令如下:

    $ cat /etc/passwd

6、验证

我们通过之前安装的ftp客户端命令来进行验证,首先登陆ftp服务端,命令如下:

    $ lftp 192.168.65.128 -u ftp

登陆成功后我们就可以看到 ftp 这个用户被限制在他自己的用户目录下,其他目录是不可以到达的,我们通过xftp工具用 ftp 这个账号登录FTP文件服务器,图示如下:

发现当前用户同样被限制在自己所在用户目录中。

到此FTP文件服务器搭建完成。

Centos7 搭建FTP文件服务器相关推荐

  1. Ubuntu 搭建FTP文件服务器

    最近公司项目中需要搭建FTP文件服务器,主要是用来解决大文件上传问题. 注:以下命令都是在已经关闭防火墙的前提下进行的 1.安装vsftpd $ sudo apt install vsftpd 2.开 ...

  2. centos7搭建ftp,匿名用户访问

    centos7搭建ftp,匿名用户访问 注意 #安装服务 yum install vsftpd -ycd /etc/vsftpd mv vsftpd.conf vsftpd.conf.bak #编辑配 ...

  3. 搭建ftp文件服务器

    一搭建ftp服务器: (一)  切换到root用户:su root centos开桥接模式. 输入密码:xxxxx (二):修改/etc/vsftpd/vsftpd.conf文件下的属性 (三):YE ...

  4. WIN10家庭版搭建FTP文件服务器

    1.创建用户 和专业版本不一样的是,WIN10家庭版中是没有用户和组的,所以是直接在控制面板-用户账号中创建,具体的创建方式如下: 2.启动WINDOWS功能 3.在本地电脑上创建一个文件夹,用于FT ...

  5. CentOS7搭建简单文件服务器

    CentOS7使用nginx或httpd 搭建简单的文件服务器. nginx 搭建 安装nginx yum -y install nginx 修改配置文件, vim /etc/nginx/nginx. ...

  6. linux7.0ftp,Linux(Centos7)搭建FTP服务

    一.FTP的介绍. FTP是File Transfer Protocol()的英文简称,而中文简称为"文传协议".用于Internet上的的双向传输.同时,它也是一个(Applic ...

  7. centos7搭建FTP服务器

    1.  使用 yum 安装 vsftpd:yum install -y vsftpd 2. 启动 VSFTPD:systemctl start vsftpd.service 3. 启动后可监听到21端 ...

  8. CentOS7搭建ftp服务器(vsftpd,亲测成功)

    安装vsftpd sudo yum install vsftpd   配置参数 命令行输入 vim /etc/vsftpd.conf   使用如下配置 # Example config file /e ...

  9. [CentOs7]搭建ftp服务器(3)——上传,下载,删除,重命名,新建文件夹

    摘要 上篇文章介绍了如何为ftp添加虚拟用户,本篇将继续实践如何上传,下载文件. 上传 使用xftp客户端上传文件,如图所示 此时上传状态报错,查看详情 从错误看出是应为无法创建文件造成的.那么我们就 ...

最新文章

  1. Druid数据库连接池超时问题com.alibaba.druid.pool.GetConnectionTimeoutException: wait millis 1000, active 10
  2. Android常用知识点回顾
  3. ADO.NET笔记——带参数的查询防止SQL注入攻击
  4. Phoenix连接安全模式下的HBase集群
  5. 学习threeJS(一)--第一个threeJs
  6. Mongoose aggregate 多表关联查询
  7. EasyUI remote ajax方式提交验证
  8. OC算法练习-Hash算法
  9. C#-gdi绘图,双缓冲绘图,Paint事件的触发
  10. STM32F103RCT6移植到STM32F103C8T6注意事项
  11. 微信支付成功后发送短信通知
  12. Java SE 12 新增特性
  13. 家谱整站源码php_基于PHP语言的家谱网站的设计与实现.doc
  14. Python爬虫之爬取网站图片
  15. 蒸汽凝结水颜色发红十种常见除铁处理技术优劣对比
  16. C语言 | 常见问题汇总
  17. linux系统(压缩与解压缩,系统管理)
  18. lag和lead 分析函数
  19. 【NOIP2013初赛】整除
  20. linux logstash启动脚本,在Linux中从bash脚本启动时Logstash shutdown停止

热门文章

  1. 平面电磁波的反射与折射,极化滤波作用
  2. java访问数据库的中间件有哪些_数据库中间件是什么?
  3. 查看mysql版本命令_查看MySql版本号命令
  4. Nlog详解---非常详细
  5. SkeyeVSS露天焚烧高架视频监控解决方案
  6. 谷歌浏览器 手机/浏览器切换
  7. 求助帖,苹果U盘格式化 后手机不认
  8. C++语法(二)string和int、long int、float的转换
  9. 配置方法_怎么查看电脑配置?三个方法学起来
  10. Progressive Tree-Based Compression of Large-Scale Particle Data | 学习笔记