FTP可以说是Internet上使用非常广泛的一种通讯协议了。它工作在OSI模型的第7层,是TCP/IP的一种具体应用。FTP采用基于TCP的可靠连接:监听21端口来等待控制连接请求,当连接建立后,采用20号端口来建立数据传输通道。

  FTP中使用的一些典型消息:

    125  数据连接打开,传输开始

    200  命令OK

    331  用户名OK,需要输入密码

    425  不能打开数据连接

    452  错误写文件

    500  命令无法识别

  Vsftp是Linux系统下的一套开源FTP服务器软件,具有结构简单、性能优良的特点,是一款轻量型稳定安全的FTP。

  1.安装Vsftp。(测试环境:ContOS 6.5)

  查看本机有没有vsftp安装源:

~# rpm -qa | grep svftpd

  如果有,则会显示vsftp的版本,这样就可以直接安装:

~#  yum install vsftpd

  但我的上面貌似没有,只能下载源码编译了。Vsftp官网主页:http://vsftpd.beasts.org ,貌似进不去,网上找了下,可以在这里下载:站长之家 。版本是Vsftp v2.3.2 For Linux。解压编译:

~#  tar xvf vsftpd-2.3.2.tar.gz
~# cd ./vsftpd-2.3.2

  在此说明一下vsftpd-2.3.2目录下的builddefs.h文件,该文件主要用来设定FTP服务器的一些安全配置:CTP_Wrappers、PAM和SSL。可以按需要选择/取消。  

vim ./builddefs.h
#ifndef VSF_BUILDDEFS_H
#define VSF_BUILDDEFS_H #undef VSF_BUILD_TCPWRAPPERS //对TCP包进行解析的工具,用于限制某种服务的访问权限进而达到保护系统的目的。
#define VSF_BUILD_PAM //一种高效便利的用户级别的认证方式,用来加强服务器的安全性能。
#undef VSF_BUILD_SSL //利用加密技术,保障在传输过程中数据不会被窃听。 #endif /* VSF_BUILDDEFS_H */

  2.配置vsftpd.conf文件

  vsftpd.conf文件是主配置文件,在/etc/vsftpd/目录下.

# 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 //设置是否在改变目录后发送消息
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES //设置是否激活日志功能
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES //设置是否使用20端口传输数据(PORT模式)
#
# 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
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog //设置日志文件保存位置
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
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 //设置是否允许客户端使用sync等命令
#
# 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形式传输文件
# 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 //加入用户列表(前提是上面已经设置为YES)
#
# 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().
#chroot_local_user=YES //与下面配置有关
#chroot_list_enable=YES //设置是否允许本地用户离开其主目录
# (default follows)
#
//如果使用该项,则上面的chroot_local_user=YES需设置为NO。指定不能离开主目录的用户,将用户名一个一行写入指定文件。
#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 //设置是否开启IPV4监听
#
# 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 //设置是否开启IPV6监听 pam_service_name=vsftpd //设置访问所使用的PAM模块
userlist_enable=YES //如果激活该选项,将禁止所指定文件中的用户登录
tcp_wrappers=YES //设置是否使用TCP_Wrappers作为主机访问控制方式

3.配置ftpusers文件

ftpusers文件用于限定系统中那些用户能/不能使用FTP服务。可以根据实际情况添加/删除。

#User that are not allowed to login via ftp
root
...
...
...

4.配置user_list文件

 user_list文件指定的用户能否访问FTP服务器取决于userlist_deny选项的设置。默认为YES,即禁止user_list文件的用户访问FTP服务器,这与ftpusers文件相似。但是如果设置为NO,则完全相反,即只允许该文件列表里的用户访问该FTP服务器。

# vsftpd userlist
# If userlist_deny=NO,only allow users in this file
# If userlist_deny=YES(default),never allow users in this file,and do not even prompt for a password.
# ...
# ...
root
...

如果要限制指定的本地用户(即user_list文件的用户)不能访问FTP服务器,可以相应地修改vsftpd.conf文件:

userlist_enable=YES
userlist_deny=YES
userlist_file=/etc/vsftpd/user_list

同样,如果要限制指定的本地用户(即user_list文件的用户)能够访问FTP服务器,而其他的本地用户不能访问,可以相应地修改vsftpd.conf文件:

