Centos 7 搭建FTP详细配置步骤方法

vsftpd的安裝使用:

ftp概述:FTP(File Transfer protocol,文件传输协议)是经典的C/S架构的应用层协议,需要有服务端软件,客户端软件两个部共同组成实现文件传输功能。

主程序包:/usr/sbin/vsftpd

服务名:vsftpd

用户控制列表文件:

 /etc/vsftpd/ftpusers,/etc/vsftpd/user_list

主配置文件:/etc/vsftpd/vsftpd.conf

启动脚本:/etc/rc.d/init.d/vsftpd

[[email protected] mnt]# yum -y install vsftpd    安装vsftpd服务

[[email protected] mnt]# systemctl start vsftpd.service    启动vsftpd服务

[[email protected] mnt]# netstat -tunlp           查看vsftpd服务是否启动,端口为:21

此时可以访问vsftpd默认提供的站点服务;ftp://192.168.214.140,提供站点的访问资源路径为:[[email protected] pub]# cd /var/ftp/pub 下;

vim /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=YES  //开启匿名用户

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    //启用任何形式的写入权限,(如上传,删除文件等)都需要开启此项
efault 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  //目录消息(在目录下切换时会提醒,在目录新建一个(.message文件)在里面填写提示的内容)
#
# Activate logging of uploads/downloads.
xferlog_enable=YES //激活上载/下载的日志记录。
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES  //确保端口传输连接来自端口20(FTP数据)。
#
# 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  //是否改变上传文件的属主,改变谁呢,统一改变whoever用户,和下面选项关联
chown_username=whoever //改变上传的属主
#
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/xferlog  //启用xferlog日志,默认记录到:/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 //启用标准的xferlog日志格式,若禁用此项,将使用vsftpd自己的日志格式;
#
# 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  运行 vsftpd 需要的非特权系统用户,缺省是nobody

# 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 //是否将FTP本地用户禁锢在宿主目录中;
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=NO //是否以独立的运行的方式监听服务;
#
# 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=YES

pam_service_name=vsftpd  //vsftpd使用pam完成用户认证
userlist_enable=YES       //是否启用控制用户登陆列表文件;:/etc/vsftpd/user_list;

userlist_deny=YES|NO        //路径为:/etc/vsftpd/user_list;
tcp_wrappers=YES

自定义添加:

连接限制:

  max_clients:最大并发连接数;

  max_per_ip:每个IP可同时发起的并发请求数;

传输速率: 

  anon_max_rate:匿名用户的最大传输速率,单位是“字节”

  local_max_rate:本地用户的最大传输速率,单位是“字节”

虚拟用户:

  所以的虚拟用户会被统一映射为一个指定的系统账号,访问的共享位置既为此系统账号的家目录;

  各虚拟用户可以被赋予不同的访问权限;通过匿名用户的权限控制参数进行指定;

虚拟用户账号的存储方式:

    文件:编辑文件指定,奇数行为用户名,偶数为行的密码;  此文件需要被编码为hash格式;

    关系型数据库众的表中:既时查询数据库完成用户认证; mysql库:pam要依赖与pam-mysql, yum -y install pam_mysql

  

-------------------------------------------------------------------------------

实验:

一::开放匿名用户配置,并启动vsftpd服务;

  anonymous_enable=yes             //允许匿名用户访问

  local_enable=YES                //若不需要启用本地用户,可将此项设为NO;

  write_enable=YES       //开放服务器的写权限

  anon_umask=022                 //设置匿名用户上传数据的权限掩码

  anon_upload_enable=YES    //允许匿名上传文件

  anon_upload_write_enable=YES  //允许匿名用户创建目录

关闭匿名访问:anonymous_enable=NO,此时重启服务在此刷新则需要用户名和密码验证;

2:测试匿名FTP服务器;

[[email protected] pub]# yum -y install ftp

