Debian 8下vsftpd安装与配置

0.环境

root@remote:/# uname -r
3.16.0-4-amd64
root@remote:/e# lsb_release
No LSB modules are available.
root@remote:/# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 8.6 (jessie)
Release: 8.6
Codename: jessie

1.安装

hubery@remote:~$ sudo apt-get install vsftpd ftp -y

2.配置

重启vsftpd后才能使得更改的配置生效sudo systemctl restart vsftpd

默认配置:

hubery@remote:~$ cat /etc/vsftpd.conf | grep -v "^#" | grep -v "^$"
listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO

此时vsftpd已经在运行:

hubery@remote:~$ sudo systemctl status vsftpd.service
● vsftpd.service - vsftpd FTP server
Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled)
Active: active (running) since 四 2016-12-29 02:55:14 EST; 5min ago
Main PID: 17653 (vsftpd)
CGroup: /system.slice/vsftpd.service
└─17653 /usr/sbin/vsftpd /etc/vsftpd.conf 12月 29 02:55:14 remote systemd[1]: Started vsftpd FTP server.
hubery@remote:~$ sudo netstat -lpn | grep vsftpd
tcp6 0 0 :::21 :::* LISTEN 17653/vsftpd

(1)新建用户

vsftp使用系统用户来登陆,任何可以登录系统的用户都可以登陆vsftpd

hubery@remote:~$ ftp localhost
Connected to localhost.
220 (vsFTPd 3.0.2)
Name (localhost:hubery):
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 221 Goodbye.

但是为了安全,我们创建普通用户,这个用户可以登录vsfptd,但是不能SSH登陆系统

hubery@remote:~$ sudo bash -c "echo '/bin/false' >> /etc/shells"
hubery@remote:~$ sudo useradd -m jack -s /bin/false
hubery@remote:~$ sudo passwd jack
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
hubery@remote:~$ ls ~jack
hubery@remote:~$ sudo dd if=/dev/zero of=~jack/file.64MB bs=1M count=64
64+0 records in
64+0 records out
67108864 bytes (67 MB) copied, 0.0278935 s, 2.4 GB/s
hubery@remote:~$ ls -lh ~jack
total 64M
-rw-r--r-- 1 root root 64M 12月 29 03:14 file.64MB
hubery@remote:~$ su jack
Password:
hubery@remote:~$ echo $?
1

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

hubery@remote:~$ ftp -d -v localhost
Connected to localhost.
220 (vsFTPd 3.0.2)
ftp: setsockopt: Bad file descriptor
Name (localhost:hubery): jack
---> USER jack
331 Please specify the password.
Password:
---> PASS XXXX
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
Login failed.
---> SYST
421 Service not available, remote server has closed connection
ftp> ---> QUIT
221 Goodbye.

配置文件/etc/vsftpd.conf添加一行allow_writeable_chroot=YES,重启vsftpd

hubery@remote:~$ cd tmp/
hubery@remote:~/tmp$ dd if=/dev/zero of=file.32MB bs=1M count=16
16+0 records in
16+0 records out
16777216 bytes (17 MB) copied, 0.0147825 s, 1.1 GB/s
hubery@remote:~/tmp$ ls
file.32MB
hubery@remote:~/tmp$ ftp -d -v localhost
Connected to localhost.
220 (vsFTPd 3.0.2)
ftp: setsockopt: Bad file descriptor
Name (localhost:hubery): jack
---> USER jack
331 Please specify the password.
Password:
---> PASS XXXX
230 Login successful.
---> SYST
215 UNIX Type: L8
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
ftp: setsockopt (ignored): Permission denied
---> EPRT |2|::1|59080|
200 EPRT command successful. Consider using EPSV.
---> LIST
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 67108864 Dec 29 03:14 file.64MB
226 Directory send OK.
ftp> !ls
/bin/bash
file.32M
ftp> ---> QUIT
221 Goodbye.

(3)PORT(主动)模式、PASV(被动)模式

FTP两种模式的区别:

(1)PORT(主动)模式

所谓主动模式,指的是FTP服务器“主动”去连接客户端的数据端口来传输数据,其过程具体来说就是:客户端从一个任意的非特权端口N(N>1024)连接到FTP服务器的命令端口(即tcp 21端口),紧接着客户端开始监听端口N+1,并发送FTP命令“port N+1”到FTP服务器。然后服务器会从它自己的数据端口(20)“主动”连接到客户端指定的数据端口(N+1),这样客户端就可以和ftp服务器建立数据传输通道了。

(2)PASV(被动)模式