userlist_enable=YES
userlist_deny=NO
userlist_file=/etc/vsftpd/user_list

5.配置允许匿名用户使用FTP服务器

创建用户ftp-anon和目录/var/ftp-pub:

mkdir /var/ftp-pub
useradd -d /var/ftp-pub ftp-anon //-d 指定用户的主文件目录,vsftpd默认登录成功后的目录是该用户的home目录。

作为匿名访问,/var/ftp-pub不应该属于用户ftp-anon,也不应该有写权限,所以可以用以下方法修改其权限:

~# chown root.root /var/ftp-pub
~# og-w -d /var/ftp-pub

修改vsftpd.conf文件:

anonymous_enable=YES  //设置允许匿名访问(默认开启)
//设置允许匿名上传和创建目录(非必须,慎用!)
anon_upload_enable=YES
anon_mkdir_write_enable=YES

6.虚拟用户使用Vsftp服务器

上面的(包括一般的)ftp访问都是通过建立系统帐号来访问服务器的,这样很不安全,如果权限配置错误将会使服务器受到威胁。但是,通过建立虚拟FTP账户(与系统帐号分离),就可以大大增强系统的安全性。虚拟FTP账户只能用于文件传输,也叫guest用户。它是把用户名/密码保存起来,再验证的。所以Vsftp需要一个系统用户的身份来读取数据(用户名/密码)文件,即guest用户,用以映射虚拟用户。

具体配置如下:

(1)生成虚拟用户口令库文件。以下为例:

~# vim login.txt
zhangsan //username1
hehe //passwd1
lisi //username2
mimanicai //passwd2
......

(2)配置生成Vsftp的认证文件

保存并退出,使用db_load命令生成口令库文件:

~#  db_load -T -t hash -f login.txt /etc/vsftpd/vsftpd_login.db

修改口令库文件的权限:

chmod 600 /etc/vsftpd/vsftpd_login.db

编辑虚拟用户所需的PAM配置文件

~# vim /etc/pam.d/vsftpd
//加入以下两行:
auth required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login.db
account required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login.db

(3)建立虚拟用户访问的目录,并设置相应的访问权限

~# useradd -d /home/ftp virtual
~# chmod 700 /home/ftp

(4)建立配置文件

~# cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
~# vim /etc/vsftpd/vsftpd.conf
//配置如下:
anonymous_enable=YES
local_enable=YES
write_enable=YES
anon_upload_enable=NO
anon_mkdir_write_enable=NO
listen=YES
guest_enable=YES
guest_username=virtual

(5)重启Vsftp服务器

~# service vsftpd restart

至此,虚拟用户使用Vsftp服务器配置将完成了。可以使用login.txt里的用户帐号登录FTP服务器了。

7.改变Vsftp的端口号

在vsftpd.conf文件里加入如下,并重启vsftp。

~# listen_port=2121

8.配置Vstfp服务器的chroot

chroot就是为登录用户指定一个固定的目录,这个目录一般是用户的主目录,用户被限制在该目录下,类似与WEB服务器的虚拟目录,从而保护了系统安全。

设置指定的用户执行chroot:

chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list

相关参考文章: http://wiki.ubuntu.org.cn/Vsftpd

