Tuesday, 20 May 2014

WordPress Preventing Password Protecting a Directory


Password protecting a subdirectory using the cPanel icon (or a .htpasswd file) will be unsuccessful if WordPress is installed in the public_html directory with permalinks enabled.

Edit .htaccess File

  1. Edit the .htaccess file in your WordPress home folder (public_html) and remove the line  of code shown in bold below:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
  2. Replace that line with this new line:

    RewriteRule ./ /index.php [L]

    The final code snippet will look like this:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ./ /index.php [L]
    </IfModule>
    # END WordPress
  3. Save your changes.

Reset Permalinks

  1. From the left-hand navigation menu in WordPress, click Settings > Permalinks. Note the current setting. If you are using a custom structure, copy or save the custom structure somewhere.
  2. Select Default.
  3. Click Save Settings.
  4. Change the settings back to the previous configuration (before you selected Default). Put the custom structure back if you had one.
  5. Click > Save Settings.
This should reset the permalinks and prevent any posts or pages from returning a 404 Page Not Found error. You should now be able to password protect a subdirectory.

Saturday, 17 May 2014

Create SUDO user in cPanel

For security you might want to disable direct SSH login as root.

First of all login as root and create an user

#useradd sshadmin
#passwd sshadmin

Now add this user to wheel group from WHM

WHM -> Security Center -> Manage Wheel Group Users

OR from command line

#usermod -G wheel sshadmin

Now open /etc/ssh/sshd_config and set

PermitRootLogin no

Restart the ssh service

/etc/init.d/sshd restart

Now you can ssh to server as user sshadmin and run the command “su -” to switch to root user.

Now the thing is that “su -” asks for root password. If you don’t want to remember the root password then you can add the user sshadmin to sudo user list. Add below lines to /etc/sudoers

sshadmin    ALL=(ALL)       ALL

Now run the command “sudo su -” and it will directly switch to user root without asking password.

Saturday, 15 March 2014

Script to create a directory with current date and sync the folders

Script to create a directory with current date and sync the folders

#!/bin/bash
# rsync script
mkdir /home/user/backup/`date -I`
rsync -avz --progress /home/user/rsync1/ /home/user/backup/`date -I`

Find & Replace across multiple files in linux


Command to Find & Replace a word with another across multiple files in linux

>>> command to replace "test" with "testing" in multiple files

# find . -name "*.html" -print | xargs sed -i 's/test/testing/g'

Script to delete mail on a specific time period

Script to delete all mails dated 2011 from the mail accounts. email account: user@example.com


=====================
1) touch --date "2011-06-19" /home/example/mail/example.com/user/cur/start  
         >>> creating a file with particular date [from that date onwards] that we want to delete

2) touch --date "2011-12-31"/home/example/mail/example.com/user/cur/end
        >>> file created with a particular date [upto that date] that we want to delete

3) find . -newer /home/example/mail/example.com/user/cur/start -not -newer /home/example/mail/example.com/user/cur/end -exec mv {} --target-directory=/home/example/mov_mail/ ';'
       >>> script will move mails dated from 2011-06-19 to 2011-12-31 to the folder /home/example/mov_mail/

4) deleted the contents in the folder /home/example/mov_mail/

Remove IP from drop list in iptables

List existing chains

Type the following command to list current IPs in tables:
iptables -L -n

To display line number along with other information, enter:
iptables -L INPUT -n --line-numbers

You will get the list of all blocked IP. Look at the number on the left, then use number to delete it. For example delete line number 10 (subner 134.175.0.0/16), enter:
iptables -D INPUT 10

======================================================

Run :
iptables-save| grep xx.xx.xx.xx

to get the exact rule command used to enabled the block. It will be something like:

-A INPUT ! -i lo -s xx.xx.xx.xx -j DROP

Take this command, replace the -A with -D and run it through iptables:

iptables -D INPUT ! -i lo -s xx.xx.xx.xx -j DROP 

Plesk mx record change

To change an MX, A or CNAME record do the following:
    Log into Plesk
    Click on Domains
    Click on the domain name in question
    Click on the arrow next to the words "Web Site" and choose DNS Settings


To change an MX record:
    Click on the MX record to edit
     Leave "Record type" as MX
     Leave "Enter mail domain" blank
     Change the "Enter mail exchanger" to the name of your mail server
     If necessary, change the "Specify priority of mail exchange server" to the desired setting.

=============================================

To get to the DNS editor, do the following:
    Log into Plesk
    Under Hosting Services, click on Domains
    Find the domain in question, and click on the corresponding link that says "Control Panel" (on the far right side)
    Click the "Websites & Domains" tab
    Click the "DNS Settings" link
    Click on "[Manage]" for the appropriate domain
     To edit an existing record, click on the record under "Host"

MX records
     Change the "Record type" to MX (if necessary)
     "Mail domain" should be left blank
      Set the "Mail exchange server" the name of your mail server (for example ghs.google.com)
      The party who gave you the mail exchange server name may have also given you a priority number; if   not, "very high(0)" is perfect

After making your changes, click on OK. The changes will take between 4 to 8 hours to update worldwide.