![](http://ovuhiuqqd.bkt.clouddn.com/vsftpd_logo.png)
目录
Vsftpd
vsftpd
:Very Secure FTP Daemon
, CentOS
默认FTP服务器。
- 用户认证配置文件:
/etc/pam.d/vsftpd
- 服务脚本:
/usr/lib/systemd/system/vsftpd.service
/etc/rc.d/init.d/vsftpd
- 配置文件:
/etc/vsftpd/vsftpd.conf
man 5 vsftpd.conf
- 格式:
option=value
- 注意:
=
前后不要有空格
- 匿名用户(映射为系统用户
ftp
)共享文件位置:/var/ftp
- 系统用户共享文件位置:用户家目录
- 虚拟用户共享文件位置:为其映射的系统用户的家目录
Vsftpd服务配置
命令端口
[root@centos7 ~]# systemctl start vsftpd # 启动vsftpd服务
[root@centos7 ~]# ss -tnul # 默认开启端口为21
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 127.0.0.1:323 *:*
udp UNCONN 0 0 *:27830 *:*
udp UNCONN 0 0 *:68 *:*
udp UNCONN 0 0 ::1:323 :::*
udp UNCONN 0 0 :::61443 :::*
tcp LISTEN 0 128 *:22 *:*
tcp LISTEN 0 100 127.0.0.1:25 *:*
tcp LISTEN 0 80 :::3306 :::*
tcp LISTEN 0 32 :::21 :::*
tcp LISTEN 0 128 :::22 :::*
tcp LISTEN 0 100 ::1:25 :::*
[root@centos7 ~]# cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak # 备份配置文件
[root@centos7 ~]# cd /etc/vsftpd/
[root@centos7 vsftpd]# ls
ftpusers user_list vsftpd.conf vsftpd.conf.bak vsftpd_conf_migrate.sh
[root@centos7 vsftpd]# vim vsftpd.conf # 修改配置文件把端口修改为123
listen_port=123 # 添加此行
[root@centos7 vsftpd]# systemctl restart vsftpd
[root@centos7 vsftpd]# ss -tnul
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 127.0.0.1:323 *:*
udp UNCONN 0 0 *:27830 *:*
udp UNCONN 0 0 *:68 *:*
udp UNCONN 0 0 ::1:323 :::*
udp UNCONN 0 0 :::61443 :::*
tcp LISTEN 0 128 *:22 *:*
tcp LISTEN 0 100 127.0.0.1:25 *:*
tcp LISTEN 0 80 :::3306 :::*
tcp LISTEN 0 128 :::22 :::*
tcp LISTEN 0 100 ::1:25 :::*
tcp LISTEN 0 32 :::123 :::*
主动和被动模式
配置文件:主动模式端口
connect_from_port_20=YES 主动模式端口为20
ftp_data_port=20 指定主动模式的端口
实现主动模式端口
[root@centos7 ~]# cd /var/ftp/pub/ # 现在ftp服务器上面创建一个大文件
[root@centos7 ftp]# dd if=/dev/zero of=f1 bs=1G count=1
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 15.2404 s, 70.5 MB/s
[root@centos6 ~]# ftp 192.168.8.140 # 使用gcentos6区连接ftp服务器
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.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 # 列出
227 Entering Passive Mode (192,168,8,140,42,104).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 1073741824 Oct 13 01:26 f1
drwxr-xr-x 2 0 0 6 Nov 05 2016 pub
226 Directory send OK.
ftp> ? # 查看帮助
Commands may be abbreviated. Commands are:
! debug mdir sendport site
$ dir mget put size
account disconnect mkdir pwd status
append exit mls quit struct
ascii form mode quote system
bell get modtime recv sunique
binary glob mput reget tenex
bye hash newer rstatus tick
case help nmap rhelp trace
cd idle nlist rename type
cdup image ntrans reset user
chmod lcd open restart umask
close ls prompt rmdir verbose
cr macdef passive runique ?
delete mdelete proxy send
ftp> passive # 关闭被动模式,就相当于开启主动模式
Passive mode off.
ftp> get f1 # 下载f1文件
local: f1 remote: f1
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for f1 (1073741824 bytes).
[root@centos7 vsftpd]# netstat -anp | grep ftp # 回到ftp服务器上面查看,已经打开20端口传输数据
tcp6 0 0 :::21 :::* LISTEN 2186/vsftpd
tcp6 0 4039920 192.168.8.140:20 192.168.8.128:46817 ESTABLISHED 2222/vsftpd
tcp6 0 0 192.168.8.140:21 192.168.8.128:35124 ESTABLISHED 2220/vsftpd
unix 3 [ ] STREAM CONNECTED 20963 2220/vsftpd
unix 3 [ ] STREAM CONNECTED 20964 2222/vsftpd
unix 2 [ ] DGRAM 21608 2220/vsftpd
使用主动模式的端口为123
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf
connect_from_port_20=YES
ftp_data_port=123 # 修改主动模式的端口为123
[root@centos6 ~]# ftp 192.168.8.140 # 再次连接ftp服务器
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> passive # 开启主动模式
Passive mode off.
ftp> get f1
local: f1 remote: f1
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for f1 (1073741824 bytes).
[root@centos7 vsftpd]# netstat -anp | grep ftp # 查看数据传输端口已经为123
tcp6 0 0 :::21 :::* LISTEN 2248/vsftpd
tcp6 0 0 192.168.8.140:21 192.168.8.128:35126 ESTABLISHED 2249/vsftpd
tcp6 0 3601472 192.168.8.140:123 192.168.8.128:39712 ESTABLISHED 2251/vsftpd
unix 3 [ ] STREAM CONNECTED 22784 2249/vsftpd
unix 2 [ ] DGRAM 21760 2249/vsftpd
unix 3 [ ] STREAM CONNECTED 22785 2251/vsftpd
被动模式端口范围
linux客户端默认使用被动模式
windows 客户端默认使用主动模式
pasv_min_port=6000 0为随机分配
pasv_max_port=6010
使用被动模式传输
[root@centos6 ~]# !ftp # 直接访问ftp服务器
ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.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
227 Entering Passive Mode (192,168,8,140,193,204).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 1073741824 Oct 13 01:26 f1
drwxr-xr-x 2 0 0 6 Nov 05 2016 pub
226 Directory send OK.
ftp> get f1 # 下载f1文件
local: f1 remote: f1
227 Entering Passive Mode (192,168,8,140,78,255).
150 Opening BINARY mode data connection for f1 (1073741824 bytes).
[root@centos7 vsftpd]# netstat -anp | grep ftp # 在centos7上面查看开启的端口是随机开启的
tcp6 0 0 :::21 :::* LISTEN 2271/vsftpd
tcp6 0 0 192.168.8.140:20223 :::* LISTEN 2272/vsftpd
tcp6 0 3714120 192.168.8.140:20223 192.168.8.128:44845 ESTABLISHED 2274/vsftpd
tcp6 0 0 192.168.8.140:21 192.168.8.128:35128 ESTABLISHED 2272/vsftpd
ftp> !rm -f f1 # 删除本地文件f1,加上!可以执行本地命令
ftp> get f1 # 下载f1文件
local: f1 remote: f1
227 Entering Passive Mode (192,168,8,140,73,74).
150 Opening BINARY mode data connection for f1 (1073741824 bytes).
226 Transfer complete.
1073741824 bytes received in 6.76 secs (158891.58 Kbytes/sec)
[root@centos7 vsftpd]# netstat -anp | grep ftp # 查看端口是随机打开的
tcp6 0 0 192.168.8.140:18762 :::* LISTEN 2272/vsftpd
tcp6 0 0 :::21 :::* LISTEN 2271/vsftpd
tcp6 0 3991160 192.168.8.140:18762 192.168.8.128:58139 ESTABLISHED 2274/vsftpd
tcp6 0 0 192.168.8.140:21 192.168.8.128:35128 ESTABLISHED 2272/vsftpd
指定被动模式端口范围
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf
pasv_min_port=8000 # 最小端口为8000
pasv_max_port=8001 # 最大端口为8001
[root@centos7 vsftpd]# !sys #重启服务让其生效
systemctl restart vsftpd
[root@centos6 ~]# !ftp # 连接下载数据
ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> get f1
local: f1 remote: f1
227 Entering Passive Mode (192,168,8,140,31,65).
150 Opening BINARY mode data connection for f1 (1073741824 bytes).
[root@centos7 vsftpd]# netstat -anp | grep ftp # 查看端口已经是我们打开的8001
tcp6 0 0 :::21 :::* LISTEN 2289/vsftpd
tcp6 0 0 192.168.8.140:8001 :::* LISTEN 2291/vsftpd
tcp6 0 3844440 192.168.8.140:8001 192.168.8.128:39485 ESTABLISHED 2293/vsftpd
tcp6 0 0 192.168.8.140:21 192.168.8.128:35130 ESTABLISHED 2291/vsftpd
使用当地时间
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf
use_localtime=YES # 使用当地时间(默认为NO,使用GMT)
[root@centos7 vsftpd]# !sys
systemctl restart vsftpd
[root@centos6 ~]# ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.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 # 看的不是特别明显,因为原来时间就是对的
227 Entering Passive Mode (192,168,8,140,169,47).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 1073741824 Oct 13 09:26 f1
drwxr-xr-x 2 0 0 6 Nov 06 2016 pub
226 Directory send OK.
匿名用户
anonymous_enable=YES 支持匿名用户
no_anon_password=YES(默认NO) 匿名用户略过口令检查
anon_world_readable_only (默认YES)只能下载全部读的文件
anon_upload_enable=YES 匿名上传,注意:文件系统权限
anon_mkdir_write_enable=YES
anon_other_write_enable=YES 可删除和修改上传的文件
anon_umask=077 指定匿名上传umask
chown_uploads=YES(默认NO)
chown_username=wang 指定上传文件的默认的所有者
chown_upload_mode=0644 指定上传文件的默认的权限
使匿名可以用户上传文件
解决方法为:
1. 修改配置文件使匿名用户可以上传和创建文件
2. 因为ftp默认是不支持登陆根就有w权限的,所以在ftp创建一个可以上传的目录,并对其设置ACL,让其拥有rwx权限,就可以了。
3. ftp上传文件需要注意:文件系统上面的权限和vsftpd上面配置的权限。
[root@centos6 ~]# dd if=/dev/zero of=f2 bs=1G count=1 # 先创建一个测试文件f2
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 14.6191 s, 73.4 MB/s
[root@centos6 ~]# ftp 192.168.8.140 # 连接ftp
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.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
227 Entering Passive Mode (192,168,8,140,176,223).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 1073741824 Oct 13 01:26 f1
drwxr-xr-x 2 0 0 6 Nov 05 2016 pub
226 Directory send OK.
ftp> put f2 # 传输文件失败,权限被拒绝
local: f2 remote: f2
227 Entering Passive Mode (192,168,8,140,173,117).
550 Permission denied.
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf # 修改配置文件
anon_mkdir_write_enable=YES
anon_upload_enable=YES
[root@centos7 vsftpd]# !sys
systemctl restart vsftpd
[root@centos6 ~]# ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> put f2 # 上传还是失败
local: f2 remote: f2
227 Entering Passive Mode (192,168,8,140,122,54).
550 Permission denied.
[root@centos7 ftp]# setfacl -m u:ftp:rwx pub # 使ftp用户对pub目录拥有rwx权限
[root@centos7 ftp]# ll
total 1048576
-rw-r--r-- 1 root root 1073741824 Oct 13 09:26 f1
drwxrwxr-x+ 2 root root 6 Oct 13 10:51 pub
[root@centos7 ftp]# getfacl pub
# file: pub
# owner: root
# group: root
user::rwx
user:ftp:rwx
group::r-x
mask::rwx
other::r-x
[root@centos6 ~]# ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub
250 Directory successfully changed.
ftp> put f2 # 已经可以上传
local: f2 remote: f2
227 Entering Passive Mode (192,168,8,140,122,181).
150 Ok to send data.
226 Transfer complete.
1073741824 bytes sent in 13.4 secs (79893.42 Kbytes/sec)
Linux系统用户
guest_enable=YES 所有系统用户都映射成guest用户
guest_username=ftp 配合上面选项才生效,指定guest用户
local_enable=YES 是否允许linux用户登录
write_enable-YES 允许linux用户上传文件
local_umask=022 指定系统用户上传文件的默认权限
local_root=/ftproot 非匿名用户登录所在目录
所有系统用户都映射成guest用户
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf # 修改配置文件
guest_enable=YES
guest_username=ftp
[root@centos7 vsftpd]# useradd haiyun
[root@centos7 vsftpd]# passwd haiyun
Changing password for user haiyun.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@centos7 vsftpd]# !sys
systemctl restart vsftpd
[root@centos6 ~]# ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root): haiyun
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp> 221 Goodbye.
[root@centos6 ~]# ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root): haiyun
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,8,140,154,38).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 1073741824 Oct 13 01:26 f1
drwxrwxr-x 2 0 0 16 Oct 13 02:53 pub
226 Directory send OK.
禁锢所有系统用户在家目录中
chroot_local_user=YES(默认NO,不禁锢)禁锢系统用户
ftp> [root@centos6 ~]# ftp 192.168.8.140 # 默认是可以切换到根目录的
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root): haiyun
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,8,140,97,169).
150 Here comes the directory listing.
226 Directory send OK.
ftp> pwd
257 "/home/haiyun"
ftp> cd /
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,8,140,135,197).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 6 Oct 05 16:31 app
lrwxrwxrwx 1 0 0 7 Oct 05 16:31 bin -> usr/bin
dr-xr-xr-x 4 0 0 4096 Oct 10 13:52 boot
drwxr-xr-x 19 0 0 3200 Oct 13 01:21 dev
drwxr-xr-x 80 0 0 8192 Oct 13 03:21 etc
drwxr-xr-x 3 0 0 20 Oct 13 03:20 home
lrwxrwxrwx 1 0 0 7 Oct 05 16:31 lib -> usr/lib
lrwxrwxrwx 1 0 0 9 Oct 05 16:31 lib64 -> usr/lib64
drwxr-xr-x 2 0 0 6 Nov 05 2016 media
drwxr-xr-x 2 0 0 6 Nov 05 2016 mnt
drwxr-xr-x 2 0 0 6 Nov 05 2016 opt
dr-xr-xr-x 128 0 0 0 Oct 13 2017 proc
dr-xr-x--- 2 0 0 142 Oct 13 03:20 root
drwxr-xr-x 20 0 0 560 Oct 13 01:29 run
lrwxrwxrwx 1 0 0 8 Oct 05 16:31 sbin -> usr/sbin
drwxr-xr-x 2 0 0 6 Oct 05 16:31 script
drwxr-xr-x 2 0 0 6 Nov 05 2016 srv
dr-xr-xr-x 13 0 0 0 Oct 13 2017 sys
drwxrwxrwt 8 0 0 236 Oct 13 02:51 tmp
drwxr-xr-x 13 0 0 155 Oct 05 16:31 usr
drwxr-xr-x 20 0 0 278 Oct 13 01:24 var
226 Directory send OK.
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf # 修改配置文件
chroot_local_user=YES
[root@centos7 vsftpd]# !sys
systemctl restart vsftpd
[root@centos6 ~]# ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root)haiyun
331 Please specify the password.
Password:
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
Login failed.
421 Service not available, remote server has closed connection
ftp> [root@centos6 ~]# ftp 192.168.8.140 # 连接失败
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root):
530 Permission denied.
Login failed.
[root@centos7 home]# ll
total 0
drwx------ 2 haiyun haiyun 62 Oct 13 11:20 haiyun
[root@centos7 home]# chmod -w haiyun/ # 去掉w权限就可以了
[root@centos7 home]# ll
total 0
dr-x------ 2 haiyun haiyun 62 Oct 13 11:20 haiyun
[root@centos6 ~]# ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root): haiyun
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,8,140,87,198).
150 Here comes the directory listing.
226 Directory send OK.
ftp> pwd
257 "/"
禁锢或不禁锢特定的系统用户在家目录中,与上面设置功能相反
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
当chroot_local_user=YES时,则chroot_list中用户不禁锢
当chroot_local_user=NO时, 则chroot_list中用户禁锢
[root@centos7 home]# useradd test # 添加测试用户
[root@centos7 home]# passwd test
Changing password for user test.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf # 修改配置文件
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
[root@centos7 ftp]# cd /etc/vsftpd/ # 把test用户添加到chroot_list中
[root@centos7 vsftpd]# echo "test" > chroot_list
[root@centos7 vsftpd]# cat chroot_list
test
[root@centos6 ~]# ftp 192.168.8.140 # 连接测试
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root): haiyun
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/"
ftp> 221 Goodbye.
[root@centos6 ~]# ftp 192.168.8.140 # 连接测试
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root): test
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/test"
ftp> 221 Goodbye.
wu-ftp日志:默认启动
xferlog_enable=YES (默认) 启用记录上传下载日志
xferlog_std_format=YES (默认)使用wu-ftp日志格式
xferlog_file=/var/log/xferlog (默认)可自动生成
查看wu-ftp日志
[root@centos7 home]# tail /var/log/xferlog
Fri Oct 13 09:38:48 2017 8 ::ffff:192.168.8.128 1073741824 /f1 b _ o a ? ftp 0 * c
Fri Oct 13 09:39:29 2017 8 ::ffff:192.168.8.128 1073741824 /f1 b _ o a ? ftp 0 * c
Fri Oct 13 09:45:31 2017 9 ::ffff:192.168.8.128 1073741824 /f1 b _ o a ? ftp 0 * c
Fri Oct 13 09:47:48 2017 7 ::ffff:192.168.8.128 1073741824 /f1 b _ o a ? ftp 0 * c
Fri Oct 13 09:51:31 2017 8 ::ffff:192.168.8.128 1073741824 /f1 b _ o a ? ftp 0 * c
Fri Oct 13 10:36:19 2017 1 ::ffff:192.168.8.128 0 /f2 b _ i a ? ftp 0 * i
Fri Oct 13 10:36:23 2017 1 ::ffff:192.168.8.128 0 /f2 b _ i a ? ftp 0 * i
Fri Oct 13 10:48:52 2017 1 ::ffff:192.168.8.128 0 /pub/f2 b _ o a ? ftp 0 * i
Fri Oct 13 10:51:12 2017 2 ::ffff:192.168.8.128 357091608 /pub/f2 b _ i a ? ftp 0 * c
Fri Oct 13 10:54:02 2017 14 ::ffff:192.168.8.128 1073741824 /pub/f2 b _ i a ? ftp 0 * c
vsftpd日志:默认不启用
dual_log_enable=YES 使用vsftpd日志格式,默认不启用
vsftpd_log_file=/var/log/vsftpd.log(默认)可自动生成
开启vsftpd日志并查看
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf # 修改配置文件
dual_log_enable=YES
vsftpd_log_file=/var/log/vsftpd.log
[root@centos7 home]# !sys
systemctl restart vsftpd
root@centos6 ~]# ftp 192.168.8.140 # 访问测试
Connected to 192.168.8.140 (192.168.8.140).
220 (vsFTPd 3.0.2)
Name (192.168.8.140:root): haiyun
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,8,140,254,209).
150 Here comes the directory listing.
226 Directory send OK.
ftp> ls
227 Entering Passive Mode (192,168,8,140,73,11).
150 Here comes the directory listing.
226 Directory send OK.
ftp> ls
227 Entering Passive Mode (192,168,8,140,225,241).
150 Here comes the directory listing.
226 Directory send OK.
ftp> get f1
local: f1 remote: f1
227 Entering Passive Mode (192,168,8,140,169,98).
550 Failed to open file.
ftp> 221 Goodbye.
[root@centos7 home]# tail /var/log/vsftpd.log # 查看日志
Fri Oct 13 11:42:41 2017 [pid 11671] CONNECT: Client "::ffff:192.168.8.128"
Fri Oct 13 11:42:45 2017 [pid 11670] [haiyun] OK LOGIN: Client "::ffff:192.168.8.128"
Fri Oct 13 11:43:07 2017 [pid 11672] [haiyun] FAIL DOWNLOAD: Client "::ffff:192.168.8.128", "/home/haiyun/f1", 0.00Kbyte/sec
登陆提示信息
两种方法
ftpd_banner=“welcome to mage ftp server"
banner_file=/etc/vsftpd/ftpbanner.txt 优先上面项生效
方法一,优先生效
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf # 修改配置文件
ftpd_banner="Welcome to blah haiyun FTP service."
[root@centos7 home]# systemctl restart vsftpd
[root@centos6 ~]# ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220 "Welcome to blah haiyun FTP service."
Name (192.168.8.140:root): haiyun
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
方法二
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf # 修改配置文件
banner_file=/etc/vsftpd/ftpbanner.txt
[root@centos7 vsftpd]# pwd
/etc/vsftpd
[root@centos7 vsftpd]# touch ftpbanner.txt
[root@centos7 vsftpd]# echo "http://www.ihaiyun.cc/" > ftpbanner.txt
[root@centos7 home]# systemctl restart vsftpd
[root@centos6 ~]# ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220-http://www.ihaiyun.cc/
220
Name (192.168.8.140:root): haiyun
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
目录访问提示信息
dirmessage_enable=YES (默认)
message_file=.message(默认)信息存放在指定目录下.message
目录访问提示信息实现
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf # 查看配置文件,因为此项默认就是开启的
dirmessage_enable=YES
message_file=.message # 此项可以修改文件名
root@centos7 home]# cd /var/ftp/
[root@centos7 ftp]# mkdir test # 创建测试目录
[root@centos7 ftp]# echo "This is a test dir" > test/.message # 测试信息
[root@centos6 ~]# ftp 192.168.8.140
Connected to 192.168.8.140 (192.168.8.140).
220-http://www.ihaiyun.cc/
220
Name (192.168.8.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
227 Entering Passive Mode (192,168,8,140,125,170).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 1073741824 Oct 13 01:26 f1
drwxrwxr-x 2 0 0 16 Oct 13 02:53 pub
drwxr-xr-x 2 0 0 22 Oct 13 03:53 test
226 Directory send OK.
ftp> cd test
250-This is a test dir # 已经看到测试信息
250 Directory successfully changed.
ftp>
传输速率: 字节/秒
传输速率: 字节/秒
anon_max_rate=0 匿名用户的最大传输速率
local_max_rate=0 本地用户的最大传输速率
传输速率实现
[root@centos7 vsftpd]# vim /etc/vsftpd/vsftpd.conf # 修改配置文件
anon_max_rate=1024000
local_max_rate=1024000000
[root@centos7 ftp]# systemctl restart vsftpd
[root@centos7 ftp]# dd if=/dev/zero of=ftest bs=1024M count=2 # 生成测试文件
2+0 records in
2+0 records out
2147483648 bytes (2.1 GB) copied, 25.5866 s, 83.9 MB/s
[root@centos7 haiyun]# ln /var/ftp/ftest ftest
[root@centos7 haiyun]# pwd
/home/haiyun
匿名用户测速
![](http://ovuhiuqqd.bkt.clouddn.com/test-ftp1.gif)
普通用户测速
![](http://ovuhiuqqd.bkt.clouddn.com/test-ftp2.gif)
连接时间:秒为单位
connect_timeout=60 主动模式数据连接超时时长
accept_timeout=60 被动模式数据连接超时时长
data_connection_timeout=300 数据连接无数据输超时时长
idle_session_timeout=60 无命令操作超时时长
优先以文本方式传输
- ascii:文本方式传输数据,可能会破坏数据。例如:把windows的文本文件通过ftp下载到linux上面,会进行转换。那么如果传输一个图片的话可能会把图片破坏。
- binary:二进制方式传输数据
ascii_upload_enable=YES
ascii_download_enable=YES
Centos 6 配置VSFTPD为非独立服务
[root@centos6 ~]# vim /etc/vsftpd/vsftpd.conf # 修改配置文件
listen=NO
[root@centos6 ~]# cat /etc/xinetd.d/vsftpd # 此文件默认是不存在的,需要手动写一份
service ftp
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/vsftpd
log_on_failure += USERID
disable = no
}
[root@centos6 ~]# ss -tnul
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 *:68 *:*
tcp LISTEN 0 128 :::22 :::*
tcp LISTEN 0 128 *:22 *:*
tcp LISTEN 0 100 ::1:25 :::*
tcp LISTEN 0 100 127.0.0.1:25 *:*
[root@centos6 ~]# service xinetd start
Starting xinetd: [ OK ]
[root@centos6 ~]# ss -tnul #端口已经打开
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 *:68 *:*
tcp LISTEN 0 64 :::21 :::*
tcp LISTEN 0 128 :::22 :::*
tcp LISTEN 0 128 *:22 *:*
tcp LISTEN 0 100 ::1:25 :::*
tcp LISTEN 0 100 127.0.0.1:25 *:*
[root@centos6 ~]# netstat -anp | grep 21 # 可以看到21端口是有xinetd服务监听的
tcp 0 0 :::21 :::* LISTEN 1891/xinetd
unix 3 [ ] DGRAM 10021 492/udevd
[root@centos7 ~]# ftp 192.168.8.128 #
Connected to 192.168.8.128 (192.168.8.128).
220 (vsFTPd 2.2.2)
Name (192.168.8.128:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
[root@centos6 ~]# netstat -anp | grep 21 # 再次查看21端口是由vsftpd提供服务的
tcp 0 0 192.168.8.128:21 192.168.8.140:46626 ESTABLISHED 1901/vsftpd
tcp 0 0 :::21 :::* LISTEN 1891/xinetd
unix 3 [ ] DGRAM 10021 492/udevd