Sunday 13 January 2013

PHP show blank page on CentOS

Check if php-mysql plugin is installed.
(run phpinfo() and search for "mysql" and the browser)

If not, install  it and restart web server

Slow SSH login on CentOS

1. Make sure  /etc/hosts has an entry with your server’s external IP and hostname.
2. Edit the SSH server configuration file /etc/ssh/sshd_config and add (or change, if already present) the UseDNS parameter to read “no”. After that restart sshd:

#echo "UseDNS no" >> /etc/ssh/sshd_config
#service sshd restart


Friday 11 January 2013

Using custom folder as DocumentRoot in httpd CentOS


If you use different directory as DocumentRoot (for example /website), httpd will complaint and show you this error message:

DocumentRoot must be a directory

This is due to the Security-Enhanced Linux (SELinux) which is a mandatory access control security mechanism implemented in kernel. For more info you can visit SELinux@wikipedia

To overcome this problem, we need to set the proper access control to our website folder so that it can be recognized by apache httpd

sudo chcon -Rv --type=httpd_sys_content_t /website

Thursday 3 January 2013

Install and Configure Vsftpd on CENTOS

SOURCE: http://duyquangou1989.blogspot.com/2010/09/cau-hinh-ftp-vsftpd-centos.html

Cấu hình FTP (VSFTPD) Centos
1. Giới thiệu
- Là 1 dịch vụ dùng để chia sẻ tài nguyên.
- FTP là FTP server chạy trên môi trường Linux.
- VSFTP sẽ phân quyền dựa trên cấu hình và File Permisson.

2. Yêu cầu
Xây dựng DNS cho domain linux106.com sao cho phân giải được record ftp.linux106.com

a. Cài đặt FTP Server
- Kiểm tra gói phần mềm, nếu chưa cài thì cài vào (xem mục cài đặt)
#rpm -qa vsftpd

- Tắt Firewall, SELinux

b. Cấu hình FTP Server - vsftpd

- File cấu hình /etc/vsftpd/vsftpd.conf


3. Các bài Lab

3.1 Lab 1
Cấu hình cho phép anonymous được phép truy cập FTP Server
- Sủa dòng 12 trong file cấu hình với nội dung như sau:
anonymous_enable=YES

- Start dịch vụ vsftpd
#service vsftpd start

- Kiểm tra:
+ dùng trình duyệt explorer trên Windows
+ dòng lệnh: mở CMD, rồi gõ lệnh sau:
ftp ftp.linux106.com
+ lưu ý: thư mục root của ftp là /var/ftp

3.2 Lab 2
Thay đổi thư mục gốc của FTP Server là /data/ftp
- Tạo thư mục
#mkdir /data
#mkdir /data/ftp

- Thêm vào cuối file cấu hình nội dung sau:
anon_root=/data/ftp

- restart lại dịch vụ
#service vsftpd restart

- Kiểm tra bằng trình duyệt explorer hoặc dòng lệnh.

3.3 Lab 3
Cấu hình để anonymous được upload file lên thư mục /upload trên Ftp Server
- Tạo thư mục
#mkdir /data/ftp/upload

- Chỉnh sửa nội dung sau trong tập tin cấu hình:
+ dòng 18
write_enable=YES
+ dòng 27
anon_upload_enable=YES

- restart dịch vụ
#service vsftpd restart

- Cấp quyền cho thư mục /data/ftp/upload
#chmod 757 /data/ftp/upload

- Kiểm tra.

3.4 Lab 4
Cấu hình để anonymous được upload thư mục lên thư mục /upload trên Ftp Server
- Chỉnh sửa nội dung sau trong tập tin cấu hình:
+ dòng 18
write_enable=YES
+ dòng 31
anon_mkdir_write=YES

3.5 Lab 5
Cấu hình để có thể xóa, đổi tên file
- Thêm vào cuối file tập tin cấu hình nội dung sau:
anon_other_write_enable=YES

3.6 Lab 6
Cấu hình sao cho anonymous upload file lên và download được file đó về
- Thêm nội dung sau vào cuối file cấu hình /etc/vsftpd/vsftpd.conf
anon_usmask=022

- Restart dịch vụ
#service vsftpd restart

- Kiểm tra

- Chú ý:
Nếu download về không được thì vào tools -> internet options -> sercurity ->trusted sited ->sites -> add

3.7 Lab 7
Cho phép các user local login vào Ftp Server
- Chỉnh file cấu hình nội dung dòng 15 như sau:
local_enable=YES

- restart dịch vụ
#service vsftpd restart

- Kiểm tra
Tạo user hv1 và hv2 và login vào để kiểm tra.

3.8 Lab 8
Cấm user hv1 login vào Ftp Server
- Chỉnh file cấu hình dòng 115
userlist_enable=YES

- thêm user hv1 vào cuối file
/etc/vsftpd/user_list

- restart dịch vụ
#service vsftpd restart

- kiểm tra
login vào Ftp Server bằng user hv1 để kiểm tra.

3.9 Lab 9
Cấm máy bên cạnh truy xuất FTP Server
- Chỉnh sửa file cấu hình, dòng 116
tcp_wrappers=YES

- thêm nội dung sau vào cuối file /etc/hosts.deny
vsftpd: 192.168.9.107

- restart dịch vụ
#service vsftpd rertart

- Kiểm tra
Truy cập FTP Server từ máy 192.168.9.107 vào máy xem có bị cấm không?
copy from chuyen.org
vsftp.conf http://vsftpd.beasts.org/vsftpd_conf.html

Wednesday 2 January 2013

Vsftpd OOPS: cannot change directory:/home/dev

Solution:
#Setenforce 0

or

getsebool -a | grep ftp
setsebool -P ftp_home_dir on
getsebool -a | grep ftp