533442 发表于 2016-11-14 09:44:34

vsftp安装及配置

一、安装

1
2
3
4
5
6
# 安装vsftpd
yum -y installvsftpd
# 启动
service vsftpdstart
# 开机启动
chkconfig vsftpdon




二、配置文件
2.1 vsftpd.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES

listen=YES

pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=YES
userlist_file=/etc/vsftpd/user_list
use_localtime=yes
tcp_wrappers=YES

local_root=/ftp
chroot_list_enable=yes
chroot_list_file=/etc/vsftpd/chroot_list

************************************分割线,各配置项说明*****************************************
anonymous_enable=NO
#禁止匿名用户anonymous登录,默认为YES
local_enable=YES
#允许本地用户登录
write_enable=YES
#让登录的用户有写权限(上传,删除)
local_umask=022
#默认umask文件的权限掩码
dirmessage_enable=YES
#开启目录标语,默认是YES
xferlog_enable=YES
#开启日志,默认是YES
connect_from_port_20=YES
#指定FTP使用20端口进行数据传输,默认值为YES。
xferlog_file=/var/log/vsftpd.log
#设置日志文件名和路径,默认值为/var/log/vsftpd.log。
xferlog_std_format=YES
#如果启用,则日志文件将会写成xferlog的标准格式

listen=YES
#设置vsftpd服务器是否以standalone模式运行。
#若设置为NO,则vsftpd不是以独立的服务运行,要受到xinetd服务的管控,功能上会受到限制。
#
pam_service_name=vsftpd
#PAM认证文件名。PAM将根据/etc/pam.d/vsftpd进行认证
userlist_enable=YES
#是否借助vsftpd的抵挡机制来处理某些不受欢迎的账号,与下面的参数设置有关
userlist_deny=YES
#当 userlist_enable=YES 时才会生效的设定,若此设定值为 YES 时,则当使用者账号被列入到相应的文件时,
#在该文件内的使用者将无法登入vsftpd服务器!该文件名与下面设置(userlist_file=/etc/vsftpd/user_list)有关。
#若设置为YES,则/etc/vsftpd/user_list文件中的用户不允许访问FTP,若设置为NO,则只有/etc/vsftpd/user_list文件中的用户才能访问FTP。
#/etc/vsftpd/ftpusers文件里的用户将禁止登录ftp服务器,优先级高于user_list
#详细可参考

userlist_file=/etc/vsftpd/user_list
#控制用户访问FTP的文件,里面写着用户名称,一个用户名称一行;
#若上面 userlist_deny=YES 时,则这个设置就有用处了!在这个文件内的账号都无法使用 vsftpd !

use_localtime=yes
#是否使用本地时间,vsftpd 预设使用 GMT 时间(格林威治),所以预设的 FTP
#的日期会比中国晚 8 小时,建议修改设定为 YES
tcp_wrappers=YES
#如果启用,则vsftpd服务器会检查/etc/hosts.allow 和/etc/hosts.deny
#中的设置,来决定请求连接的主机,是否允许访问该FTP服务器

local_root=/ftp
#锁定ftp访问目录(默认没有此项)
chroot_list_enable=yes
#设置为YES,即让chroot_list文件里的用户列表有效。设置是否启用chroot_list_file配置项指定的用户列表文件。默认值为NO。
chroot_list_file=/etc/vsftpd/chroot_list
#需要手动建立chroot_list文件,用于指定用户列表文件,该文件用于控制哪些用户可以切换到用户家目录的上级目录。




2.2 ftpusers

此文件中的用户禁止登录ftp服务器


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody




2.3 user_list

在该文件内的使用者将无法登入vsftpd服务。
关联配置项:
pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=YES
userlist_file=/etc/vsftpd/user_list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody




2.4 chroot_list

将某些账号的使用者 chroot 在他们的家目录下.
关联配置项:
chroot_list_enable=yes
chroot_list_file=/etc/vsftpd/chroot_list

1
2
test /ftp/test
#用户名 限制访问的目录





三、创建用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
1.拥有读写权限
#mkdir /ftp
#useradd -s /sbin/nologin -d /ftp -M admin
# passwd admin
Changing password for user admin.
New UNIX password:
BAD PASSWORD: it is too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

