6 Sept 2011

How to set or change root password in mysql server

A very important step in a database configuration, and many times forgotten, is the setup of a root password. This easy procedure will increase the security for your databases, even if you're only using a personal server on your laptop there is always a chance for an intruder to get sensible data.



In a shell we use the mysqladmin command to achieve this as follows for a local database server:
mysqladmin -u root password "the_new_password"
 Or a remote one:
mysqladmin -u root -h host_name password "the_new_password"
Next you should restart the database server, to make sure the new security settings are used.
sudo /etc/init.d/mysql restart

14 Jul 2011

Wordpress stopped working after upgrade to version 3.2

As usual, as soon as I noticed the new version announcement at the top of the wordpress administration interface I instructed it to start. However, immediately after the upgrade to version 3.2 the wordpress installation stopped working.
I could not access wp-admin to try and fix whatever went wrong and, at the same time, the visitors would not be able to reach the blog.

So I went to check the server logs in cPanel and found out that the problem was somehow related to the WP to Twitter plugin, but how could I fix it without access to the administration panel?

The errors found:
[warn] mod_fcgid: stderr: PHP Warning: require_once() [function.require-once]: Unable to access /var/www/vhosts//httpdocs/wp-includes/class-json.php in /var/www/vhosts//httpdocs/wp-content/plugins/wp-to-twitter/functions.php on line 52
[warn] mod_fcgid: stderr: PHP Warning: require_once(/var/www/vhosts//httpdocs/wp-includes/class-json.php) [function.require-once]: failed to open stream: No such file or directory in /var/www/vhosts//httpdocs/wp-content/plugins/wp-to-twitter/functions.php on line 52
[warn] mod_fcgid: stderr: PHP Fatal error: require_once() [function.require]: Failed opening required '/var/www/vhosts//httpdocs/wp-includes/class-json.php' (include_path='.:/usr/share/pear') in /var/www/vhosts//httpdocs/wp-content/plugins/wp-to-twitter/functions.php on line 5


Easy solution: manually remove the plugin 

Accessing through FTP I went to the plugins directory inside wordpress instalation directory ( in my case it is /httpdocs/wp-content/plugins ) and removed the plugin directory 'wp-to-twitter'.
 Wordpress was available again so I went to wp-admin and 're'installed WP to Twitter. All configurations were kept so everything ended up alright.

Anyway, next time I'll make sure to check compatibility information regarding installed plugins and update them or disable before a wordpress upgrade.

7 Jun 2011

Stop ssh attacks with fail2ban in CentOS

Every server on the web is subject to frequent breaking attempts, and when there are services running on default ports like 22 for ssh it becomes even more common.

However, using a simple tool freely available called fail2ban we can easily keep those intruders out of our machines without having to change our service ports.

In order to get fail2ban working on a CentOS machine you just have to install it straight from the repositories using:

$ yum install fail2ban


And then edit the configuration file to activate ssh and adjust some key parameters.

#edit configuration using your favourite editor ( I like vi )
$ vi /etc/fail2ban/jail.conf 

To activate ssh access monitorization find [ssh-iptables] section and make it active
enabled  = true
and  point the script to the right log file
logpath  = /var/log/secure

Then you might want to change the following aditional parameters:

  • ignoreip - A comma separated list of IPs you consider safe and would like the script to ignore regarding access attempts (this comes in the top of the configuration file)
  • action - Change the sender and recipient emails to get notifications regarding fail2ban actions
  • maxretry - The maximum number of failed login attempts before an IP get banned
Now just restart the service
/etc/init.d/fail2ban restart
and test it. Just make sure you do not get locked out. Anyway, the ban will be released after 10 minutes (default value).


[UPDATE] Forgot to let you know that if you are using Ubuntu you can also install fail2ban from the repositories and it works straight out of the box with no additional configurations required:
$ sudo apt-get install fail2ban