[[email protected] pub]# ftp 192.168.214.140
Connected to 192.168.214.140 (192.168.214.140).
220 (vsFTPd 3.0.2)
Name (192.168.214.140:root): ftp
331 Please specify the password.
Password:      //默认密码为空
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls     //查看ftp服务器众的内容
227 Entering Passive Mode (192,168,214,140,210,168).
150 Here comes the directory listing.
drwxr-xr-x    2 0        0              19 Dec 10 09:42 pub
226 Directory send OK.

可以在/var/ftp/新建一个目录;

给权限:setfacl -m u:root:rwx  upload

在配置文件中修改或添加:anon_ohter_write_enable=YES 才可以进行删除;

在进行测试:
ftp> lcd /opt      //将本地目录切换到/opt

ftp> get vsftpdconf.tar.gz  //将文件下载到本地(/opt/目录)

ftp> cd put     //将ftp目录切换到/pub

ftp> put install.log  //将文件上传到服务器(pub/目录)

ftp> ls        //查看所上传文件的权限

ftp> quit       //断开ftp链接并退出

二:vsftpd的用户验证

1:配置本地用户验证

  vim /etc/vsftpd/vsftpd.conf

  local_enable=YES  

  write_enabl=YES  

  local_umask=022

  chroot_local_user=YES

2:使用user_list用户列表

当vsftpd服务器开放了“local_enable”配置以后,默认情况下所以的系统服务用户都可以登陆到次FTP服务器,若只希望对一小部分用户开放FTP服务,则需要开放用户列表控制的相关配置,其中主要包含userlist_enable,userlist_deny,例如:执行一下操作后vsftpd服务器将只允许laya,vanko,hunter三个用户登陆。

[[email protected] vsftpd]# vim /etc/vsftpd/user_list

laya
vanko
hunter

[[email protected] vsftpd]# vim /etc/vsftpd/vsftpd.conf

userlist_enable=YES

userlist_deny=NO

systemctl restart vsftpd.service

就可以测试验证了:

ftp://192.168.214.140

这时会报错:

 vsftpd : 500 OOPS: vsftpd: refusing to run with writable root inside chroot ()

解决方法:[[email protected] vsftpd]# vim /etc/vsftpd/vsftpd.conf
allow_writeable_chroot=YESsystemctl restart vsftpd.service

这时使用账户就可以访问了,使用其他用户则拒绝登陆;

其他:

前两小结中分别做了学习匿名访问,用户验证的FTP服务器基本配置,除此以为还用一下其他的常用配置,许需要我们有一定的了解

1:修改vsftpd服务的监听地址,端口

vim /etc/vsftpd/vsftp.conf

  listen=YES  //允许独立监听服务  listen_address=192.168.4.11  //只在一个接口监听服务  listen_port=2121        //监听端口为2121[[email protected] vsftpd]# service restart vsftpd[[email protected] vsftpd]#netstat -anpt | grep vsftpd2:允许使用FTP服务器的被动模式vim /etc/vsftpd/vsftp.conf     pasv_enable=YES    //允许被动模式连接

  pasv_min_port=24500  //指定被动模式下限端口

  pasv_max_port=24600  //指定被动模式的上限端口

[[email protected] vsftpd]# service restart vsftpd

3:限制FTP连接的并发数,传输速度

 vim /etc/vsftpd/vsftp.conf

   max_client=20    //限制并发客户端连接最多20个

  max_per_ip=2    //限制每个IP地址的连接数最多2个

  anan_max_rate=50000  //限制匿名用户传输速度为50kB/s

  local_max_rate=200000  //限制本地用户传输速率为200kB/s

[[email protected] vsftpd]# service restart vsftpd

三:基于虚拟用户的FTP服务

1:创建文本格式的用户名称,密码列表

  [[email protected] vsftpd]# vim /etc/vsftpd/vusers.list

  mike

  123

  john  

  456

2:创建Berkeley DB格式的数据库文件