#chown admin:admin /ftp
#chmod 755 /ftp

2.只拥有读权限
#mkdir -p /ftp/test
#useradd -s /sbin/nologin -d /ftp/test -M test
# passwd test
Changing password for user test.
New UNIX password:
BAD PASSWORD: it is too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

#chown test:admin /ftp/test
#chmod 575 /ftp/test

3.限制用户只访问所指定的目录,不能访问其他路径
启用chroot_list_enable=YES,chroot_local_user=NO,chroot_list_file=/etc/vsftpd/chroot_list。
在/etc/vsftpd.chroot_list文件中列出的用户,不能切换到其他目录;未在文件中列出的用户,可以切换到其他目录。
创建并编辑/etc/vsftpd/chroot_list文件,将受限制的用户添加进去,每个用户名一行
vim /etc/vsftpd/chroot_list
添加后如下:
test /ftp/test
即test用户不能切换到其他目录,未添加到chroot_list文件中的admin用户可以切换。

共分为一下四种情况:
①当chroot_list_enable=YES,chroot_local_user=YES时,在/etc/vsftpd.chroot_list文件中列出的用户,可以切换到其他目录;未在文件中列出的用户,不能切换到其他目录。
②当chroot_list_enable=YES,chroot_local_user=NO(默认值)时,在/etc/vsftpd.chroot_list文件中列出的用户,不能切换到其他目录;未在文件中列出的用户,可以切换到其他目录。
③当chroot_list_enable=NO,chroot_local_user=YES时,所有的用户均不能切换到其他目录。
④当chroot_list_enable=NO,chroot_local_user=NO时,所有的用户均可以切换到其他目录。
chroot_local_user=YES/NO(NO)
用于指定用户列表文件中的用户是否允许切换到上级目录。默认值为NO。




四、测试

1.使用admin用户列出目录


1
2
3
4
5
6
7
8
# curl ftp://10.10.60.197 -u admin:admin -s
-rw-r--r--    1 503      504             0 Nov 12 01:53 123
dr-xrwxr-x    2 501      504          4096 Nov 12 02:04 ctrip
dr-xrwxr-x    2 502      504          4096 Nov 12 02:05 test

# curl ftp://10.10.60.197/test/ -u admin:admin -s
-rw-r--r--    1 503      504             0 Nov 12 02:05 123
-rw-r--r--    1 0      0               0 Nov 12 01:22 test.file





1
2
3
4
5
6
7
8
9
10
(注意test后有斜线,否则会返回"curl: (19) RETR response: 550)

# curl ftp://10.10.60.197/test -u test1:test1
curl: (19) RETR response: 550
#
# curl ftp://10.10.60.197/test/ -u test1:test1
-rw-r--r--    1 503      504             0 Nov 12 02:04 123
-r-xrwxr-x    1 501      504         339 Nov 12 01:02 test.file
-rw-r--r--    1 504      504         556 Nov 12 04:25 test.sh
-rw-r--r--    1 501      504          5865 Nov 02 23:42 test.txt





2.测试上传与下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
客户端上传

# echo "123" > 123
#
使用admin账户传到test ftp目录下
# curl ftp://10.10.60.197/test/ -u admin:admin -T 123
% Total    % Received % XferdAverage Speed   Time    Time   TimeCurrent
                                 DloadUpload   Total   Spent    LeftSpeed
100   4    0   0100   4      0   10 --:--:-- --:--:-- --:--:--    11

使用admin账户传到其ftp目录下
# curl ftp://10.10.60.197 -u admin:admin -T 123
% Total    % Received % XferdAverage Speed   Time    Time   TimeCurrent
                                 DloadUpload   Total   Spent    LeftSpeed
100   4    0   0100   4      0   11 --:--:-- --:--:-- --:--:--    12


服务器端查看

# cd /ftp/
# pwd
/ftp
# ll
total 12
-rw-r--r-- 1 admin admin    4 Nov 12 03:33 123
dr-xrwxr-x 2 testadmin 4096 Nov 12 03:29 test
#
# cat 123
123
#
# cat test/123
123



页: [1]
查看完整版本: vsftp安装及配置