1、安装Pure-FTPd
sudo apt-get install pure-ftpd-mysql mysql-server
2、添加用户和组
sudo groupadd -g 2001 ftpgroup
sudo useradd -u 2001 -s /bin/false -d /dev/null -c "pure-ftpd user" -g ftpgroup ftpuser
3、Chroot设置
sudo sh -c "echo 'yes' > /etc/pure-ftpd/conf/ChrootEveryone"
4、手工创建用户目录
sudo sh -c "echo 'No' > /etc/pure-ftpd/conf/CreateHomeDir"
5、为Pure-FTPd创建MySQL数据库
mysql -uroot -pxdnice -e "create database ftpusers;"
创建数据库用户ftpadmin赋予权限
grant select,insert,update,delete,create,drop on ftpusers.* to 'ftpadmin'@'localhost' identified by 'admin888';
grant select,insert,update,delete,create,drop on ftpusers.* to 'ftpadmin'@'localhost.localdomain' identified by 'admin888';
flush privileges;
创建users表
create table if not exists `users`(
`user` varchar(16) not null default '',
`password` varchar(32) not null default '',
`uid` int(11) not null,
`gid` int (11) not null,
`dir` varchar(128) not null default '',
`quotafiles` int(10) not null default '500',
`quotasize` int(10) not null default '30',
`ulbandwidth` int(10) not null default '80',
`dlbandwidth` int(10) not null default '80',
`ipaddress` varchar(15) not null default '*',
`comment` tinytext,
`status` enum('0','1') not null default '1',
`ulratio` smallint(5) not null default '1',
`dlratio` smallint(5) not null default '1',
primary key (`user`),
unique key `user` (`user`)
)engine=myisam default charset=latin1;
6、配置Pure-FTPd的mysql.conf
sudo mv /etc/pure-ftpd/db/mysql.conf /etc/pure-ftpd/db/mysql.conf_orig
sudo nano /etc/pure-ftpd/db/mysql.conf
MySQLServer 127.0.0.1
MySQLSocket /var/run/mysqld/mysqld.sock
MySQLUser ftpadmin
MySQLPassword xdnice*
MySQLDatabase ftpusers
MySQLCrypt md5
MySQLGetPW SELECT password FROM users WHERE user="\L" AND status="1" AND (ipaddress="*" OR ipaddress LIKE "\R")
MySQLGetUID SELECT uid FROM users WHERE user="\L" AND status="1" AND (ipaddress="*" OR ipaddress LIKE "\R")
MySQLGetGID SELECT gid FROM users WHERE user="\L" AND status="1" AND (ipaddress="*" OR ipaddress LIKE "\R")
MySQLGetDir SELECT dir FROM users WHERE user="\L" AND status="1" AND (ipaddress="*" OR ipaddress LIKE "\R")
MySQLGetQTAFS SELECT quotafiles FROM users WHERE user="\L" AND status="1" AND (ipaddress="*" OR ipaddress LIKE "\R")
MySQLGetQTASZ SELECT quotasize FROM users WHERE user="\L" AND status="1" AND (ipaddress="*" OR ipaddress LIKE "\R")
MySQLGetRatioUL SELECT ulratio FROM users WHERE user="\L" AND status="1" AND (ipaddress="*" OR ipaddress LIKE "\R")
MySQLGetRatioDL SELECT dlratio FROM users WHERE user="\L" AND status="1" AND (ipaddress="*" OR ipaddress LIKE "\R")
MySQLGETBandwidthUL SELECT ulbandwidth FROM users WHERE user="\L" AND status="1" AND (ipaddress="*" OR ipaddress LIKE "\R")
MySQLGETBandwidthDL SELECT dlbandwidth FROM users WHERE user="\L" AND status="1" AND (ipaddress="*" OR ipaddress LIKE "\R")
sudo chmod g=o= /etc/pure-ftpd/db/mysql.conf
sudo /etc/init.d/pure-ftpd-mysql restart
7、安装web管理界面
到http://machiel.generaal.net/index.php?subject=user_manager_pureftpd&button=download下载
解压缩
sudo tar zxvf /home/babycat/ftp_v2.1.tar.gz
修改配置文件
sudo nano /var/www/ftp/config.php
$DEFUserID = "2001"; // nobody // Default user id of virtual ftp user.
$DEFGroupID = "2001"; // guest // Default group is of virtual ftp user.
$UsersFile = "/etc/passwd"; // The unix user file
$GroupFile = "/etc/group"; // The unix group file
$StyleSheet = "style/default.css.php"; // The location of the style sheet
$EnableQuota = 0; // Enable virtual quota's (0=Off 1=On)
$EnableRatio = 0; // Enable ratio (0=Off 1=On)
// The pureftpd server has to be compiled with ratio support.
/* This list of users will NOT appear in the dropdown menu. */
$BlacklistUsers = array ('adm','bin','bind','daemon','gopher','halt','kmem','lp',
'mailnull','man','named','nfsnobody','nscd','operator',
'pop','root','rpc','rpcuser','rpm','shutdown','smmsp',
'sshd','sync','toor','tty','uucp','vcsa','xfs');
/* This list of groups will NOT appear in the dropdown menu. */
$BlacklistGroups = array ('adm','bin','bind','daemon','dialer','dip','disk','floppy','gopher','kmem',
'lock','lp','mailnull','man','named','mem','network','news',
'nscd','ntp','operator','pcap','root','rpc','rpcuser','rpm','slocate','smmsp',
'sshd','staff','sys','tty','utmp','uucp','vcsa','wheel','xfs');
创建admin表
use ftpusers;
create table if not exists `admin`(
`username` varchar(35) not null default '',
`password` char(32) not null default '',
primary key (`username`)
)engine=myisam default charset=latin1;
插入管理帐号
insert into `admin` (`username`,`password`) values ('ftpadmin',MD5('admin888'));
《本文转载至--Ubuntu Server 最佳方案》
配置参数。
参数 |
说明 |
listen_address=ip address |
指定侦听IP |
listen_port=port_value |
指定侦听端口,默认21 |
anonymous_enable=YES |
是否允许使用匿名帐户 |
local_enable=YES |
是否允许本地用户登录 |
nopriv_user=ftp |
指定vsftpd服务的运行帐户,不指定时使用ftp |
write_enable=YES |
是否允许写入 |
anon_upload_enable=YES |
匿名用户是否可上传文件 |
anon_mkdir_write_enable=YES |
匿名用户是否建立目录 |
dirmessage_enable=YES |
进入每个目录是显示欢迎信息,在每个目录下建立.message文件在里面写欢迎信息 |
xferlog_enable=YES |
上传/下载文件时记录日志 |
connect_from_port_20=YES |
是否使用20端口传输数据(是否使用主动模式) |
chown_uploads=YES、chown_username=whoever |
修改匿名用户上传文件的拥有者 |
xferlog_file=/var/log/vsftpd.log |
日志文件 |
xferlog_std_format=YES |
使用标准文件日志 |
idle_session_timeout=600 |
会话超时,客户端连接到ftp但未操作 |
data_connection_timeout=120 |
数据传输超时 |
async_abor_enable=YES |
是否允许客户端使用sync等命令 |
ascii_upload_enable=YES、ascii_download_enable=YES |
是否允许上传/下载二进制文件 |
chroot_local_user=YES |
限制所有的本地用户在自家目录 |
chroot_list_enable=YES、chroot_list_file=/etc/vsftpd/chroot_list |
指定不能离开家目录的用户,将用户名一个一行写在/etc/vsftpd/chroot_list文件里,使用此方法时必须chroot_local_user=NO |
ls_recurse_enable=YES |
是否允许使用ls -R等命令 |
listen=YES |
开启ipv4监听 |
listen_ipv6=YES |
开启ipv6监听 |
pam_service_name=vsftpd |
使用pam模块控制,vsftpd文件在/etc/pam.d目录下 |
userlist_enable=YES |
此选项被激活后,vsftpd将读取userlist_file参数所指定的文件中的用户列表。当列表中的用户登录FTP服务器时,该用户在提示输入密码之前就被禁止了。即该用户名输入后,vsftpd查到该用户名在列表中,vsftpd就直接禁止掉该用户,不会再进行询问密码等后续步聚 |
userlist_deny=YES |
决定禁止还是只允许由userlist_file指定文件中的用户登录FTP服务器。此选项在userlist_enable 选项启动后才生效。YES,默认值,禁止文件中的用户登录,同时也不向这些用户发出输入密码的提示。NO,只允许在文件中的用户登录FTP服务器 |
tcp_wrappers=YES |
是否允许tcp_wrappers管理 |
local_root=/home/ftp |
所有用户的根目录,,对匿名用户无效 |
anon_max_rate |
匿名用户的最大传输速度,单位是Byts/s |
local_max_rate |
本地用户的最大传输速度,单位是Byts/s |
download_enable= YES |
是否允许下载 |
在上面所有参数中,只要涉及到上传的参数在启用后还需要对应本地目录有写入权限。