all-in-one 7 (multisite proftpd)

ทำ ftp ใช้ proftpd

ที่ทำเป็น คือใช้ proftpd (ตัวอื่นทำ VirtualHost ไม่เป็น หรืออาจทำยาก)

เนื่องจากเรามี 2 โดเมน คือ example.com และ example.org เราต้องการทำ ftp ทั้งสองโดเมน จึงต้องทำเรื่อง VirtualHost

แต่เนื่องจากระบบ VirtualHost ใน proftpd ไม่เหมือนใน apache2 เสียทีเดียว เนื่องจากเขาไม่ถือชื่อโฮสต์เป็นสำคัญ แต่จะถือไอพีและพอร์ตเป็นตัวจำแนกแทน ดังนั้นถ้าเราต้องการแยกไดเรกทอรีระหว่าง example.com และ example.org เราจะต้องใช้พอร์ตเป็นตัวแยกแทน

สมมุติฐานมีดังนี้คือ

เตรียมผู้ใช้และกลุ่ม
เพิ่มกลุ่ม ftpusers สำหรับส่วนกลาง และ comgroup กับ orggroup สำหรับพอร์ตพิเศษ

# groupadd ftpusers
# groupadd comgroup
# groupadd orggroup

แก้ไขผู้ใช้ ftpuser1 ให้เข้ามาเป็นสมาชิกของ comgroup และ ftpuser2 ให้เข้ามาเป็นสมาชิกของ orggroup

# useradd -g ftpusers -G comgroup -m -d /home/ftpuser1 ftpuser1
# useradd -g ftpusers -G orggroup -m -d /home/ftpuser2 ftpuser2
# passwd ftpuser1
# passwd ftpuser2

ป้อนรหัสผ่านตามปกติ

เตรียมไดเรกทอรี

# mkdir -p /sys1/sysb/var/ftp/{pub,example.com,example.org}
# ln -sf /sys1/sysb/var/ftp /var
# chown ftpuser1:comgroup /var/ftp/example.com
# chown ftpuser2:orggroup /var/ftp/example.org
# chown ftp:ftpusers /var/ftp/pub
# chmod 775 /var/ftp/*

ติดตั้ง

# aptitude install proftpd
Run proftpd from inetd or standalone? <<<--- standalone

แก้ไขเรื่อง IPv6 ไม่ให้แสดงรายงานความผิดพลาด
และแก้ไขงานของ Anonymous โดยเอาจากตัวอย่างในไฟล์
และเพิ่มให้อ่านไฟล์คอนฟิกของ example.com และ example.org

# vi /etc/proftpd/proftpd.conf
...
#UseIPv6             on
UseIPv6             off
...

# A basic anonymous configuration, no upload directories.

#<Anonymous ~ftp>
<Anonymous /var/ftp/pub>
  User              ftp 
  Group             nogroup
  # We want clients to be able to login with "anonymous" as well as "ftp"
  UserAlias         anonymous ftp 
  # Cosmetic changes, all files belongs to ftp user
  DirFakeUser   on ftp
  DirFakeGroup on ftp

  RequireValidShell     off 

  # Limit the maximum number of anonymous logins
  MaxClients            10

  # We want 'welcome.msg' displayed at login, and '.message' displayed
  # in each newly chdired directory.
  DisplayLogin          welcome.msg
  DisplayFirstChdir     .message

  # Limit WRITE everywhere in the anonymous chroot
  <Directory *>
    <Limit WRITE>
      DenyAll
    </Limit>
  </Directory>

  # Uncomment this if you're brave.
  # <Directory incoming>
  #   # Umask 022 is a good standard umask to prevent new files and dirs
  #   # (second parm) from being group and world writable.
  #   Umask             022  022 
  #            <Limit READ WRITE>
  #            DenyAll
  #            </Limit>
  #            <Limit STOR>
  #            AllowAll
  #            </Limit>
  # </Directory>

</Anonymous>

Include /etc/proftpd/example.com.conf
Include /etc/proftpd/example.org.conf

สร้างไฟล์ example.com.conf ให้มาใช้พอร์ต 10021

# vi /etc/proftpd/example.com.conf
<VirtualHost ftp.example.com>
    ServerName              "Example.com's FTP site"
    DefaultRoot             ~
    AllowOverwrite          on
    Umask                   002
    User                    ftpuser1
    Group                   comgroup
    MaxClients              10
    Port                    10021

    <Anonymous /var/ftp/example.com>
      User                                ftp
      Group                               nogroup
      # We want clients to be able to login with "anonymous" as well as "ftp"
      UserAlias                   anonymous ftp
      # Cosmetic changes, all files belongs to ftp user
      DirFakeUser on ftp
      DirFakeGroup on ftp

      RequireValidShell           off

      # Limit the maximum number of anonymous logins
      MaxClients                  10

      # We want 'welcome.msg' displayed at login, and '.message' displayed
      # in each newly chdired directory.
      DisplayLogin                welcome.msg
      DisplayFirstChdir           .message

      # Limit WRITE everywhere in the anonymous chroot
      <Directory /var/ftp/example.com>
      </Directory>
      <Directory *>
        <Limit WRITE>
          DenyAll
        </Limit>
      </Directory>
    </Anonymous>

</VirtualHost>

สร้าง example.org.conf ให้มาใช้พอร์ต 10022

# vi /etc/proftpd/example.org.conf
<VirtualHost ftp.example.org>
    ServerName              "Example.org's FTP site"
    DefaultRoot             ~
    AllowOverwrite          on
    Umask                   002
    User                    ftpuser2
    Group                   orggroup
    MaxClients              10
    Port                    10022

    <Anonymous /var/ftp/example.org>
      User                                ftp
      Group                               nogroup
      # We want clients to be able to login with "anonymous" as well as "ftp"
      UserAlias                   anonymous ftp
      # Cosmetic changes, all files belongs to ftp user
      DirFakeUser on ftp
      DirFakeGroup on ftp

      RequireValidShell           off

      # Limit the maximum number of anonymous logins
      MaxClients                  10

      # We want 'welcome.msg' displayed at login, and '.message' displayed
      # in each newly chdired directory.
      DisplayLogin                welcome.msg
      DisplayFirstChdir           .message

      # Limit WRITE everywhere in the anonymous chroot
      <Directory /var/ftp/example.org>
      </Directory>
      <Directory *>
        <Limit WRITE>
          DenyAll
        </Limit>
      </Directory>
    </Anonymous>

</VirtualHost>

เริ่ม protftpd ใหม่

# /etc/init.d/proftpd restart

เสร็จแล้ว
ผู้ใช้งานสามารถใช้งานผ่าน

หมายเหตุ