บทความนี้จะสอนการติดตั้ง FTP Server บน CentOS โดยใช้ ProFTPd ซึ่งเราจะทำการติดตั้งโดยการคอมไพล์ซอสโค้ด และเมื่อติดตั้งเสร็จแล้วเราจะทำการคอนฟิกให้ยูเซอร์ที่ล็อกอินเข้ามาสามารถเห็นได้แค่โฟลเดอร์ของตัวเองเท่านั้น ไม่สามารถเข้าไปดูโฟลเดอร์อื่นๆ ที่อยู่นอกเหนือจากของตัวเองได้ อย่างน้อยก็สร้างความเป็นส่วนตัวของยูเซอร์แต่ละคนและก็ปลอดภัยขึ้นมาอีกนิดหนึ่ง ยังไม่พอเราจะทำการปิด anonymous ftp ไปด้วยเลย ไม่รู้จะเปิดไว้ทำไมอีกเหมือนกันอันตรายเปล่าๆ
อย่างแรกทำการตรวจสอบไฟล์ /etc/hosts ก่อนว่าทำการแมพ IP กับ Host ของเราถูกต้องหรือยัง ถ้ายังก็พิมพ์เพิ่มเข้าไปเลยครับ ในตัวอย่างของผมคือจะแมพโดเมน server1.example.com ไปที่ IP 192.168.8.104
1 | # nano /etc/hosts |
เพื่อความมั่นใจว่าไม่มี FTP Server ตัวอื่นทำงานอยู่ในระบบ ซึ่งตัวดีฟอลที่ติดมากับ CentOS จะเป็น vsftpd แต่เราจะไม่เอา ให้ remove ออกไปเลย ถ้าไม่มีก็แล้วไป
1 | # yum remove vsftpd |
ทำการดาวโหลดและติดตั้งโปรแกรม ProFTPd โดยให้เลือกเอาตัว Stable ตัวล่าสุด (ขณะทดลองวันนี้ Stable: 1.3.4b) เข้าไปดูเพิ่มเติมได้ที่ http://www.proftpd.org/
1 2 3 4 5 6 7 | # cd /tmp/ # wget ftp://ftp.proftpd.org/distrib/source/proftpd-1.3.4b.tar.gz # tar xvzf proftpd-1.3.4b.tar.gz # cd proftpd-1.3.4b/ # ./configure --sysconfdir=/etc # make # make install |
สร้างลิงค์ของ /usr/local/sbin/proftpd ให้ไปอยู่ที่ /usr/sbin/
1 | # ln -s /usr/local/sbin/proftpd /usr/sbin/proftpd |
ทำการสร้าง init script ที่ /etc/init.d/proftpd เพื่อใช้เรียกผ่านเซอวิสของระบบ
1 | # nano /etc/init.d/proftpd |
ภายในไฟล์ /etc/init.d/proftpd ให้พิมพ์คำสั่งต่อไปนี้ลงไปนะครับ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #!/bin/sh # $Id: proftpd.init,v 1.1 2004/02/26 17:54:30 thias Exp $ # # proftpd This shell script takes care of starting and stopping # proftpd. # # chkconfig: - 80 30 # description: ProFTPD is an enhanced FTP server with a focus towards \ # simplicity, security, and ease of configuration. \ # It features a very Apache-like configuration syntax, \ # and a highly customizable server infrastructure, \ # including support for multiple 'virtual' FTP servers, \ # anonymous FTP, and permission-based directory visibility. # processname: proftpd # config: /etc/proftp.conf # pidfile: /var/run/proftpd.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x /usr/sbin/proftpd ] || exit 0 RETVAL=0 prog="proftpd" start() { echo -n $"Starting $prog: " daemon proftpd RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/proftpd } stop() { echo -n $"Shutting down $prog: " killproc proftpd RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/proftpd } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status proftpd RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f /var/lock/subsys/proftpd ]; then stop start fi ;; reload) echo -n $"Re-reading $prog configuration: " killproc proftpd -HUP RETVAL=$? echo ;; *) echo "Usage: $prog {start|stop|restart|reload|condrestart|status}" exit 1 esac exit $RETVAL |
ทำการเปลียน permission ของไฟล์ /etc/init.d/proftpd
1 | # chmod 755 /etc/init.d/proftpd |
แก้ไขไฟล์คอนฟิกของ ProFTPd ที่ /etc/proftpd.conf
1 | # nano /etc/proftpd.conf |
โดยทำการแก้ไขตามค่าต่างๆ ดังนี้
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # เอาคอมเม้นหน้า (# ตัวนี้แหละคอมเม้น) หน้า DefaultRoot ออก เพื่อให้ยูเซอที่ล็อกอินเข้ามาเห็นแต่โฟลเดอร์ของตัวเอง DefaultRoot ~ # ในส่วนของ User และ Group ให้เปลี่ยนเป็น nobody User nobody Group nobody # ในส่วนของ Limit SITE_CHMOD ให้เปลี่ยนเป็น AllowAll ยูเซอร์จะได้ทำการเปลี่ยน Permission เองได้ <Limit SITE_CHMOD> AllowAll </Limit> # ในส่วนของ Anonymous Ftp ให้ทำการคอมเม้นไว้ทั้งหมด เพราะเราจะไม่ใช้งาน #<Anonymous ~ftp> # User ftp # Group ftp # # # We want clients to be able to login with "anonymous" as well as "ftp" # UserAlias anonymous ftp # # # 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 # DisplayChdir .message # # # Limit WRITE everywhere in the anonymous chroot # <Limit WRITE> # DenyAll # </Limit> #</Anonymous> |
กำหนดให้ Service ของ ProFTPd ทำงานทุกครั้งที่เปิดเครื่อง
1 | # chkconfig proftpd on |
สั่ง Start Service ของ ProFTPd
1 | # service proftpd start |
สร้างยูเซอร์ที่จะใช้ทำการทดสอบ FTP
1 2 | # useradd hin # passwd hin |
จากนั้นทดสอบทำการ FTP เข้าระบบ จะเห็นว่าเราจะอยู่แค่ในโฟลเดอร์ของเราอย่างเดียว ไม่สามารถดูของยูเซอร์คนอื่นได้