การ install และ config โปรแกรม vsftpd
ในความคิดของผมคิดว่า เครื่อง server ไหนก็ตามที่ลงเป็น LAMP server มันน่าจะต้องใช้บริการ ftp อยู่แล้ว แต่แปลกครับ ไม่มี ftp server ตอนเลือกที่จะติดตั้ง Ubuntu Server เราต้องมาลงเองทีหลัง (หรือว่ามันมี แต่ผมไม่รู้จัก ก็ไม่ทราบ)
คาดว่าสาเหตุคงเกิดจาก ใน Linux นั้น มี FTP Server ให้เลือกใช้มากมาย จนไม่รู้ว่าจะลงอะไรเป็น default แถมมาให้ดี
เท่าที่ผมเห็นใช้กันมากๆก็จะมี 2 ตัว คือ vsftpd กับ ProFTPD
โดยส่วนตัว ผมเลือก vsftpd ครับ เพราะเมื่อก่อนผมใช้ redhat แล้วมันแถมมาตอนลง server ผมก็เลยใช้มันมาเรื่อยๆ (ก็คนมันเคยชินแล้วนี่นา)
แต่ก็นั่นแหละ ใน Ubuntu Server เราต้องลงเอง โดยใช้คำสั่ง
apt-get install vsftpd
จากนั้น เราก็มา config ค่าต่างๆของ FTP Server โดยแก้ไข config file ที่ /etc/vsftpd.conf
การแก้ไข อย่าลืม su ให้เป็น root ก่อนนะครับ ไม่งั้นแก้ไปแก้มา save ไม่ได้ เสียเวลาเราอีก (จากประสบการณ์เคยมาแล้วและเซ็งไปแล้ว)
ในไฟล์ vsftpd.conf แก้ไขค่า
anonymous_enable = NO
# ปิดการใช้ anonymous ftp
write_enable = YES
# ให้ user สามารถใช้ FTP write ได้
local_enable = YES
# ใช้ user จาก /etc/passwd
file_open_mode = 0777 (เพิ่มบรรทัดนี้เข้าไป)
local_umask = 0022
# ให้ file ที่ user upload ขึ้นไป มี permission เป็น 755 อัตโนมัติโดยไม่ต้องมาไล่ chmod กันทีหลัง
chroot_local_user = YES
chroot_list_enable = YES
chroot_list_file = /etc/vsftpd.chroot_list
# ให้ user อยู่แต่ใน home directory ของตัวเองเท่านั้น ยกเว้นให้ผู้ใช้ที่มีชื่ออยู่ในไฟล์ /etc/vsftpd.chroot_list ซึ่งไฟล์นี้ต้องสร้างขึ้นมาใหม่
เมื่อเสร็จแล้ว ให้ save file vsftpd.conf นี้ จากนั้นก็ไปสร้างไฟล์ใหม่ คือ /etc/vsftpd.chroot_list แล้วใส่ชื่อ user ที่ต้องการยกเว้นลงไป
จากนั้น restart service vsftpd โดยใช้ตำสั่ง
/etc/init.d/vsftpd restart
จากนั้นก็ทดลองใช้งาน ftp ครับ
How to restrict users to SFTP only instead of SSH
root@host # usermod -s /usr/lib/sftp-server username
root@host # echo '/usr/lib/stfp-server' >> /etc/shells
ทดสอบการทำงาน
echo "/usr/local/libexec/sftp-server" >> /etc/shells
At this point, you can test the account using sftp.
# sftp visitor@localhost
Connecting to localhost...
visitor@localhost's password:
sftp> ls
sftp> put test
Uploading test to /home/visitor/test
test 100% 415 0.4KB/s 00:00
sftp> ls
test
sftp> bye
Adding New Users To vsftpd
I found it rather strange that there arent any good tutorial that can explain how to add new users to vftpd. Google gives few results but most of them are trial and error method. So i decided to write this post after spending 1 hr trying to accomplish this simple task.
#edit /etc/vsftpd.conf or /opt/etc/vsftpd.conf
Open the vsftpd.conf file and search for chroot_list_enable=YES
Make sure it is YES. Do the same for the following variables
chroot_list_file=/etc/vsftpd.chroot_list or /opt/etc/vsftpd.chroot_list
chroot_list_enable=YES
Save and close the file
Create vsftpd.chroot_list in /etc/ or /opt/etc/
Add the username you want to export to ftp.
IMP: The user must already be a system user with a valid passwd. You must be able to find /home/
If the user you want to add is not a system user then create that user first before editing the above file.
#adduser
#passwd
Restart the vsftpd server using /etc/init.d/vsftpd restart or service vsftpd restart
Now you can log into ftp using the new user.
Back to Linux-How to