August 12, 2015

How to Install vsftpd Centos/RHEL/Fedora

vsftpd –Very Secure File Transport Protocol Daemon.


Cài đặt vsfptd

Chạy dòng lệnh sau
sudo yum install vsftpd
Ngoài ra chúng ta cần cài đặt thêm FTP client
sudo yum install ftp

Sau khi tải và cài đặt xong, bạn đã có thể sử dụng ngay được rồi. Tuy nhiên, cần cấu hình thêm một chút để bảo mật hơn cho VPS.
B2: Cấu hình vsftpd.
– Bạn mở file cấu hình hình bằng chương trình vi/vim hoặc nano, ở đây mình sử dụng vi:
1
vi /etc/vsftpd/vsftpd.conf
– Chỉnh sửa một số option sau:
– Thiết lập anonymous_enable từ NO thành YES để không cho phép những người không có tài khoản ftp truy cập lên ftp server.
anonymous_enable=YES
# Bỏ comment dòng local_enable, chuyển thành Yes và cho phép write
local_enable=YES
#Bỏ comment dòng chroot_local_user và chuyển thành Yes để user không thể truy cập các folder khác của server
chroot_local_user=YES
ascii_upload_enable=YES
ascii_download_enable=YES
ftpd_banner=Welcome to LADAIHIEP FTP service
##và thêm dòng này vào cuối
use_localtime=YES
Lưu lại và thoát, xong thì khởi động dịch vụ và cho phép khởi động cùng CentOS
[root@hocmang ~]# service vsftpd restart
Starting vsftpd for vsftpd:                                [  OK  ]
[root@hocmang ~]# chkconfig vsftpd on
B3: Tạo FTP user
Bước tiếp theo chúng ta sẽ tạo user để kết nối FTP
useradd userftp -d /home/domain.com/  # add user vào thư mục /hom/domain của bạn .com
or useradd userftp -d /var/www/html
passwd userftp  # set mât khẩu cho user
Phân quyền cho account
chown -R userftp /home/domain.com/
chown _R userftp /var/www/html
chmod -R 777 /home/domain.com/
B4: Kết nối với FTP server
[root@hocmang ~]# ftp 192.168.80.100 Connected to 192.168.80.100 (192.168.80.100). 220 Welcome to Hocmang FTP service. Name (192.168.80.100:root): thangphan 331 Please specify the password. Password: 500 OOPS: cannot change directory:/home/thangphan Login failed. ftp>
bạn sẽ gặp thông báo “500 OOPS: cannot change directory:/home/thangphan”
Đăng nhập không thành công, bởi vì SELinux chặn user log in vào ftp server, để cho phép thì bạn dùng câu lệnh sau:

[root@hocmang ~]# setsebool -P ftp_home_dir on


Để cho phép kết nối từ xa, bạn phải vào iptables allow port 21 dùng cho ftp
[root@hocmang ~]# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state –state NEW –dport 21 -j ACCEPT

Disable Selinux  » open the file /etc/selinux/config and find the line
SELINUX=enforcing
and replace with
SELINUX=disabled
now reboot the server and try again.

Sử dụng FileZilla để kết nối với FTP server


Bạn sẽ không kết nối được, Connection timed out, bạn tiến hành sửa file iptables-config như sau:
[root@hocmang ~]# vi /etc/sysconfig/iptables-config
IPTABLES_MODULES=”ip_conntrack_ftp
[…]

Khởi động lại dịch vụ:
[root@hocmang ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[root@hocmang ~]# 
service iptables restart 
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]
iptables: Loading additional modules: ip_conntrack_ftp     [  OK  ]
Tiếp đến thử đăng nhập lại bằng FileZilla xem  graphic
Tải hướng dẫn bằng PDF

0 comments:

Post a Comment