[[email protected] vsftpd]# cd /etc/vsftpd/
[[email protected] vsftpd]# db_load -T -t hash -f vusers.list vusers.db
[[email protected] vsftpd]# file vusers.db
vusers.db: Berkeley DB (Hash, version 9, native byte-order)[[email protected] vsftpd]# chmod 600 /etc/vsftpd/vusers.*
[[email protected] vsftpd]# ls -lh /etc/vsftpd/vsftpd.*
-rw-------. 1 root root 5.0K 12月 12 21:05 /etc/vsftpd/vsftpd.conf
-rw-------. 1 root root 5.0K 12月 12 20:44 /etc/vsftpd/vsftpd.conf.bak
3:添加虚拟用户的映射账号,创建FTP根目录

[[email protected] vsftpd]# useradd -d /var/ftproot -s /sbin/nologin virtual
[[email protected] vsftpd]# chmod 755 /var/ftproot/
4:为vsftpd服务添加虚拟用户支持

 1:为虚拟用户建立PAM认证文件
      vim /etc/pam.d/vsftpd.vu
      #%PAM-1.0
      auth    required        pam_userdb.so db=/etc/vsftpd/vusers
      account required        pam_userdb.so db=/etc/vsftpd/vusers

 2:修改vsftpd配置,添加虚拟用户支持

 vim /etc/vsftpd/vsftpd.conf
   anonymous_enable=NO
   local_enable=YES
   wirte_enable=YES
   anon_umask=022
   guest_enable=YES
   guest_username=virtual
   pam_service_name=vsftpd.vu

3:为不同的虚拟用户建立独立的配置文件

  vim /etc/vsftpd/vsftpd.conf

    user_config_dir=/etc/vsftpd/vusers_dir

    [[email protected] vsftpd]# mkdir /etc/vsftpd/vusers_dir
    [[email protected] vsftpd]# cd /etc/vsftpd/vusers_dir/
    [[email protected] vusers_dir]# vim john

      anon_upload_enable=YES

      anon_mkdir_write=YES

  [[email protected] vusers_dir]# touch mike
  [[email protected] vusers_dir]# systemctl restart vsftpd.service

  ?:mike用户可以登陆,并能够正常浏览,下载文件,但不能上传文件。  

?:john用户可以登陆,且能够正常流量,下载文件,也可以上传文件。

  ?:Linux主机的系统用户将无法登陆;

  

  

 

  

userlist_deny=NO

时间: 2024-07-29 01:15:18

Centos 7 搭建FTP详细配置步骤方法的相关文章

关于腾讯云服务器使用FTP详细配置教程

