Thứ Năm, 13 tháng 2, 2014

// // Leave a Comment

FTP Server - CentOS 5.10

I/ Cài đặt FTP:
FTP là dịch vụ cung cấp cơ chế truyền tin dưới dạng file thông qua mạng tcp. Có nhiều chương
trình ftp server sử dụng trên Linux như: Vsftpd, Wu-ftpd, PureFTPd, ProFTPD,…

Port = 20 [ Control Connection ]
           21 [ Data Control ]
 [root@cent5 ~]# yum install vsftpd
Kiểm tra lại:
 [root@cent5 ~]# rpm -qa|grep vsftpd
vsftpd-2.0.5-28.el5
II: Cấu hình:
Xem các file cấu hình liên quan đến vsftpd:
 [root@cent5 ~]# rpm -ql vsftpd
/etc/logrotate.d/vsftpd.log
/etc/pam.d/vsftpd
/etc/rc.d/init.d/vsftpd
/etc/vsftpd
/etc/vsftpd/ftpusers
Chứa cac user ko dc login vaof FTP.Vì vấn đề bảo mật trên hệ thống Linux, dịch vụ ftp không cho phép người dùng root và một số người dùng đặc biệt khác đăng nhập để sử dụng dịch vụ ftp. Nếu chúng ta muốn người dùng root và một số người dùng khác trong file ftpusers được phép đăng nhập qua ftp, chúng ta thêm ký tự (#) trước tên người dùng.
Ví dụ chúng ta muốn người dùng root được phép đăng nhập ftp:
# root
/etc/vsftpd/user_list # Chi co cau user trong file nay dc phep login neu: userlist_deny=NO
/etc/vsftpd/vsftpd.conf #File cấu hình chính chứa những tùy chọn cấu hình cho FTP server.
/etc/vsftpd/vsftpd_conf_migrate.sh
/usr/sbin/vsftpd
/usr/share/doc/vsftpd-2.0.5
/usr/share/doc/vsftpd-2.0.5/AUDIT
............
Sửa file cấu hình vsftpd.conf như sau:
[root@cent5 ~]# vi /etc/vsftpd/vsftpd.conf
anonymous_enable=NO# không cho phép anonymous login vào :12
local_enable=YES  # Cho phép người dùng cục bộ login vào :15
write_enable=YES  # Cung cấp quyền ghi cho người dùng :18
xferlog_enable=YES  # Cho phép ghi log : 39
xferlog_file=/var/log/vsftpd.log  # Vị trí file log : 52
connect_from_port_20=YES # Sử dụng cổng 20 cho FTP-Data : 42
ftpd_banner=Trung Tam Dao Tao Mang May Tinh Athena  : 85
userlist_enable=YES  # Những người dùng trong user_list bị cấm truy cập : 117
 #chroot_list_file=/etc/vsftpd/chroot_list # Chua cac user dc phep duyet cac thu muc ben ngoai homedir : 98
#anon_upload_enable=YES # không cho phép người dùng nặc danh upload file qua ftp. Nếu chúng ta muốn cho phép người dùng nặc danh upload file qua ftp thì bỏ ký tự # ở đầu đi. Chú ý: chúng ta phải để anonymous_enable=YES thì khi bỏ ký tự # mới có giá trị. : 27

- Khởi động và test - đã disable selinux:
[root@cent5 vsftpd]# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]
[root@cent5 vsftpd]# /etc/init.d/vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[root@cent5 vsftpd]# /etc/init.d/iptables stop
Flushing firewall rules:                                   [  OK  ]
Setting chains to policy ACCEPT: filter                    [  OK  ]
Unloading iptables modules:                                [  OK  ]

Chú ý: Khi chạy vsftpd trên CentOS5. Nếu bật chức năng SELinux = enforcing
(/etc/sysconfig/selinux) thì ta cần phải set biến ftp_home_dir = on

- Kiểm tra biến ftp_home_dir:
[root@cent5 ~]# getsebool ftp_home_dir
ftp_home_dir --> off

- Set biến ftp_home_dir = on:
 [root@cent5 ~]# setsebool -P ftp_home_dir 1 # Chờ hơi lâu
haitruong homedir /tmp/haitruong or its parent directory conflicts with a
defined context in /etc/selinux/targeted/contexts/files/file_contexts,
/usr/sbin/genhomedircon will not create a new context. This usually indicates an incorrectly defined system account.  If it is a system account please make sure its login shell is /sbin/nologin.
hieutruong homedir /tmp/hieutruong or its parent directory conflicts with a
defined context in /etc/selinux/targeted/contexts/files/file_contexts,
/usr/sbin/genhomedircon will not create a new context. This usually indicates an incorrectly defined system account.  If it is a system account please make sure its login shell is /sbin/nologin.
anhtuyet homedir /tmp/anhtuyet or its parent directory conflicts with a
defined context in /etc/selinux/targeted/contexts/files/file_contexts,
/usr/sbin/genhomedircon will not create a new context. This usually indicates an incorrectly defined system account.  If it is a system account please make sure its login shell is /sbin/nologin.
- Thử kiểm tra lại:
[root@cent5 ~]# getsebool ftp_home_dir
ftp_home_dir --> on
 - Tạo FTP home dir:
[root@cent5 ~]# mkdir /home_ftp

- Tạo User haicute cho phép truy cập FTP server:
 [root@cent5 ~]# useradd -d /home_ftp/haicute haicute
[root@cent5 ~]# passwd haicute
Changing password for user haicute.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
- Thử tạo 1 file bất kỳ:
[root@cent5 ~]# touch /home_ftp/haicute/haicutene.txt
- FTP Server cần mở port 20 và 21 trên firewall, hoặc ta cũng có thể disable firewall:
[root@cent5 ~]# /etc/init.d/iptables stop
Flushing firewall rules:                                   [  OK  ]
Setting chains to policy ACCEPT: filter                    [  OK  ]
Unloading iptables modules:                                [  OK  ]
[root@cent5 ~]# chkconfig iptables off
- Khởi động lại dịch vụ và test thử:
[root@cent5 ~]# /etc/init.d/vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]

0 nhận xét:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.