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.