顯示廣告
隱藏 ✕
看板 Knuckles
作者 Knuckles(阿德)
標題 [Ubuntu] 用Proftpd架設FTP server
時間 2008年10月19日 Sun. AM 02:24:54


安裝 proftpd

$ sudo apt-get install proftpd proftpd-doc

◎ 修改 /etc/proftpd/proftpd.conf

# 禁止root帳號登入
RootLogin off

一般的使用者加入ftp群組,家目錄都設在 /home/ftp
進階的使用者加入ftp-adv與ftp群組,有各自的家目錄,且可以存取 /home/ftp
所以要限制ftp群組的使用者在/home/ftp下,
而ftp-adv的使用者只限制在 /home 之下

DefaultRoot ~ ftp,!ftp-adv
DefaultRoot /home

◎ 重新啟動 proftpd
$ sudo /etc/init.d/proftpd restart


◎ 虛擬目錄

mount --bind <原始的資料夾> <要掛上的資料夾>

要把 /home/ftp 掛上每個帳號的 ~/ftp
先在每個人的 ~ 目錄開一個 ftp 資料夾

將bind寫在fstab使得每次開機都有效
編輯 /etc/fstab 加上

/home/ftp  /home/user1/ftp  none  bind  0  0
/home/ftp  /home/user2/ftp  none  bind  0  0
...

立即將fstab定義的分割區掛上
$ sudo mount -a

◎ 將別人的站掛上目錄

http://curlftpfs.sourceforge.net/

$ sudo apt-get install curlftpfs

$ sudo vim /etc/fuse.conf
啟用 user_allow_other (將 #user_allow_other 這行的#刪掉)

$ mkdir test
$ curlftpfs -o codepage=big5 -o allow_other ftp://帳號:密碼@位址:連接埠/ test/

其中 -o codepage=big5 代表連接的站台是使用big5編碼
     -o allow_other 允許非root的使用者存取,需先啟用/etc/fuse.conf的user_allow_other

開機機自動掛載

在/etc/fstab中加入:
curlftpfs#帳號:密碼@位址:連接埠 /mnt/test fuse rw,user,codepage=big5,allow_other 0 0
重開機即可,也可以打以下指令立即掛上
$ sudo mount /mnt/test


◎ 虛擬帳號

http://moto.debian.org.tw/viewtopic.php?p=35579

建立一個虛擬帳號 user1,密碼1234,只能讀取 /home/ftp/pub
使用系統帳號 ftp uid=114, gid=1004

$ sudo ftpasswd --passwd --name=user1 --uid=114 --gid=1004 --home=/home/ftp/
                --shell=/bin/false --file=/etc/proftpd.passwd
輸入兩次密碼 1234

編輯 proftpd.conf:

DefaultRoot ~
...
AuthUserFile /etc/proftpd.passwd
...
<Anonymous ~virtual_user>
# user是virtual_user,不是ftp
# 否則如下的WRITE/READ=DenyAll會無效
User virtual_user
Group nogroup

AnonRequirePassword on
RequireValidShell off

</Anonymous>


◎ 修改log檔格式

修改/etc/proftpd/proftpd.conf
將 TransferLog /var/log/proftpd/xferlog 前面加#取消
自訂一個log格式
LogFormat myxfer "%t %u "%m %f" %a(%h) %b bytes %T sec"
LogFormat myauth "%t %u "%r" %S %a(%h)"
ExtendedLog /var/log/proftpd/transfer.log read,write myxfer
ExtendedLog /var/log/proftpd/auth.log auth myauth

◎ 自己寫的新增使用者帳號的 script 檔: ftpuseradd.sh
#!/bin/bash

read -p "Enter the user name: " name
read -p "Only access FTP?(y/n):" onlyFTP

if [ "$onlyFTP" == "y" ]; then
	
para_str=" -g ftp -d /home/ftp -s /bin/false"
else
	
read -p "Enter the initial group: " initial_group
	
read -p "Enter the other groups (group1,group2,...): " other_group
	
read -p "Create a home directory?(y/n): " CreateHome

	
[ "$initial_group" != "" ] && para_str=" -g "$initial_group
	
[ "$initial_group" == "" ] && para_str=" -g ftp"

	
[ "$other_group" != "" ] && para_str=$para_str" -G "$other_group

	
[ "$CreateHome" == "y" ] && para_str=$para_str" -m" 
	
[ "$CreateHome" == "n" ] && para_str=$para_str" -d /home/ftp"
	
para_str=$para_str" -s /bin/bash"
fi


echo "sudo useradd "$para_str" "$name
sudo useradd $para_str $name

read -p "Set a random password?(y/n)" SetPW
if [ "$SetPW" == "y" ]; then
	
password=makepasswd --char=6
	
echo "The random password is: "$password
	
echo "${name}:${password}" | sudo chpasswd
else
	
sudo passwd $name
fi




--
※ 來源: DISP BBS (http://disp.twbbs.org)
※ 作者: Knuckles  來自: 140.112.175.128  時間: 2008-10-19 02:24:54
※ 編輯: Knuckles  來自: 140.112.175.128  時間: 2008-10-19 02:38:30
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2009-01-27 17:28:08
推 Knuckles:修改了一下: ◎ 將別人的站掛上目錄
	
>>140.112.175.130 01-27 17:28
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2009-01-27 18:32:23
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2009-05-31 15:28:15
※ 編輯: Knuckles  來自: 140.112.175.130  時間: 2009-05-31 15:28:59
※ 編輯: Knuckles  來自: 114.43.116.76  時間: 2009-11-17 11:48:44
※ 編輯: Knuckles 時間: 2011-04-04 08:15:52 來自: 111-248-5-73.dynamic.hinet.net
※ 看板: KnucklesNote 文章推薦值: 2 目前人氣: 0 累積人氣: 3268 
※ 文章分類: Ubuntu 安裝與設定
分享網址: 複製 已複製
terrykyo 轉錄至看板 terrykyo 時間:2011-04-04 01:53:17
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