顯示廣告
隱藏 ✕
看板 Knuckles_note
作者 Knuckles (站長 那克斯)
標題 [Linux][CentOS] pureftpd 安裝與設定
時間 2012年10月07日 Sun. AM 02:26:13


官網 http://www.pureftpd.org/project/pure-ftpd

參考
  
 


安裝 pure-ftpd
$ yum install pure-ftpd

啟動 pure-ftpd
$ service pure-ftpd start

設定每次開機自動啟動
$ chkconfig pure-ftpd on

修改設定檔
$ vim /etc/pure-ftpd/pure-ftpd.conf

# 禁止匿名帳號,將no改為yes
NoAnonymous                 yes

# 將下面這行的#拿掉,就可以使用系統帳號登入
# 使用系統帳號或用資料庫建帳號只能選一種
# UnixAuthentication    yes

# 設定ftp要監聽哪個IP與port,預設是所有IP的port 21
# Bind                      127.0.0.1,21
Bind xxx.xxx.xxx.xxx,21

# 使用被動模式時可使用的port範圍,之後要在防火牆打開此範圍的port
#PassivePortRange          30000 50000

# 上傳的檔案要拿掉什麼權限
# 設定 113:022 代表檔案權限為 664, 目錄權限為 755
Umask                       113:022



修改完設定檔要重開才會生效
$ service pure-ftpd restart


◎ 使用 MySQL 建立虛擬帳號

修改設定檔
$ vim /etc/pure-ftpd/pure-ftpd.conf

# 找到下面這行,將前面的#拿掉
# MySQLConfigFile               /etc/pure-ftpd/pureftpd-mysql.conf

# 拿掉這行的#,若使用者沒有家目錄則自動建一個
#CreateHomeDir               yes


修改 pureftpd-mysql 設定檔
$ vim /etc/pure-ftpd/pureftpd-mysql.conf


#如果MySQL是在本機上的話
MYSQLSocket     /var/lib/mysql/mysql.sock

#如果MySQL是在另一台主機上的話
MYSQLServer     xxx.xxx.xxx.xxx
MYSQLPort       3306


# 改為自己要給 pureftpd 使用的 mysql 帳號、密碼、資料庫
MYSQLUser       pureftpd
MYSQLPassword   passwd
MYSQLDatabase   pureftpd
# 密碼的加密方式
MYSQLCrypt      md5

#讀取資料庫的語法,不用改
MYSQLGetPW      SELECT Password FROM users WHERE User='\L'
MYSQLGetUID     SELECT Uid FROM users WHERE User='\L'
MYSQLGetGID     SELECT Gid FROM users WHERE User='\L'
MYSQLGetDir     SELECT Dir FROM users WHERE User='\L'


建立一個系統帳號ftp給所有虛擬帳號使用

帳號 ftp,UID 為 2001
群組 ftp,GID 為 2001

(若系統上已有ftp這個帳號,先執行 $ userdel ftp)

$ groupadd -g 2001 ftp
$ useradd -u 2001 -s /bin/false -d /bin/null -c "pureftpd user" -g ftp ftp




建立資料庫

在 MySQL 新增上面設定的使用者 pureftpd
並建立一個 pureftpd 資料庫

在 pureftpd 資料庫中新增一個 users 資料表
CREATE TABLE users (
id int(32) unsigned NOT NULL auto_increment,
User varchar(16) NOT NULL default '',
Password varchar(64) NOT NULL default '',
Uid varchar(11) NOT NULL default '-1',
Gid varchar(11) NOT NULL default '-1',
Dir varchar(128) NOT NULL default '',
QuotaSize smallint(5) NOT NULL default '0',
QuotaFiles int(11) NOT NULL default '0',
ULBandwidth smallint(5) NOT NULL default '0',
DLBandwidth smallint(5) NOT NULL default '0',
ULRatio smallint(6) NOT NULL default '0',
DLRatio smallint(6) NOT NULL default '0',
comment tinytext NOT NULL,
ipaccess varchar(15) NOT NULL default '*',
status enum('0','1') NOT NULL default '0',
create_date datetime NOT NULL default '0000-00-00 00:00:00',
modify_date datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (id,User),
UNIQUE KEY User (User)
) TYPE=MyISAM AUTO_INCREMENT=5 ;



新增一個虛擬帳號: test,密碼: 1234,UID: 2001,GID: 2001,家目錄 /home/ftp
INSERT INTO pureftpd (User, Password, Uid, Gid, Dir) VALUES ('test', MD5('1234'), '2001', '2001', '/home/ftp');


或是用 phpMyAdmin 新增,如圖:
[圖]



