vsftp服务配置详解
FTP服务器简介:FTP服务器是提供文件存储和访问服务的服务器,通过ftp(文件传输协议)实现数据传输,而且FTP是仅基于TCP的服务,不支持UDP。FTP应用是一种C/S架构的应用,客户端和服务器端都需要安装相关的软件才能实现相互之间的数据传输。常见的软件套件有FileZilla,Server-U,VsFTP,Pure-FTPd ,ProFTPD等,其中VsFTP,Pure-FTPd ,ProFTPD是单纯的服务器程序,常见客户端程序有ftp,lftp。本文实验环境中采用的服务器程序是vsftp。工作原理:
基于pam认证框架实现认证:
安装:
1
# yum install vsftpd -y
启动:
1
2
# service vsftpd start
Starting vsftpd for vsftpd:
1
2
# ps -ef |grep vsftpd
root 85235 10 00:52 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf #以root启动以ftp运行
默认家目录:
1
2
3
4
5
# cat /etc/passwd |grep ftp
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
# cd /var/ftp/pub
# touch a
客户端默认登入:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# ftp 172.16.178.153
Connected to 172.16.178.153 (172.16.178.153).
220 (vsFTPd 2.2.2)
Name (172.16.178.153:root): anonymous #匿名用户
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 (172,16,178,153,65,242).
150 Here comes the directory listing.
drwxr-xr-x 2 0 0 4096 May 25 16:59 pub
226 Directory send OK.
ftp> cd pub
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (172,16,178,153,138,207).
150 Here comes the directory listing.
-rw-r--r-- 1 0 0 0 May 25 16:59 a
226 Directory send OK.
图形化操作:
创建一个ftp账号:
1
# useradd-g sherry -s /sbin/nologin-d /home/tftp testftp
登入本地账号(use lftp):
1
2
3
4
5
6
7
# yum install lftp -y
# lftp -u testftp,111111 172.16.178.153
lftp testftp@172.16.178.153:~> ls
-rw-r--r-- 1 0 0 0 May 25 17:59 1
-rw-r--r-- 1 501 500 0 May 25 18:02 a
lftp testftp@172.16.178.153:/> put all.sql
651585 bytes transferred
lftp指令获取:
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
lftp testftp@172.16.178.153:/> help
!<shell-command> (commands)
alias [<name> [<value>]] bookmark
cache cat [-b] <files>
cd <rdir> chmod mode file...
close [-a] cls
debug [<level>|off] [-o <file>] du <dirs>
exit [<code>|bg] get <rfile> [-o <lfile>]
glob <cmd> <args> help [<cmd>]
history -w file|-r file|-c|-l jobs [-v]
kill all|<job_no> lcd <ldir>
lftp <site> ls [<args>]
mget <files> mirror ]
mkdir [-p] <dirs> module name
more <files> mput <files>
mrm <files> mv <file1> <file2>
nlist [<args>] open <site>
pget <rfile> [-o <lfile>] put <lfile> [-o <rfile>]
pwd [-p] queue [<cmd>]
quote <cmd> repeat
rm [-r] [-f] <files> rmdir [-f] <dirs>
scache [<session_no>] set [<var> [<val>]]
site <site_cmd> source <file>
torrent [-O <dir>] <file> user <user|URL> [<pass>]
version wait [<jobno>]
zcat <files> zmore <files>
在lftp上用!command执行本地命令
1
2
lftp testftp@172.16.178.153:/> !ls
aa.bin.sqla.sqlall.sqlanaconda-ks.cfginstall.loginstall.log.syslog
获取配置文件帮助:
1
# man 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
# vim /etc/vsftpd/vsftpd.conf
# 注释
# 是否启用匿名用户
anonymous_enable=YES
# 匿名用户默认再根目录下没有写权限子目录文件系统有写权限和服务进程开启写就可以写入 跟目录不能改权限
# 上传
#anon_upload_enable=YES
# 删除
#anon_other_write_enable=YES
# 创建目录
#anon_mkdir_write_enable=YES
# 是否允许本地用户访问
local_enable=YES
# 是否允许本地用户上传
write_enable=YES
# 禁锢所有用户家目录 默认no
chroot_local_user=YES
# 开启对记录文件中的用户 禁锢功能跟上面chroot_local_user=YES 不能同时使用
#chroot_list_enable=YES
#chroot_list_file=/etc/vsftpd/chroot_list
# 登入信息显示
#ftpd_banner=Welcome to blah FTP service.
# 还可以引入文件
#banner_file=/etc/vsftpd/banner
# 在有.messages的目录 切换到此目录就会显示.messages里面信息
dirmessage_enable=YES
# 用户列表是否启用默认是黑名单
# 黑名单:userlist_enable=YESuserlist_deny=YES 第二选项可省略
# 白名单: userlist_enable=YESuserlist_deny=NO
userlist_enable=YES
# 连接限制
# 最大并发连接数
#max_clients
# 每个ip可同时发起并发请求
#max_per_ip
# 传输速率
#匿名用户的最大传输速率,单位是“字节/秒”
#anon_max_rate
# 本地用户的最大传输速率,单位是“字节/秒”
#local_max_rate
# 上传文件的umask
# 匿名用户上传文件的umask;
#anno_umask
# 本地用户上传文件的umask;
#local_umask
# 修改匿名用户上传文件的属主和属组:
#chown_uploads=YES
#chown_username=someuser
# 日志
xferlog_enable=YES
#xferlog_file=/var/log/xferlog
很多系统用户不能登入比如root:
1
2
3
4
5
6
7
8
9
# cat /etc/pam.d/vsftpd
#%PAM-1.0
session optional pam_keyinit.so force revoke
auth requiredpam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed #这项认证中的文件里的用户都是不能登入的
auth requiredpam_shells.so
auth include password-auth
account includepassword-auth
session required pam_loginuid.so
session includepassword-auth
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# cat /etc/vsftpd/ftpusers
# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
games
nobody
所有的虚拟用户会映射会一个系统用户,访问时的文件目录是为此系统用户的家目录;
虚拟用户配置:
hash编码的文件:奇数行为用户名,偶数行为密码关系型数据库:pam-mysql实现认证查询pam_mysql.so是否安装
1
2
# ls /lib64/security/pam_m
pam_mail.so pam_mkhomedir.sopam_motd.so
1
2
3
yum install pam_mysql-y
# ls /lib64/security/pam_m
pam_mail.so pam_mkhomedir.sopam_motd.so pam_mysql.so
创建vsftpd所需用到的库,表,以及vsftpd用户
1
2
3
4
5
6
7
8
9
10
mysql> create database vsftpd;
mysql> grant select on vsftpd.* to 'vsftpd'@'localhost' identified by '222222';
mysql> flush privileges;
mysql> create table users (
id int AUTO_INCREMENT NOT NULL,
name char(20) binary NOT NULL,
password char(48) binary NOT NULL,
primary key(id)
);
添加虚拟用户:
1
2
mysql> insert into users(name,password) values('tom',password('tom'));
mysql> insert into users(name,password) values('jerry',password('jerry'));
配置vsftpd:建立pam认证所需文件
1
2
3
4
5
# vim /etc/pam.d/vsftpd.mysql
# 认证时 crypt=2 mysql-password加密3 md5 4sha1
auth required /lib64/security/pam_mysql.so user=vsftpd passwd=222222 host=127.0.0.1 db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2
#账号检验
account required /lib64/security/pam_mysql.so user=vsftpd passwd=222222 host=127.0.0.1 db=vsftpd table=users usercolumn=name passwdcolumn=password crypt=2
1
2
# useradd-g sherry -s /sbin/nologin-d /home/tftp testftp
# chmod go+rx tftp/
1
2
3
4
5
6
7
8
9
10
11
12
请确保/etc/vsftpd.conf中已经启用了以下选项
anonymous_enable=YES
local_enable=YES
write_enable=YES
anon_upload_enable=NO
anon_mkdir_write_enable=NO
chroot_local_user=YES
而后添加以下选项
guest_enable=YES
guest_username=testftp #映射用户
pam_service_name=vsftpd.mysql
启动服务:
1
2
3
# /etc/init.d/vsftpd restart
Shutting down vsftpd:
Starting vsftpd for vsftpd:
登入成功:
1
2
3
4
5
6
# lftp -u tom,tom 172.16.178.153
lftp tom@172.16.178.153:/> put a.bin.sql
2448 bytes transferred
# ll
total 644
-rw------- 1 testftp sherry 2448 May 26 04:50 a.bin.sql
权限配置:
1
2
3
# vim /etc/vsftpd/vsftpd.conf
# 配置vsftpd为虚拟用户使用配置文件目录vusers_config名字随意
user_config_dir=/etc/vsftpd/vusers_config
创建所需要目录,并为虚拟用户提供配置文件
1
2
3
# mkdir /etc/vsftpd/vusers_config/
# cd /etc/vsftpd/vusers_config/
# touch tom jerry
虚拟用户对vsftpd服务的访问权限是通过匿名用户的相关指令进行的。比如,如果需要让tom用户具有上传文件的权限,可以修改/etc/vsftpd/vusers/tom文件,在里面添加如下选项即可。
1
2
3
4
# /etc/vsftpd/vusers/tom
anon_upload_enable={YES|NO}
anon_mkdir_write_enable={YES|NO}
anon_other_write_enable={YES|NO}
页:
[1]