Wednesday, March 5, 2008

Increasing the file display limit on pure-ftp

By default, pure-ftp has a file display limit of 2000 files. To change this you need to edit the /etc/pure-ftp.conf file.

Step 1) Log into the machine and gain root access
Step 2) Use your favorite text editor to open /etc/pure-ftp.conf
Step 3) Search for the line (the values 2000 8 below may be different):

LimitRecursion 2000 8

Step 4) The first number after LimitRecursion is the display limit of files pure-ftp will show at anyone time. Change it to whatever values you feel is necessary for your server. The second number is the max subdirectory depth shown. You may change this value if necessary as well.
Step 5) Restart the pure-ftpd service

service pure-ftpd restart

Disable Apache Directory Listings

How to Disable Apache Directory Listings

The following procedure disables directory listings on an Apache web server using a .htaccess rule.

Go to the folder that you wish to disable directory listings on.
>cd /home/user/folder

Open .htaccess and add the following. If .htaccess doesn’t exist, you can create it.

>vi .htaccess

Insert the following line:

Options –Indexes

Save your modifications to the file and quit.

Enable PHP Error Logging

How to Enable PHP Error Logging

To enable error logging edit the /etc/php.ini file and locate the error_log and uncomment it by removing the semi-colon. Next put in the filename of where the errors and warnings should be logged to. Example:

error_log = /var/log/php_error

On production sites it is advisable to have the following options set:

error_reporting = E_ALL
display_errors = Off
display_startup_errors = Off
log_errors = On

This way the errors are logged to a file instead of being displayed on the website. If you prefer to change this, then switch to display_errors = On. Please visit http://us.php.net/manual/en/ref.errorfunc.php to see the error handling and logging section in the php manual for extensive details. Make sure to restart your webserver after making changes to the /etc/php.ini file.

How to block an IP/netblock using iptables

To block IPs in Linux you use a program called iptables that should already be installed on your server. To issue the neccessary commands you will need to login to your server via SSH as the root user.

Adding Temporary Rules:
To make only temporary rules that will not survive a reboot you can do the following steps. Once the rules are setup correctly they can be made permanent
Step 1) Determine which IPs need to be blocked from accessing your server.
Step 2a) To block a single IP issue the following command at the command prompt
iptables -I INPUT -s -j DROP
Step 2b) To block a range of IPs issue the following command at the command prompt. This will block all ips starting at and incrementing by one until it reaches and includes
iptables -I INPUT -s : -j DROP
Step 2c) To block a Netblock of IPs issue the following command at the command prompt. This will block all ips that fall into the subet by applying the to .
iptables -I INPUT -s / -j DROP

Removing Temporary Rules:
Step 1) At the command line type the following command to display the list of current rules:
iptables -L
Step 2) The previous command should have displayed "Chain INPUT" followed by a list of rules. The top most rule is considered to be Rule 1. Count down to the rule you wish to remove and note its number. So the first rule is Rule 1, the second is Rule 2, etc.
Step 3) Type in the following command where is the number of the rule you wish to delete
iptables -D INPUT

Making/Adding Permanant Rules:
The above rules will only last until your server is rebooted. There are two ways to make make the rules permant on a RHEL or CENTOS based system. You can setup temporary rules as shown above and then save the current configuration when you are sure all the rules are correct. To do this you type in the following command which will save the rules and make sure they run at the next reboot.
iptables-save > /etc/sysconfig/iptables; chkconfig iptables on

The second method is to add the rules manually to the file /etc/sysconfig/iptables and then restart iptables. The rules themselves remain mostly unchanged as seen below. The only difference is that you do not call the iptables command.
1a) To block a single IP add the following to /etc/sysconfig/iptables.
-I INPUT -s -j DROP
1b) To block a range of IPs add the following to /etc/sysconfig/iptables.
-I INPUT -s : -j DROP
1c) To block a Netblock of IPs add the following to /etc/sysconfig/iptables
-I INPUT -s / -j DROP
2) Restart iptables by issusing the following command:
service iptables restart
3) Ensure iptables runs at reboot
chkconfig iptables on

Removing Permanant Rules:
1) Delete the rules from the file /etc/sysconfig/iptables
2) Restart iptables by issusing the following command:
service iptables restart

Manually Password Protecting a Directory in Apache

Password Protecting a Directory in Apache

The following procedure details how to password protect a directory on a *nix server running Apache. If you have a control panel such as Plesk or cPanel, this can be handled from within the panel, but for a plain installation you will need to follow the steps below:

Use cd to move to the directory that you will be protecting.
>cd /home/user/directory

Create a file called .htaccess with the following contents. If .htaccess already exists you can simply add this to the end of the existing file:

>vi .htaccess

AuthName "Login Message"
AuthType Basic
AuthUserFile /home/user/directory/.htpasswd
AuthGroupFile /dev/null

require user user-name


“Login Message” should be replaced with the message that you want to show in the login dialog box that the browser will show. /home/user/directory/ should be the same path that your .htaccess file was created in. user-name needs to be replaced by the user that will be able to access the folder.

The last step is creating a .htpasswd file for the folder. This file stores the password for folder in an encrypted format:

>htpasswd -c .htpasswd user-name

You will be asked to enter and then confirm the password.

Disable Apache Directory Listings

How to Disable Apache Directory Listings

The following procedure disables directory listings on an Apache web server using a .htaccess rule.

Go to the folder that you wish to disable directory listings on.
>cd /home/user/folder

Open .htaccess and add the following. If .htaccess doesn’t exist, you can create it.

>vi .htaccess

Insert the following line:

Options –Indexes

Save your modifications to the file and quit.

How do I determine what version of the Linux kernel my system is running?

How do I determine what version of the Linux kernel my system is running?

The command uname -a will tell you the system defined kernel name, hostname, kernel version, hardware name, processor type, hardware platform and operating system name. Executing a uname -r will tell you just the kernel version. Run a ‘man uname’ for specifics.