ubuntu下Pure-FTPd的安装和配置

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'));

搭建好后测试FTP是否连接成功,如果出现530错误,解决方法:
在 /etc/pure-ftpd/auth 目录下输入以下命令:
ln -s ../conf/MySQLConfigFile 30mysql  (使用软连接到MySQLConfigFile中的/etc/pure-ftpd/db/mysql.conf)
完成后重启 /etc/init.d/pure-ftpd-mysql restart

你可能感兴趣的:(ubuntu)