設定好後重啟ftp
$ service pure-ftpd restart


在iptables防火牆設定裡將設定的ftp port打開
iptables -A INPUT -p TCP -i eth0 --dport  21  -j ACCEPT   # FTP
iptables -A INPUT -p TCP -i eth0 --dport  30000:50000  -j ACCEPT   # FTP passive



登入看看
# ftp localhost



◎ 設定檔 pure-ftpd.conf 詳細內容

# Cage in every user in his home directory
ChrootEveryone    yes
# 限定每一個使用者都只能在自己家目錄下活動。
# 當設定成 no 時,則 Real User 可切換至其他目錄做存取。

# TrustedGID     100
# 當您將註解拿掉後,GID 100 的群組成員會被視為信任的使用者,因此可以存取家目錄外的
# 其他目錄。此時無論 ChrootEveryone 設定為何,都是一樣的結果。

# Maximum number of simultaneous users
MaxClientsNumber   10
# 限定最大連線數為 10。

# Maximum number of sim clients with the same IP address
MaxClientsPerIP     3
# 限定同一來源端位址的最大連線數為 3。

# List dot-files even when the client doesn't send "-a".
DisplayDotFiles     yes
# 這個參數設定成 yes 的話,則 Client 可以看到檔名是以 "." 作開始的隱藏檔。

# Don't allow authenticated users - have a public anonymous FTP only.
AnonymousOnly    yes
# 是否只允許匿名登入。當您希望 Real User 也能登入時,就設定成 no。

# Disallow anonymous connections. Only allow authenticated users.
NoAnonymous     no
# 是否不允許匿名登入。當設定成 no,表示允許匿名登入,但如果您希望只有 Real User 能經
# 由認證登入時,這裡就設定成 yes 吧。

# Syslog facility (auth, authpriv, daemon, ftp, security, user, local*)
# The default facility is "ftp". "none" disables logging.
SyslogFacility     ftp
# 您可以在 /etc/syslog.conf 裡使用 ftp 這個 facility,來告知 syslogd 要將 ftp 的相關訊息紀錄到
# 哪裡,比如: ftp.*   /var/log/ftplog

# Don't resolve host names in log files. Logs are less verbose, but it uses less bandwidth. Set this to "yes"
# on very busy servers or if you don't have a working DNS.
DontResolve      yes
# ftp 的紀錄檔是否不需解析主機名稱。

# Maximum idle time in minutes (default = 15 minutes)
MaxIdleTime      15
# 設定 FTP Client 端的閒置時間為 15 分鐘。

# PureDB user database (see README.Virtual-Users)
# PureDB   /etc/pure-ftpd/pureftpd.pdb
# 這是使用虛擬帳號登入時,所指定要使用的資料庫。

# If you want to enable PAM authentication, uncomment the following line.
PAMAuthentication    yes
# 是否使用 PAM 認證模組來對使用者作認證。

# If you want simple Unix (/etc/passwd) authentication, uncomment this.
# UnixAuthentication  yes
# 是否依照傳統的 /etc/passwd 來做認證。

# Are anonymous users allowed to create new directories ?
AnonymousCanCreateDirs  no
# 是否允許 anonymous 建立新目錄。如設定成 yes,則 anonymous 雖可建立目錄,但無法刪除。

# Port range for passive connections replies. - for firewalling.
# PassivePortRange 30000 50000
# 當 Client 端採用被動模式來建立資料通道時,FTP Server 預計所要使用 data channel 連接埠的範圍。
# 當您 Linux Client 端執行 ncftp 或 ftp 指令連上 FTP 站台後,可使用 passive 指令來變更連線模式。

# Upload/download ratio for anonymous users.
# AnonymousRatio   1 10
# 設定 anonymous 上傳/下載比率。
# 以 1:10 而言,如果 anonymous 上傳了 1MB 的資料後,就能夠下載 10MB 的檔案資料。

# Upload/download ratio for all users. This directive superscedes the previous one.
# UserRatio      1 10
# 設定 All User 上傳/下載比率。當 AnonymousRatio 及 UserRatio 都做設定時,是以 UserRatio 為主。

# Disallow downloading of files owned by "ftp", ie.
# files that were uploaded but not validated by a local admin.
AntiWarez       yes
# 匿名使用者要下載的檔案,如果其擁有者是 ftp 的話,則不允許下載。當您的 FTP 站台開放 anonymous 上傳時 (上
# 傳之後的檔案擁有者為 ftp),為了防止有些人會上傳一些有問題的檔案來供人下載,因此才設定這個參數 ; 而等
# 管理者確認上傳的檔案沒問題後,就可以把此檔的擁有者做個改變,這樣就能提供正常下載了。

