[root@centos ~]# yum -y install vsftpd
Thiết lập vsftpd.conf
[root@centos ~]# vi /etc/vsftpd/vsftpd.conf
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO ← Cấm user anonymous login
# Activate logging of uploads/downloads.
xferlog_enable=YES ← Ghi nhớ vào log /var/log/vsftpd.log
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log ← Ghi nhớ vào log /var/log/vsftpd.log
# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=NO ← Ghi nhớ vào log /var/log/vsftpd.log
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
ascii_upload_enable=YES ← Cho phép upload
ascii_download_enable=YES ← Cho phép download
# You may fully customise the login banner string:
ftpd_banner=Welcome to blah FTP service. ← Không biểu thị tên và version phần mềm khi login FTP
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_local_user=YES ← Cấm access vào thư mục trên mặc địnhs
chroot_list_enable=YES ← Được phép access
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list ← Danh sách user được phép access
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
ls_recurse_enable=YES ← Cho phép xoá thư mục
Thêm vào
local_root=public_html ← Thư mục khi login ~/public_html
use_localtime=YES ← Chỉnh thời gian
3. Khởi động vsftpd
[root@centos ~]# /etc/rc.d/init.d/vsftpd start ← Khởi động vsftpd
vsftpd 用の vsftpd を起動中: [ OK ]
[root@centos ~]# chkconfig vsftpd on ← Setting khởi động tự động vsftpd
[root@centos ~]# chkconfig --list vsftpd
vsftpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5. Mở cổng 21 từ router
Cách 2:
Cài đặt FTP trong 5 phút.
Phút đầu tiên:
# cài đặt VSFTP từ internet và mở ngay file cấu hình ngay sau khi cài đặt (vậy mới đỡ tốn thời gian)
apt-get install vsftpd && nano /etc/vsftpd.conf
Phút thứ 2:
Tìm trong /etc/vsftpd.conf bật 3 option này lên, nếu đã bật rồi thì save lại
local_enable=YES # cho phép user trong mạng local
write_enable=YES # cho phép users upload file lên
chroot_local_user=YES # giới hạn users trong thư mục riêng của chính user đó
nếu đã bật rồi thì save lại, mau mau nhào ra ngòai shell phang :
#/etc/init.d/vsftpd restart
Phút thứ 3 và 4:
Tạo 1 user theo yêu cầu của sếp yêu cầu và tạo home directory cho user đó, có toàn quyền truy nhập:
#useradd ftp5phut && passwd ftp5phut
--> nhập pass cho user này
#mkdir /home/ftp5phut && chown ftp5phut /home/fpt5phut
Default firewall của linux sẽ block fpt, phải add rule cho nó chấp nhận connection vào từ local và internet với port 21
iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
Nếu dùng shorewall thì nhào dzô /etc/shorewall/rules, nhưng mà vậy thì lâu, phang rule thẳng bằng command echo cho lẹ, bạn chẳng còn bao lâu cho phút thứ 3 này :(
echo ACCEPT net $FW tcp 21 >> /etc/shorewall/rules
echo ACCEPT loc $FW tcp 21 >> /etc/shorewall/rules
shorewall restart
Phút thứ 5:
test nhé, từ windows xp command promt, phang gấp:
C:\Documents and Settings\Administrator>ftp 192.168.0.12
Connected to 192.168.0.12.
220 Welcome Unix VSFTP - power by PhuLe
User (192.168.0.12:(none)): ftp5phut
331 Please specify the password.
Password:
230 Login successful.
ftp>
Giờ mình tạo một thư mục tên abc để kiểm tra chức năng write được hay không,
ftp>mkdir abc
257 "/abc" created
Kiểm tra xem nó có thiệt hay không nhá,
ftp>dir
200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. drwx------ 2 1008 1008 4096 Sep 07 06:47 abc 226 Directory send OK. ftp: 61 bytes received in 0.00Seconds 61000.00Kbytes/sec.
Xong !!!
Tóm tắt: Nếu phang theo kiểu này thì user chỉ có thấy được thư mục riêng của chính mình, không thấy đường dẫn của thư mục trên thanh address trong browser. Tất cả data của user upload lên đều nằm trong /home/tênuser. Bài viết này hướng dẫn bạn tạo một ftp server đơn giản phục vụ cho việc đáp ứng tức thời, những option cao cấp khác bạn có thể tìm hiểu thêm để tăng tính ổn định cho server, vd như giới hạn một ip download 3 connection để điều tiết băng thông:
add thêm dòng này trong /etc/vsftpd.conf của bạn
max_per_ip=3
#/etc/init.d/vsftpd restart
Vậy thì khi ông ngọai nào dùng flashget download nhiều hơn 3 connection sẽ bị server chửi câu error 421 đại khái giống vầy
421 There are too many connections from 210.77.77.77 (chết mày chưa !!!)
Nếu bạn để ftp trong DMZ hoặc phía sau firewall linux thì cần phải config cho NAT cho firewall, cái này bạn tự phang nhé, vì nó nằm trong khuôn khổ bài viết 5 ngày (5 phút làm được, nhưng chắc gấu lắm, khặc khặc).
Cái quan trọng là giờ tôi đã cài đặt vsftp rồi đã chuyển nó vào /var/www nhưng khi tôi upload các file & foler thì báo ko thể upload đc. Nếu tôi muốn upload lên host thì lại phải chmod folder thành 777. Vậy có cách nào khắc phục đc không.
Tôi ví dụ nếu bạn đã có user vnlamp rồi thì giờ nên chuyễn directory của user vnlamp vào /var/www
#usermod -d /var/www -s /sbin/nologin vnlamp
và nhớ là :
#chmod -R 700 /var/www
#chown -R vnlamp /var/www
Không có nhận xét nào:
Đăng nhận xét