1.腾讯云服务器介绍 2.关于腾讯云服务器使用感受 3.作为开发者使用过程中遇到的问题 4.腾讯云服务器FTP Server环境搭建 5.腾讯云常见FTP客户端安装方法及注意事项 首先非常感谢CSDN联合腾讯云提供的免费云资源,我是一个开发者,目前从事软件外包.教育培训相关工作.在技术方面还可以,但是在服务器管理方面还欠缺很多知识,所以遇到了一些问题,顺便花点时间研究下,把自己的心得分享给大家,供大家学习交流. 1.腾讯云服务器介绍 腾讯云(http://www.qcloud.com)-腾讯公司

CentOS+Nginx+PHP+MySQL详细配置(图解)

原文地址: http://www.jb51.net/article/26597.htm CentOS+Nginx+PHP+MySQL详细配置(带有图解),需要的朋友可以参考下. 一.安装MySQL 目前web服务器已经很少有跑静态页面的,如果要跑动态网站那当然就离不开数据库,虽然在以前文章中有写MySQL是怎么安装的,但是感觉好久没装MySQL,现在只把步骤贴出来,就不做过多的讲解了 #useradd mysql #tar zxvf mysql-5.0.40.tar.gz #cd mysql-5

(总结)CentOS Linux搭建SVN Server配置详解

PS:今天给开发的同事搭建一个公网的SVN Server,google一下,发现下面这篇最详细,就记录下来,重新排版一下.顺便根据自己的使用经验,补充了几个细节和总结.本文配置是基于CentOS 5.x的,但一样适用于其他Linux发行版! SVN简介和工作原理 subversion(简称svn)是近几年崛起的版本管理软件,是cvs的接班人,目前绝大多数开源软件都使用svn作为代码版本管理软件.Subversion支持linux和windows,但较多安装在linux下. svn服务器有两种运行

CentOS 下搭建FTP服务器

vsftpd是Linux下比较著名的FTP服务器,搭建FTP服务器当然首选这个.本文介绍了在CentOS 6 4下安装vsftpd.配置虚拟用户登录FTP的过程.正 vsftpd是Linux下比较著名的FTP服务器,搭建FTP服务器当然首选这个. 本文介绍了在CentOS 6.4下安装vsftpd.配置虚拟用户登录FTP的过程. 正文: 一:安装vsftpd 查看是否已经安装vsftpd 1 2 3 4 rpm -qa | grep vsftpd #如果没有,就安装,并设置开机启动 yum -y

CentOS Linux搭建SVN Server配置详解

SVN简介和工作原理 subversion(简称svn)是近几年崛起的版本管理软件,是cvs的接班人,目前绝大多数开源软件都使用svn作为代码版本管理软件.Subversion支持linux和windows,但较多安装在linux下. svn服务器有两种运行方式:独立服务器和借助于apache. svn://或http://svn客户端tortoisesvnsvn的基本工作原理: 在一台服务器上建立一个源代码库,库里可以存放许多不同项目的源程序.有源代码库管理员统一管理这些源程序.每个用户在使用

Centos下搭建ftp服务器

一.  FTP 说明 linux 系统下常用的FTP 是vsftp, 即Very Security File Transfer Protocol. 还有一个是proftp(Profession ftp). 我们这里也是简单的说明下vsftp的配置. vsftp提供3种远程的登录方式: (1)匿名登录方式 就是不需要用户名,密码.就能登录到服务器电脑里面 (2)本地用户方式 需要帐户名和密码才能登录.而且,这个帐户名和密码,都是在你linux系统里面,已经有的用户. (3)虚拟用户方式 同样需要用

生产环境搭建ftp并配置虚拟用户

虚拟用户的特点是只能访问服务器为其提供的FTP服务,而不能访问系统的其它资源.所以,如果想让用户对FTP服务器站内具有写权限,但又不允许访问系统其它资源,可以使用虚拟用户来提高系统的安全性.在VSFTP中,认证这些虚拟用户使用的是单独的口令库文件(pam_userdb),由可插入认证模块(PAM)认证. 虚拟用户并非系统上的用户,但它必须映射到系统上的某个用户,虚用户的家目录属主和属组就这系统上的这个用户.并且每个虚用户有自己的用户名和密码,每个虚用户也可以单独设定对家目录的访问权限.使用文件的

Centos 下搭建FTP上传下载服务器

首先判断你服务器上是否安装了vsftpd 安装vsftpd #yum -y install vsftpd 安装完成之后就要重启vsftpd服务 到vsftpd的主配置文件里面 把这个改为NO 默认是YES (改为NO 就是禁止匿名用户登录,不需要注释) 不可以让ftp用户跳出自己的家目录,否则太危险了,需要做限制 默认是注释掉的,把#号去掉 然后重启vsftpd 创建ftp用户 (yuanfei这个用户智能连接ftp无法登录系统,默认家目录是在var/www/html 文件夹下面) 给yuanf

在CentOS 7中安装与配置Tomcat-8方法

安装前提 在CentOS 7中安装与配置JDK8 安装tomcat  apache-tomcat-8.0.14.tar.gz文件上传到/usr/local中执行以下操作: [root@localhost ~]# cd /usr/local [root@localhost ~]# tar -zxv -f apache-tomcat-8.0.14.tar.gz // 解压压缩包 [root@localhost ~]# rm -rf apache-tomcat-8.0.14.tar.gz // 删除压