# IP address/port to listen to (default=all IP and port 21).
# Bind       127.0.0.1,21
# 設定 FTP Server 要在哪個介面位址監聽哪個 port。預設是允許在所有介面位址監聽 21 port。

# Maximum bandwidth for anonymous users in KB/s
# AnonymousBandwidth 8
# 設定 anonymous 最大上傳、下載頻寬,單位為KB/s。

# Maximum bandwidth for *all* users (including anonymous) in KB/s.
# Use AnonymousBandwidth *or* UserBandwidth, both makes no sense.
# UserBandwidth    8
# 設定 All User 最大上傳、下載頻寬。當 AnonymousBandwidth 及 UserBandwidth 都設定時,是以 UserBandwidth 為主。

# File creation mask. <umask for files>:<umask for dirs> . 177:077 if you feel paranoid.
Umask        177:077
# 設定上傳檔案、目錄 (含建立新目錄) 的預設權限,177:077 表示檔案的預設權限為 600,目錄為 700。

# Minimum UID for an authenticated user to log in.
MinUID        100
# 設定能允許 Real User 認證登入的最小 UID 為 100,也就是說 UID 100 以上 (含100) 的使用者方可認證登入。
# 如您欲允許 root 登入的話,這個地方請註解起來,並且在 /etc/ftpusers 檔案中將 root 帳號移除。
# /etc/ftpusers 是用來設定拒絕登入 FTP Server 的使用者名單的。

# Users can't delete/write files beginning with a dot ('.') even if they own them. If TrustedGID is enabled,
# this group will have access to dot-files, though.
ProhibitDotFilesWrite   yes
# 是否要禁止使用者刪除或修改隱藏檔,即使使用者就是該隱藏檔的擁有者。設定 yes 就表示要禁止啦。

# Prohibit *reading* of files beginning with a dot (.history, .ssh...)
ProhibitDotFilesRead  no
# 是否要禁止使用者讀取隱藏檔內容。當以上兩個參數都設定 no 時,表示使用者對隱藏檔具有 r 及 w 的權限 (anonymous
# 為例外)。當 ProhibitDotFilesWrite 設定成 no,而 ProhibitDotFilesRead 設定成 yes 時,使用者是不能刪除檔案的。但是無論
# 如何設定,只要 TrustedGID 有設定時,則此群組的成員認證進來後是可以具有 r 及 w 的權限,並不會受到這裡的規範。

# Never overwrite files. When a file whoose name already exist is uploaded,
# it get automatically renamed to file.1, file.2, file.3, ...
AutoRename       yes
# 當上傳檔案時,若對方目錄內已經存在一個同檔名的檔案,則允許將上傳的那個檔案作自動更名的動作。

# Disallow anonymous users to upload new files (no = upload is allowed)
AnonymousCantUpload yes
# 是否要拒絕 anonymous 上傳。如要開放匿名使用者上傳檔案的話,就設定成 no。另外要允許上傳目錄時,除了這裡要
# 設定成 no 以外,AnonymousCanCreateDirs 參數需設定成 yes 才行。

# Disallow the CHMOD command. Users can't change perms of their files.
#NoChmod       yes
# 是否要拒絕使用者執行 chmod 指令來修改權限。

# Allow users to resume and upload files, but *NOT* to delete them.
#KeepAllFiles     yes
# 當設定成 yes 時,表示使用者無法刪除伺服器上的檔案。

# Automatically create home directories if they are missing
#CreateHomeDir    yes
# 當使用者家目錄不存在,是否要自動建立起來。

# This option is useful with servers where anonymous upload is allowed. As /var/ftp is in /var, it save some
# space and protect the log files. When the partition is more that X percent full,new uploads are disallowed.
MaxDiskUsage     99
# 假使我們將 anonymous 的家目錄改成 /var/ftp (修改 /etc/passwd ),然後又設定允許匿名使用者上傳,那這個參數就很好用
# 了,因為當 /var partition 的使用空間達 99% 時,就不允許匿名使用者再上傳資料,不然 /var/log 目錄下的那些記錄檔可就
# 無法持續記錄一些重要資訊了。

# Set to 'yes' if you don't want your users to rename files.
NoRename        yes
# 是否要拒絕使用者修改檔案目錄的名稱 (重新命名)。




--
※ 作者: Knuckles 時間: 2012-10-07 02:26:13
※ 編輯: Knuckles 時間: 2014-12-07 00:07:42
※ 看板: KnucklesNote 文章推薦值: 0 目前人氣: 0 累積人氣: 2975 
※ 文章分類: Linode CentOS 架站筆記
分享網址: 複製 已複製
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