所谓被动模式,指的是FTP服务器“被动”等待客户端来连接自己的数据端口,其过程具体是:当开启一个FTP连接时,客户端打开两个任意的非特权本地端口(N >1024和N+1)。第一个端口连接服务器的21端口,但与主动方式的FTP不同,客户端不会提交PORT命令并允许服务器来回连它的数据端口,而是提交PASV命令。这样做的结果是服务器会开启一个任意的非特权端口(P > 1024),并发送PORT P命令给客户端。然后客户端发起从本地端口N+1到服务器的端口P的连接用来传送数据。(注意此模式下的FTP服务器不需要开启tcp 20端口了)

两种模式的比较:

(1)PORT(主动)模式模式只要开启服务器的21和20端口,而PASV(被动)模式需要开启服务器大于1024所有tcp端口和21端口。

(2)从网络安全的角度来看的话似乎ftp PORT模式更安全,而ftp PASV更不安全,那么为什么RFC要在ftp PORT基础再制定一个ftp PASV模式呢?其实RFC制定ftp PASV模式的主要目的是为了数据传输安全角度出发的,因为ftp port使用固定20端口进行传输数据,那么作为黑客很容使用sniffer等探嗅器抓取ftp数据,这样一来通过ftp PORT模式传输数据很容易被黑客窃取,因此使用PASV方式来架设ftp server是最安全绝佳方案。

因此:如果只是简单的为了文件共享,完全可以禁用PASV模式,解除开放大量端口的威胁,同时也为防火墙的设置带来便利。

不幸的是,FTP工具或者浏览器默认使用的都是PASV模式连接FTP服务器,因此,必须要使vsftpd在开启了防火墙的情况下,也能够支持PASV模式进行数据访问。

(4)配置PASV主动模式

iptables配置: 主动模式使用20端口来传输数据,需要同时打开

hubery@remote:~$ sudo iptalbes -I INPUT 4 -m state --state NEW -p tcp --dport 21 -j ACCEPT
hubery@remote:~$ sudo iptalbes -I INPUT 4 -m state --state NEW -p tcp --dport 20 -j ACCEPT

尽管如此,由于vsftpd需要主动连接ftp客户端监听的端口,导致部分操作失败。这样就需要关闭客户端所在机器的防火墙www@localhost:~$ sudo iptables -F

ftp> ls
ftp: setsockopt (ignored): Permission denied
---> PORT 192,168,0,156,86,3
200 PORT command successful. Consider using PASV.
---> LIST
425 Failed to establish connection.

(5)配置PASV被动模式

因为主动模式下需要关闭客户机的防火墙,加上使用固定端口20传输数据易被抓取,被动模式才是被广泛采用的模式。默认状态下,vsftpd使用任意非特权端口传输数据,这里给它限定一个范围7000~800,在配置文件后添加下面两句。

pasv_enable=yes
pasv_min_port=7000
pasv_max_port=8000