FTP服务器的搭建与安全配置的更多相关文章

  1. ubuntu 14.04 下FTP服务器的搭建--锁定用户目录,解决vsftpd: refusing to run with writable root inside chroot()

    FTP服务器的搭建,我要实现的需求是: 不允许匿名访问,因为我的机器不想让谁都能登录上来,随便获取文件, 需要锁定一个目录,因为在家里,我需要给媳妇下载一些电影 韩剧之类的东西,媳妇会来我机器下载,但 ...

  2. Ubuntu 14.04 下FTP服务器的搭建

    FTP服务器的搭建,我要实现的需求是: 不允许匿名访问,因为我的机器不想让谁都能登录上来,随便获取文件, 需要锁定一个目录,因为在家里,我需要给媳妇下载一些电影 韩剧之类的东西,媳妇会来我机器下载,但 ...

  3. Linux:FTP服务器的搭建

    FTP服务器的简介 系统用户 即系统本机的用户.Linux一般不会针对实体用户进行限制,因此实体用户可以针对整个文件 系统进行工作.但通常不希望他们通过FTP方式远程访问系统. 虚拟用户 只能采用FT ...

  4. 自学linux——18.FTP服务器的搭建

    Centos7下FTP服务器的搭建 一.FTP的作用 文件传输协议(File Transfer Protocol,FTP),是一种在互联网中进行文件传输的协议,基于客户端/服务器模式,默认使用 20. ...

  5. 【FTP】FTP服务器的搭建

    记录一下FTP服务器的搭建首先打开 程序和功能>打开或关闭Windows功能 进入到Windows功能界面:勾选FTP服务器.然后再在IIS界面,新建一个网站.右键网站,选择“添加到FTP发布” ...

  6. FTP服务器的搭建与配置

    主要来源:http://www.cnblogs.com/helonghl/articles/5533857.html 1.安装FTP服务器: yum install vsftpd -y 2.启动FTP ...

  7. Ubuntu14.04下FTP服务器的搭建配置 标签: ubuntuftp服务器虚拟机 2017-06-13 15:24 161人阅读 评

    首先说明一下,我是在虚拟机中装的Ubuntu14.04,物理机是Win10,最初只是为了在两个系统间传输文件才在Ubuntu中安装了ftp服务器,从Windows端登陆其即可.最初也是按照网上的各种教 ...

  8. Linux篇---ftp服务器的搭建

    一.前述 企业中linux搭建ftp服务器还是很实用的,所以本文针对centoos7和centoos6搭建服务器教程做个总结. 二.具体 1.显示如下图则表示已安装 vsftp软件.如果未显示则需要安 ...

  9. Linux中FTP服务器的搭建

    vmware12上安装的CentOs6.8,最终实现物理机上的windows10能正常访问CentOs上的FTP服务器. 一.查看是否安装有ftp相关的安装包. # rpm -qa | grep vs ...

随机推荐

  1. java 面向对象 — 继承

    继承中的构造方法,先执行父类中的构造方法,然后执行子类中的构造方法 继承中的属性,最后执行的属性 覆盖前面的属性 因为是开辟了 两个内存空间,所以相比较是不同的. 如果想比较两个对象的值是否相同的话, ...

  2. bzoj 3615: MSS

    Description 小C正在出一道题...因为语文水平有限他想不出复杂的背景,所以以下就是题意了. 平面上有N个点,开始时每个点属于一个不同的集合.不妨设点Pi属于集合Si.请维护数据结构支持以下 ...

  3. Y480&Y580 刷slic2.1全自动教程

    由于之前时间赶,写得比较乱,现在我重新把我.安装UltraISO.2.插上一个U盘.3.用UltraISO打开setup98.img镜像4.在UltraISO的“启动”的下拉菜单里选择“写入硬盘镜像” ...

  4. 新手之:SpringBoot ——Reids主从哨兵整合(CentOS7)

    一.Redis主从搭建(一台服务器模拟多个端口) 结构图:) 1.确保安装了Redis,我装在了/opt/redis目录下.可通过"whereis redis-cli"命令查看是否 ...

  5. 九、创建Slave节点

    通常情况下,我们的项目会由多个模块或者系统组成,不同模块可能会分别部署在不同的服务器,比如mod1部署在ser1,mod2部署在ser2上: 之前的文档是描述了将jenkins也部署在ser1上,当m ...

  6. WPF MVVM

    MVVM全称:Model-View-ViewModel 优点:MVVM的引入使程序实现了松耦合设计,UI层与业务逻辑可以并行设计 1.Model:对现实世界的抽象 比如:需要做一个学校的管理系统,学校 ...

  7. 拦截TextBox 双击消息

    Option Explicit Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLo ...

  8. Android bitmap转byte

    逆转start协议输出 private static byte[] bitmap2byte(Bitmap bmp) throws Exception{ return bitmap2byte(bmp, ...

  9. js中获取父节点,兄弟节点及处理属性节点

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  10. CentOS Linux最常用命令及快捷键整理

    最近一直在对CentOS系统进行各种体验,为方便自己也方便他人,整理了Linux常用命令及快捷键,不过其实大多和DOS是一样的,只是命令的表达上可能有点儿不一样. 常用Linux命令: 文件和目录: ...