Thursday, July 18, 2013

Slow ssh in RHEL/CentOS

It's everywhere and so it's also here, if ssh to Red Hat or CentOS takes forever, here's a quick fix:
# sed -i 's/^#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
# sed -i 's/^#GSSAPIAuthentication no/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
# sed -i 's/^GSSAPIAuthentication yes/#GSSAPIAuthentication yes/g' /etc/ssh/sshd_config
# service sshd restart

Monday, May 6, 2013

BASH CLI turn monitor off / blank screen

So you want to get your screen blank or get your monitor into standby mode from the CLI?
Add the following to your .bashrc:


alias blank='sleep 1 && xset dpms force standby'

From there on, just use the command blank from your terminal.

Saturday, April 6, 2013

Quickly add rules to IPTABLES on CentOS/RHEL 5.x using a script

Older iptables lack the -C switch so you have to use bash to check whether a rule already exists before appending it. Works like this:

if [ ! "`iptables-save | grep 'dport 21'`" ]; then iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT;fi
if [ ! "`iptables-save | grep 'dport 22'`" ]; then iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT;fi
if [ ! "`iptables-save | grep 'dport 80'`" ]; then iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT;fi
service iptables save
Probably not the most elegant solution, but it works. 

Quickly disable SELinux in a setup script

So we all know how to disable SELinux manually, but what about doing so as part of a setup script?
Easy, got to love sed!

Setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/sysconfig/selinux && cat /etc/sysconfig/selinux
Repeat on /etc/selinux/config for Centos 7

Wednesday, February 20, 2013

Wednesday, February 6, 2013

phpMyAdmin - Error

Don't you just love them errors? They make you stress your mind, check everything all over again, force to communicate with people around you and basically waste your time.

One such lovely error is:

Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.
There are quite a few answers online for fixing this problem but sometimes, especially if there's a chance you did something silly along the way, it just won't help.  So, yet another solution if everything else fails:

# chmod 0777 /var/lib/php/session

Monday, February 4, 2013

Apache cluster active server

So you have Apache running in a cluster and you want to know which server is active right now. PHP can help you there.

Put this line of code in whoami.php

<?php system('hostname', $retval); ?>