并配置防火墙`sudo iptables -I INPUT 4 -p tcp --dport 7000:8000 -j ACCEPT'

加载内核模块(可能不是必选项),

root@remote:/# modprobe ip_conntrack_ftp
root@remote:/# modprobe ip_nat_ftp

永久加载需要在/etc/modules-load.d/modules.conf文件尾添加

ip_conntrack_ftp
ip_nat_ftp

ftp被动模式连接ftp -p remoteIP

(6)配置SSL安全连接

编辑/etc/vsftpd.conf去注释或添加

pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=YES
force_local_data_ssl=NO
force_local_logins_ssl=NO
require_cert=NO

配置之后:

root@remote:/# cat /etc/vsftpd.conf | grep -v "^#" | grep -v "^$"
listen=NO
listen_ipv6=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
ascii_upload_enable=YES
ascii_download_enable=YES
ftpd_banner=Welcome to blah FTP service.
chroot_local_user=YES
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=YES
force_local_data_ssl=NO
force_local_logins_ssl=NO
require_cert=NO
allow_writeable_chroot=YES
pasv_enable=yes
pasv_min_port=7000
pasv_max_port=8000

参考:

vsftpd doc

vsftpd的主动模式与被动模式

vsftpd被动模式配置

vsftpd:500 OOPS: vsftpd: refusing to run with writable root inside chroot ()错误的解决方法

Installing and configuring FTP server vsftpd.

vsftpd与/bin/false、/sbin/nologin

Debian 8下vsftpd安装与配置的更多相关文章

  1. centos下vsftpd安装与配置

    1.已经配置好可以上网了,所以即可通过yum install vsftpd安装啦.如果不能上网则可以通过dvd2.iso工具集rpm方式进行安装. 2.安装好后,默认本地可以通过匿名用户登录,但是其它 ...

  2. 烂泥:ubuntu下vsftpd虚拟用户配置

    本文由ilanniweb提供友情赞助,首发于烂泥行天下 想要获得更多的文章,可以关注我微信ilanniweb. 以前搭建vsftpd都是在centos下,本以为在ubuntu按照以前的步骤搭建即可.可 ...

  3. [转]CentOS 5.5下FTP安装及配置

    一.FTP的安装 1.检测是否安装了FTP : [root@localhost ~]# rpm -q vsftpd vsftpd-2.0.5-16.el5_5.1 否则显示:[root@localho ...

  4. [转]非常好的vsftpd安装于配置

    环境:CentOS 5.0 操作系统一.安装:1.安装Vsftpd服务相关部件:[root@KcentOS5 ~]# yum install vsftpd*Dependencies Resolved= ...

  5. libCURL开源库在VS2010环境下编译安装,配置详解

    libCURL开源库在VS2010环境下编译安装,配置详解 转自:http://my.oschina.net/u/1420791/blog/198247 http://blog.csdn.net/su ...

  6. Windows下pry安装和配置

    Windows下pry安装和配置 pry是一个增强型的交互式命令行工具,比irb强大. 有自动完成功能,自动缩进,有颜色.有更强大的调试功能. pry 安装很简单. 在终端输入: gem instal ...

  7. [moka同学摘录]在Centos 6.5下成功安装和配置了vim7.4

    来源:https://my.oschina.net/gzyh/blog/266097 资源下载地址: 链接:http://pan.baidu.com/s/1kVuaV5P 密码:xkq9   摘要: ...

  8. Windows Server 2003 下如何安装及配置 FTP 服务器(转)

    Windows Server 2003 下如何安装及配置 FTP 服务器 一.安装 FTP 服务器组件: 写在这里的一点 : 安装及配置 FTP 服务器之前 , 必须先手工配置服务器本身的 IP 地址 ...

  9. Linux下MySQL安装和配置

    --Linux下MySQL安装和配置 ---------------------------2014/05/18 Linux下MySQL的配置和安装 本文的安装采用 rpm 包安装 1.首先在官网下载 ...

随机推荐

  1. APP测试之登录

    我们公司产品登录很简单 手机号为账号,每次登录输入短信验证码.验证码为6位数字.登陆后可以记录登录状态.未登录时可以微信登录然后验证或者APP登录后可以在个人中心绑定微信. 一APP内部登录 1.手机 ...

  2. MySQL优化的奇技淫巧之STRAIGHT_JOIN

    原文地址:http://huoding.com/2013/06/04/261 问题 通过「SHOW FULL PROCESSLIST」语句很容易就能查到问题SQL,如下: SELECT post.* ...

  3. Android中webview和js之间的交互(转)

    http://www.cnblogs.com/leizhenzi/archive/2011/06/29/2093636.html 1.android中利用webview调用网页上的js代码. Andr ...

  4. hdu4044 GeoDefense

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4044 题意:一个树上的塔防游戏.给你n个结点的树,你要在树结点上建塔防御,在第 i 个结点上有 ki ...

  5. (转) PowerDesigner逆向工程导入MYSQL数据库总结

    PowerDesigner逆向工程导入MySQL数据库总结 由于日常数据建模经常使用PowerDesigner,使用逆向工程能更加快速的生成模型提高效率,所以总结使用如下: 1.      安装MYS ...

  6. app进入后台之后接收到通知,点进去进入新的页面,再次进入后台,再点击通知进入页面(,两次通过通知进入的页面,创建了两次,会多一个页面,)解决办法监听

    在点击通知进入的页面的 //UIApplicationWillResignActiveNotification是app即将进入后台的方法 //增加监听使它在进入后台之前pop上一个页面 - (void ...

  7. S_ISREG等几个常见的宏(转)

    来自百度文库:http://wenku.baidu.com/view/31777dc1d5bbfd0a795673b1.html stat函数讲解: 表头文件: #include <sys/st ...

  8. Storyboard中segue(转场)使用

    源引:http://www.2cto.com/kf/201210/161737.html 一.视图切换类型介绍在storyboard中,segue有几种不同的类型,在iphone和ipad的开发中,s ...

  9. Linux用户和组的管理操作

    用户和组的管理操作 命令中涉及的单词和简写: 用户:user:组:group : 增加:add :  修改:modify  mod ;  删除 : delete  del 增加用户     /etc/ ...

  10. Android内部自带的SQLite数据库操作dos命令

    1:什么叫做SQLite数据库 Android系统内核是Linux系统,Android系统很特殊,他自带了一个SQLite数据库,轻量型的一款嵌入式的数据库 它占用资源非常的低,在嵌入式设备中,可能只 ...