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
FTP服务器的搭建与安全配置的更多相关文章
- ubuntu 14.04 下FTP服务器的搭建--锁定用户目录,解决vsftpd: refusing to run with writable root inside chroot()
FTP服务器的搭建,我要实现的需求是: 不允许匿名访问,因为我的机器不想让谁都能登录上来,随便获取文件, 需要锁定一个目录,因为在家里,我需要给媳妇下载一些电影 韩剧之类的东西,媳妇会来我机器下载,但 ...
- Ubuntu 14.04 下FTP服务器的搭建
FTP服务器的搭建,我要实现的需求是: 不允许匿名访问,因为我的机器不想让谁都能登录上来,随便获取文件, 需要锁定一个目录,因为在家里,我需要给媳妇下载一些电影 韩剧之类的东西,媳妇会来我机器下载,但 ...
- Linux:FTP服务器的搭建
FTP服务器的简介 系统用户 即系统本机的用户.Linux一般不会针对实体用户进行限制,因此实体用户可以针对整个文件 系统进行工作.但通常不希望他们通过FTP方式远程访问系统. 虚拟用户 只能采用FT ...
- 自学linux——18.FTP服务器的搭建
Centos7下FTP服务器的搭建 一.FTP的作用 文件传输协议(File Transfer Protocol,FTP),是一种在互联网中进行文件传输的协议,基于客户端/服务器模式,默认使用 20. ...
- 【FTP】FTP服务器的搭建
记录一下FTP服务器的搭建首先打开 程序和功能>打开或关闭Windows功能 进入到Windows功能界面:勾选FTP服务器.然后再在IIS界面,新建一个网站.右键网站,选择“添加到FTP发布” ...
- FTP服务器的搭建与配置
主要来源:http://www.cnblogs.com/helonghl/articles/5533857.html 1.安装FTP服务器: yum install vsftpd -y 2.启动FTP ...
- Ubuntu14.04下FTP服务器的搭建配置 标签: ubuntuftp服务器虚拟机 2017-06-13 15:24 161人阅读 评
首先说明一下,我是在虚拟机中装的Ubuntu14.04,物理机是Win10,最初只是为了在两个系统间传输文件才在Ubuntu中安装了ftp服务器,从Windows端登陆其即可.最初也是按照网上的各种教 ...
- Linux篇---ftp服务器的搭建
一.前述 企业中linux搭建ftp服务器还是很实用的,所以本文针对centoos7和centoos6搭建服务器教程做个总结. 二.具体 1.显示如下图则表示已安装 vsftp软件.如果未显示则需要安 ...
- Linux中FTP服务器的搭建
vmware12上安装的CentOs6.8,最终实现物理机上的windows10能正常访问CentOs上的FTP服务器. 一.查看是否安装有ftp相关的安装包. # rpm -qa | grep vs ...
随机推荐
- [C++ Primer] 第6章: 函数
参数传递 const形参和实参: 顶层const作用于对象本身, 和其他初始化过程一样, 当用实参初始化形参时会忽略掉顶层const, 换句话说, 形参顶层const被忽略掉了, 当形参有顶层cons ...
- springboot利用MockMvc测试controller控制器
主要记录一下控制器的测试,service这些类测试相对简单些(可测试性强) API测试需求比较简单: ① 需要返回正确的http状态码 200 ② 需要返回json数据,并且不能返回未经捕获的系统异常 ...
- 在Linux中安装Oracle(较详细图解)
原创 http://www.cnblogs.com/nucdy/p/5603998.html 参考视屏:链接: https://pan.baidu.com/s/1kViEZQZ 密码: z7ha ( ...
- 根据现有表操作基于active record的model
指南上都是直接生成mode,然后db migrate来生成数据库,在现实场景中,很可能是反过来的 例如 测试表app_versions rails里面,建立model class AppVersion ...
- 简化Redis数据访问代码RedisTemplate
---恢复内容开始--- Redis数据结构简介: Redis可以存储键与5中数据结构类型之间的映射,这5中数据结构类型分别是;String(字符串),List(列表),Set(集合),Hash(散列 ...
- C++ 实例化对象 p->printX()
一.从栈实例化对象 我们首先定义一个类,类的名字叫TV,里面包括两个成员变量,两个成员函数. class TV // 定义一个电视的类TV { public: ]; // 定义类的属性,一个数组 in ...
- 十、jdk工具之Jdb命令(The Java Debugger)
目录 一.jdk工具之jps(JVM Process Status Tools)命令使用 二.jdk命令之javah命令(C Header and Stub File Generator) 三.jdk ...
- PyDev for eclipse 插件下载地址
PyDev for eclipse 插件下载地址http://sourceforge.net/projects/pydev/files/pydev/python解释器以及python类库下载地址htt ...
- requests and BeautifulSoup
requests Python标准库中提供了:urllib.urllib2.httplib等模块以供Http请求,但是,它的 API 太渣了.它是为另一个时代.另一个互联网所创建的.它需要巨量的工作, ...
- git/github基本命令
Git与项目 git的使用,主要包括: 本地仓库的命令 远程仓库的命令 项目需求.页面.模型类的设计,及页面的使用 sudo apt-get install git 安装成功后,运行如下命令 git ...