FTP服务器的搭建与安全配置

  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

转载于:https://www.cnblogs.com/lingerhk/p/4008023.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/359539.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C#值类型以及默认值记录下

C#的值类型有bool,byte,sbyte,decimal,double,float,int,uint,long,string等 如果我们擅长使用默认值,可以帮助我们减少带来赋值及代码编写. 比如我我经常赋值: int i0;下面都是各个值类型的默认值: bool>false byte,sbyte>0 int,uint,…

java泛型视频教程_Java泛型快速教程

java泛型视频教程泛型是Java SE 5.0引入的一种Java功能,在其发布几年后,我发誓那里的每个Java程序员不仅会听说过,而且已经使用过。 关于Java泛型,有很多免费和商业资源,而我使用的最佳资源是: Java教程 …

Windows上的Oracle Java

我最近为基于Windows 7的笔记本电脑下载了JDK 9的早期访问版本 (内部版本68 )。 由于这是早期版本,因此当自动安装在笔记本电脑上安装主要Java Runtime Environment(JRE)引入了一些不太理想的问题时,我并不…

DM oracle Mysql 查询数据库表和字段

-----------------------------------------------------ORALCE、DM select * from user_tab_comments;--查询当前用户下的表注释 select * from user_col_comments;--查询当前用户下的字段注释 select * from dba_tables ;--查询数据库实例下的表 属性 select * from dba_t…

java synchronized 对指定代码添加锁-简单样例

1:对静态代码添加锁 private final static Object syncLock new Object(); // 相当于线程锁,用于线程安全 public static int n0; public static void main(String[] args) { synchronized (syncLock){//锁 for(int i0;i<100;i) { n; Syst…

使用无锁的方式和有锁的方式的程序性能对比

这里分别使用有锁和无锁两种方式&#xff0c;对一个数值进行增加&#xff0c;一直增加到100000&#xff0c;然后输出使用时间的长短。 1 import java.util.concurrent.ExecutorService;2 import java.util.concurrent.Executors;3 import java.util.concurrent.TimeUnit;4 impo…

java pgp_Java相当好的隐私(PGP)

java pgp公钥加密 这篇文章讨论了PGP或“很好的隐私”。 PGP是常规加密和公用密钥加密的混合实现。 在详细介绍PGP之前&#xff0c;让我们先谈谈公钥加密。 与其他任何加密技术一样&#xff0c;公钥加密解决了通过不安全介质传输安全数据的问题。 即互联网。 结果&#xff0c;…

extjs弹出窗口查看文本内容-new Ext.Window

代码样例&#xff1a; function processscan(){ var text时间 用户 操作<br> 时间 用户 操作<br> 时间 用户 操作; var win new Ext.Window({ layout: fit, width: 700, height: 600, closeAction: hide, dra…

MySql默认编码所造成的乱码麻烦1.222

1、前言 MySQL在安装时&#xff0c;最后的一步&#xff0c;会让你选择MySQL服务器及客户端、数据库、连接接口的默认编码。通常可选择 UTF8和GB2312. 但是&#xff0c;如果你选择了utf8的时候&#xff0c;恰好你要从另一个数据库上迁移一个gb2312编码格式的数据库过来&#xff…

jquery(js) 增加 删除 修改属性样式、元素内容

引入jquery.js 1.增加或修改样式 $(#id).css(display,none);--根据id设置隐藏 2.$("#id").css({"background-color":"yellow","font-size":"200%"}); 3.增加或修改属性 $(#id).attr(readonly,true);--根据id设置标签属性…

构建自动化面板

上周二&#xff0c;我作为持续讨论&#xff08;&#xff03;c9d9&#xff09;的一部分&#xff0c;参加了一个关于Build Automation主题的在线讨论会&#xff0c;这是一系列有关敏捷&#xff0c;持续交付和DevOps的社区讨论会。 自动化构建流程面临许多挑战&#xff0c;包括第三…

Ioc Autofac心得

对于这个容器注入&#xff0c;个人也不是很熟悉&#xff0c;很多还不懂&#xff0c;只会基本的操作&#xff0c;几天把它记录下来&#xff0c;说不定以后帮助就大了呢&#xff0c;这方面跟安卓差距还是挺大的 下面记录下应用的流程 步骤&#xff1a; 1.添加应用 2.重写工厂&…

开启关闭mysql日志

//mysql开启sql日志 SET GLOBAL log_output TABLE;SET GLOBAL general_log ON; //mysql关闭sql日志 SET GLOBAL log_output TABLE; SET GLOBAL general_log OFF; ---查询mysql运行过的sql SELECT * from mysql.general_log ORDER BY event_time DESC;

深入学习Web Service系列----异步开发模式

概述 在本篇随笔中&#xff0c;通过一些简单的示例来说一下Web Service中的异步调用模式。调用Web Service方法有两种方式&#xff0c;同步调用和异步调用。同步调用是程序继续执行前等候调用的完成&#xff0c;而异步调用在后台继续时&#xff0c;程序也继续执行&#xff0c;不…

java 实现excel样式设置(居中、字体、大小、换行、合并行,列宽、指定特定字符串样式等)

HSSFWorkbook workbook new HSSFWorkbook(); Sheet sheet workbook.createSheet(); sheet.setColumnWidth(0, 30*256);//设置当前sheet页第一列宽度 sheet.setColumnWidth(1, 70*256);//第二列宽度 CellStyle style workbook.createCellStyle(); Font font workbook.cre…

可选依赖项

有时您正在编写的库可能具有可选的依赖项。 例如“如果apache http客户端在类路径上&#xff0c;请使用它&#xff1b;否则&#xff0c;请使用它。 否则–退回到HttpURLConnection”。 为什么要这么做&#xff1f; 由于各种原因–在分发库时&#xff0c;您可能不想强加较大的依…

XML-RPC协议学习

XML-RPC调用包括2部分&#xff1a;客户端client&#xff08;调用线程&#xff09;、服务器端server&#xff08;被调用的线程&#xff09;。服务端是通过特定的URL获得的&#xff0c;调用过程如下&#xff1a; 1.客户端程序使用XML-RPC客户端发出作业请求&#xff0c;指定方法名…

extjs tree 遍历树节点并设置选中

function initTreeChecked(){//获取根节点 var rootnoe Ext.getCmp("id").getRootNode();; setAllNodes(rootnoe); } //遍历所有节点 function setAllNodes(node){ setNodeChecked(node);//设置选中 var nodesnode.childNodes; for(var i0;i<…

Android开发中调用系统窗口的方法

//直接拨号 Intent callIntent new Intent(Intent.ACTION_CALL,Uri.parse("tel:12345678")); startActivity(callIntent); //将电话号码传入拨号程序 Intent dialIntent new Intent(Intent.ACTION_DIAL,Uri.parse("tel:12345678")); startActivity(dial…

navicate导出导入表数据问题

1.导出导入json&#xff0c;如下图&#xff0c;右击表点击导出向导&#xff0c;选择json导出类型&#xff0c;根据提示导出即可。 导入时&#xff0c;右击接收的表&#xff0c;点击导入向导&#xff0c;根据提示即可快速导入&#xff08;注&#xff1a;不同系统之间导出导入易…