Main Page

From Cheatsheet
Revision as of 01:41, 1 March 2011 by Admin (talk | contribs) (→‎HTOP)
Jump to navigation Jump to search

This is my wiki, containing all of my SECRETS. Also I would like to note that... YOU LOSE THE GAME! TG Fukung Pointless Sites Addicting Pacman Games


Notice: blah blah


Specified Guides

We are going to change this up a little. Links to the Specified Guides will be first now.

Coremanaged phpmyadmin
Coremanaged Pure-ftp
Coremanaged SSL
cpanel
Custom Compiling
Email walkthrough
Exim
Firewalls
FTP walkthrough
Godaddy, nameserver setup
HTTPD AND APACHE
Memory and load
Modsec
Mysql
Perl
PHP =
Plesk
Ramdisk
Shared server list
Suphpfix

CMS guides

Drupal Guide
Drupal Modules
Joomla Guide
Joomla Modules
Wordpress Guide
Wordpress Plugins

Core system understanding Guides

These are to help you better understand the operating system itself. (Coming shortly)

Understanding Linus startup

Cpanel& WHM Hackery

2 domains 1 docroot
2 domains 1 ip

General Shit

.htaccess

Addon domain issues

If you come across this error:

" Error from park wrapper: Using nameservers with the following IPs:
174.132.129.99,174.132.129.98 Sorry, the domain is already pointed to an IP
address that does not appear to use DNS servers associated with this server.
Please transfer the domain to this servers nameservers or have your
administrator add one of its nameservers to /etc/ips.remotedns and make the
proper A entries on that remote nameserver. "

go to tweak settings an check the option to:

Allow Creation of Parked/Addon Domains that resolve to other servers (i.e. domain transfers)

ChkServd

enable chkservd

/usr/local/cpanel/bin/tailwatchd --enable=Cpanel::TailWatch::ChkServd

Disable chkservd

/usr/local/cpanel/bin/tailwatchd --disable=Cpanel::TailWatch::ChkServd


Crond

For help with crond entries go to this url

http://www.linuxhelp.net/guides/cron/

cron log location

vim /var/log/cron

Location of the main cron

vim /var/spool/cron/root

Location of the cpanel users crons

/var/spool/cron/

Location of the specific crons, daily weekly monthly...etc

vim /etc/cron.

Tab complete to see all of the options

Add this to the main cron to make all mail in the .sent/cur directory erase after being 15 days old.

0 3 * * * find /home*/*/mail/*/*/cur /home*/*/mail/*/*/.Sent/cur -type f -mtime +30 -exec rm {} \;

REMINDER CRON Also another nice cron for those of us who forget to clock out or in. This will open the
time clock in a new window to remind you to clock out. Use the link above to set your own time.

55 08 * * 1-5 art env DISPLAY=:0.0 firefox --new-window https://tc.int.liquidweb.com/content/index.html

CSS not loading

Come accross a page that doesnt want to load its css on a vps? Log into the server and do the following.

curl -v 'http://domain.com/(path to the css file goes here)'

If in that's response this line is returned

* transfer closed with 1386 bytes remaining to read
* Closing connection #0
curl: (18) transfer closed with 1386 bytes remaining to read

OR an easier way is to use these if they return nothing, go to next step.

cat /usr/local/apache/conf/includes/* | grep EnableSendFile
cat /usr/local/apache/conf/httpd.conf | grep EnableSendFile

Copy and paste the following to fix

echo "EnableSendFile Off">>/usr/local/apache/conf/includes/pre_main_global.conf
/etc/init.d/httpd restart

Custom php.ini

For SuPhP, First copy the php.ini over

cp /usr/local/lib/php.ini /home/(username)/public_html/php.ini
chown (username). /home/(username)/public_html/php.ini

In .htaccess under public_html, add the following:

suPHP_ConfigPath /home/user/public_html 
<Files php.ini> 
order allow,deny 
deny from all 
</Files>

Note: the local php.ini REPLACES the system one, it does not override like a .htaccess setting does.

For CGI, First copy the php.ini over

cp /usr/local/lib/php.ini /home/(username)/public_html/php.ini
chown (username). /home/(username)/public_html/php.ini

In .htaccess under public_html, add the following:

AddHandler php-cgi .php .htm 
Action php-cgi /home/(username)/public_html/cgi-bin/php5.cgi

if by chance the php5.cgi does not exist please add it with the following contents.

#!/bin/sh
export PHPRC=/home/(username)/public_html/php.ini
exec /usr/local/cpanel/cgi-sys/php5

Disable root login

useradd lwstaff
passwd (assign a password)
usermod -G wheel lwstaff
vim /etc/ssh/sshd_config

change

PermitRootLogin = yes 

to no and un-comment it. restart sshd and test your work.

/etc/init.d/sshd restart

DNS Cheats

Adding a wildcard to every dns record

for i in `cat /var/cpanel/users/*| grep DNS|cut -d = -f 2`; do echo "* IN CNAME $i." >> /var/named/$i.db;done

Adjusting all ttls on a server to 300

#check current TTLs and serial number
grep --color -e '^\$TTL.*' /var/named/*.db
grep --color -e '[0-9]\{10\}' /var/named/*.db   # this will be the serial number, 10 numbers in a row
#also check that date works as expected/is newer than the serial numbers currently existing
date +%Y%m%d%H 
#the -i flag will create backups in the same directory, liquidweb.com.lwbak for example
sed -i.lwbak -e 's/^\$TTL.*/$TTL 300/g' -e 's/[0-9]\{10\}/'`date +%Y%m%d%H`'/g' /var/named/*.db
#check your work
grep --color -e '^\$TTL.*' /var/named/*.db
grep --color -e '[0-9]\{10\}' /var/named/*.db 


Email

For the number of spam in all default accounts.

for i in `ls /var/cpanel/users`; do ls -d /home/$i/mail/cur && ls -l /home/$i/mail/cur | wc -l; done

horde mail update (nothing can be in account of will all get erased)

/usr/local/cpanel/bin/update-horde --force

To determine mailserver type

/scripts/setupmailserver --current

Count mail in folder

ls | wc -l

removing mass spam

rm -Rf /home/(user here}/mail/cur*

And if that command fails, and only if that command fails try this one.
DO NOT IGNORE you MUST be in the directory that the spam is in or this command could ruin this server...

find . -type f | xargs rm -f

spam removal script

for i in $(find . | xargs grep -m 1 -s -i "Mailer-Daemon" | sed -e 's/\.\/[A-Z0-9a-z]\/\([A-Z0-9a-z\-]\{16\}\)\-[HDJ].*/\1/'); do exim -Mrm $i;done

List all email accounts on the server

for domain in `grep DNS /var/cpanel/users/* |grep DNS|cut -d = -f 2`; do for user in `cat /home/*/etc/$domain/passwd|cut -d : -f 1`;do echo $user@$domain ;done;done 2> /dev/null

List all email accounts on the server and place in a text file

for domain in `grep DNS /var/cpanel/users/* |grep DNS|cut -d = -f 2`; do for user in `cat /home/*/etc/$domain/passwd|cut -d : -f 1`;do echo $user@$domain ;done;done 2> /dev/null > EMAILLIST.txt

Fix the symlinks on the email accounts so that they show up in main account veiw.

/scripts/linksubemailtomainacct


Empty files

To create a empty file that takes so much spce for testing uploads.

dd if=/dev/zero of=file1G.tmp bs=1G count=1


Fantastico

add the Fantastico installer plugin

cd /usr/local/cpanel/whostmgr/docroot/cgi
wget -N http://files.betaservant.com/files/free/fantastico_whm_admin.tgz
tar -xzpf fantastico_whm_admin.tgz
rm -rf fantastico_whm_admin.tgz

Flash plugin for centos

yum install flash-plugin.1386


For loops and other loops

ALWAYS RUN THIS FIRST!!!!!

unalias ls

package all cpanel accounts

for user in `ls -A /var/cpanel/users`; do /scripts/pkgacct $user;done

looping a command

while x=0; do killall -9 php5; sleep .1; done

Watching for a cpanel not ran in a screen

while x=0; do ps aux | grep easyapache |grep -v grep; sleep 30; done

Grep

Use these to figure out a usename without logging into WHM.

cat /usr/local/apache/conf/httpd.conf | grep -A1 www.domain.com
grep -A1 www.domain.com /usr/local/apache/conf/httpd.conf


History Removal commands

If the customer would like their history cleared.

echo "" > /var/log/messages && echo "" /var/log/secure
echo "" > /var/log/wtmp && echo "" > /var/log/lastlog && history -r

If for some reason you ever need to cover your own tracks, like creating a usre on the wrong server or such, this will remove your session history

history -r

HTOP

Twicherts method (easier and prefered)

exec 3<&1 && bash <&3 <(curl http://layer3.liquidweb.com/lantern/htop.sh)

Source Install: (for other methods to install please see https://wiki.int.liquidweb.com/articles/Htop)

cd /usr/local/src/   
wget http://www.sfr-fresh.com/linux/misc/htop-0.8.3.tar.gz
tar zxf htop-0.8.3.tar.gz
cd htop-0.8.3
./configure ; make ; make install

HTTPD and APACHE

to distill changes to the httpd.conf

/usr/local/cpanel/bin/apache_conf_distiller --update

apache uptime

/usr/bin/lynx -dump -width 500  http://127.0.0.1/whm-server-status

Index's

Trying to veiw an index

If you can do the following tail command( with you ip of course after you have visited the site or while)

[root@host2.managed-me.net] snap >> tail -f /usr/local/apache/logs/error_log | grep 69.16.222.26
[Tue Dec 21 04:31:33 2010] [error] [client 69.16.222.26] Directory index forbidden by rule: /home/xencomca/public_html/ssm1/snap/
[Tue Dec 21 04:31:33 2010] [error] [client 69.16.222.26] File does not exist: /home/xencomca/public_html/403.shtml

Do the following, (i am using the above as an example.)

vim /home/xencomca/public_html/ssm1/snap/.htaccess

And add this line to the top of the file.

Options +Indexes

Now save and refresh the page.

Blocks the index of /

Add the following to the .htaccess of the folder in question.

Options -Indexes

to disable this just change the - to a +.

IonCube Problems

If you get this error

The ionCube PHP Loader is disabled because of startup problems.

Check the /usr/local/lib/php.ini for duplicate line that look like the following.

; Directory in which the loadable extensions (modules) reside.
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"
zend_extension="/usr/local/IonCube/ioncube_loader_lin_5.2.so"
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"
zend_extension="/usr/local/IonCube/ioncube_loader_lin_5.2.so"

Remove a set of line and restart apache, should fix the problem.

/etc/init.d/httpd restart


IPTABLES

Block temp with IPtables

iptables -I INPUT 1 -s ipaddress -j DROP

Block permanently with APF

/etc/apf/deny_hosts.rules


LIST

list by last modified

ls -lt

list by Proc id

lsof -p PID

Locating log files

Finding a log file that has been modified in the last 24hrs

find /home -name error_log -mtime -1

Mailman

Mailman reports that the list is trying to be pulled from login and do a grep in the mailman directory. in this example i will use our shared servers.

cd /usr/local/cpanel/3rdparty/mailman
grep -R koala.liquidweb.com * > list.txt

Now cat that list - the archives

cat list.txt | grep -v archive

Should give you similar results of whats below, the mailman config that contain the offending url.

archive Binary file lists/members_lendaheart.org/config.pck.last matches
Binary file lists/members_lendaheart.org/config.pck matches

now make a backup of the config.pck and edit it.

cp config.pck config.pck.lwback
sed -i -e 's/koala/hydra/g' config.pck

this will change koala to hydra, now login to mailman and see if the problem is solved. This should fix the problem of mailman going to the wrong server.

mbstring

Check if it is installed with the following

php -i | grep --color mbstring

if that come back with this it is installed but not enabled:

mbstring
mbstring extension makes use of "streamable kanji code filter and converter", which is distributed under the GNU Lesser General Public License version 2.1.
mbstring.detect_order => no value => no value
mbstring.encoding_translation => Off => Off
mbstring.func_overload => 0 => 0
mbstring.http_input => pass => pass
mbstring.http_output => pass => pass
mbstring.internal_encoding => no value => no value
mbstring.language => neutral => neutral
mbstring.strict_detection => Off => Off
mbstring.substitute_character => no value => no value

Go into the php.ini and un-comment these lines.

vim /usr/local/lib/php.ini

and un-comment these lines.

extension=php_mbstring.dll
extension=php_mcrypt.dll

Then

/etc/init.d/httpd stop
/etc/init.d/httpd startssl

ModRewrite

www redirect

Make sure mod_rewrite is on in the httpd.conf

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

MTR <enhanced traceroute>

To install:

yum install mtr

If it fails to find the package you will need to add rpmforge to your repo's

MS SQL on a cpanel box

To install MS SQL Do the following.

Install unixODBC:

cd /usr/src
wget http://www.unixodbc.org/unixODBC-2.3.0.tar.gz
tar -zxf unixODBC-2.3.0.tar.gz
cd unixODBC-2.3.0
./configure -prefix=/usr/local -enable-gui=no
make install

Install FreeTDS:

cd /usr/src/
wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar -zxf freetds-stable.tgz
cd freetds-*
./configure -with-tdsver=8.0 -with-unixODBC=/usr/local
make install
ldconfig

Tell EasyApache we want MSSQL support:

echo '--with-mssql' >> /var/cpanel/easy/apache/rawopts/all_php5

Now, recompile PHP/Apache through EasyApache. It’s OK to use the same options as previous, because MSSQL isn’t an option in EasyApache that can be toggled on and off; we did it manually (and permanently) in the last step.

Verify your work by checking phpinfo() for the mssql section.

MR Radar

Install mr radar

lpyum install mm3k-client-pull

NGINX

ADD VHOST To add a vhost you must go to:

cd /etc/nginx/vhosts/

The copy an already existing domain vhost file over to the name that you need.

cp -Rp Existing.com newdomain.com
vim newdomain.com

Change the document root over to the new users document root, also change all references of the existingdomain to the new domain then save and exit the file. restart nginx

/etc/init.d/nginx restart

Openssl

my guide to openssl

this will unpackage global sign certs that look like this CEDS1008174562.pfx

openssl pkcs12 -in CEDS1008174562.pfx -out cert -nodes

of course replace the "CEDS1008174562.pfx" with your .pfx files name and change "cert" to what ever you want the output file called,
also at this point you will need to enter the password that you setup when you converted the cert.

OwnerShip & Groups

Tell what group number owner is

cat /etc/passwd | grep nobody

Add user to group

useradd -G {group-name} username

Permissions

Find 777 folders

find /home -perm 0777 -type d -print

Find files and folders and change to 755 and 644

find /home/(username)/public_html/ -type d -exec chmod 755 '{}' \;
find /home/(username)/public_html/ -type f -exec chmod 644 '{}' \;


Pixel Post

You can go to pixelpost.org for more details about this program, for the installation guide go here Install guide

Log into the server and go to the folder that the customer wants this installed at.

cd /usr/local/src
wget http://www.pixelpost.org/releases/latest.zip  
unzip pixelpost_v1.7.3.zip 

Make sure you change the user in the next command to the correct name.

chown -R user. ./*

Give customer this link to complete setup.

http://domain.com/installation directory/admin/install.php

Ports

Bindings

netstat -lnc

Python

find python version

python -V

Register_globals

turn off register globals in dso for one cpanel account, just add the following to the cpanel account .htaccess that you want to disable globals for.

php_flag register_globals off 

Reverse DNS

File location where you add it Since my workstations ip is 69.16.222.26 I would find my ptr record in this file, on NS.liquidweb.com.

[root@ns /var/named]# vim 222.16.69.in-addr.arpa.db

Then I locate the line that says 26, (since that is the last octet of my ip) and add the following.

26 IN PTR      vov.wks.liquidweb.com.

change the ttl to 300, change the serial, and then reload the bitch.

rndc reload 222.16.69.in-addr.arpa
rndc reload 222.16.69.in-addr.arpa

You are done, Welcome to the world of being tracked by Liquidweb.

Rdesktop

rdesktop (servername here) -u mshooltz -p (passhere) &

ROBOTS.TXT

To make a file that prevents indexing of certain folders.

touch robots.txt

change the permissions to user.user and the edit the file and add these lines to it.

User-agent: *
Disallow: /

You can specify othe directorys that you wish to be blocked by adding the path, and for this file "/" = public_html.

RPM

Rpm src packages go here

/usr/local/src/

remove old kernal srcs

rpm -qa | grep kernel-source | xargs rpm -e

Rpm remove installed packages

rpm -e --nodeps {package name here}

Rsync

Basic rsync

rsync -avHl /home/(username)/public_html/ /home/(username)/public_html/

rsync from a remote server to a local server

rsync -avHle ssh -p 22222 root@67.225.167.252/usr/share/ssl /usr/share/

SCP

To secure copy do the following.

scp {file} root@(servers ip here):/home/

SED

replace this with THIS

sed -i -e 's/(this)/(THIS)/g' path/filename

S.M.A.R.T stuffs

hard drive statistics (replace X with hard drive number).

smartctl -A /dev/sdbX

Do a long HDD test

smartctl -t long /dev/hdX

SPAM filtering fix

Make spamassassin learn spam, Firstly you will have to have the customer put all of their spam in a folder, I use LWSPAM. After that has been completed you will have to figure out what cpanel users this has to be done for. Then you will ne to swithch to those users at the CLI.

su (cpanel username here)

After logging into the user you will then run the following command on that LWSPAM folder you had the customer add.

/usr/bin/sa-learn --spam /home/(username)/mail/cur/.LWSPAM/*

This has been completed tell the cusromer hola.

SPAMD

SPAMD failing

/scripts/perlinstaller Digest::SHA1
/scripts/perlinstaller --force Mail::SpamAssassin
/etc/rc.d/init.d/exim restart
/scripts/restartsrv spamd

Watch to see if spamd still fails

while x=0; do ps aux | grep spamd | grep -v grep; sleep 15; done

SSH

Add to make ssh not time out.

echo "serveraliveinterval 60" >> /home/mike/.ssh/config && echo "serveralivecountmax 10" >> /home/mike/.ssh/config

Sick of ssh alway asking you to type in yes? to accept that key. So do this to fix it.

sed -i -e 's#\#   StrictHostKeyChecking ask#   StrictHostKeyChecking no#g' /etc/ssh/ssh_config
/etc/init.d/sshd restart

now you wont have to ever type yes again.

Stats

For individual accounts, run:

/scripts/runweblogs

or for all accounts on the server, try

for i in `ls -A /var/cpanel/users`; do /scripts/runweblogs $i;done

System specs

tells the system infos

uname -a

What linux version and release

cat /etc/redhat-release

tells system kernel version

uname -r

Want cpuinfo?

cat /proc/cpuinfo

Tar

Create a tar

tar -cvf file.tar.gz /path/to/file

Extract a .tar.gz

tar -zxvf filename.tar.gz

Extract a .tar

tar -xvf filename.tar

Preview the contents of a package so you can pick what to pull out

tar -tvzf filename.tar.gz

you can also pipe that to search for a certain folder

tar -tvzf filename.tar.gz | grep (folder or filename)

Extract a certain file from a backup or tar file

tar -xvzf filname.tar.gz /home/mike/public_html

use the exact line that the previous command gave you.

Time sync

sync time to liquidwebs time server

rdate -s time.liquidweb.com

Top

sort by memory

shift - m

sort by processor usage

shift - p

Users

This is a one liner to add user, put them in a group, and change their password.

useradd bmurphy && usermod -G wheel bmurphy && passwd bmurphy

VI commands

Add line numbers

:set number

Remove line numbers

:set nonumber

VPS

Get root fight when logged in using LDAP

sudo su -

VPS is locked when some operation (backup, migration, start / stop, etc.) with this VPS is in progress. You can determine which process is holding VPS #101 using the following command on the hardware node:

cat /vz/lock/101.lck

You can kill that process if needed. Make sure that the process is really killed. If there is no process with that PID on the node, just remove the lockfile.

WHM Service Manager

To add a service to the WHM service manager and have tailwatchedd monitor it do the following. Adding the script to /etc/chkserv.d/ will let it be monitored and restarted automatically if needed. Code:

echo "service[(servicenamehere)]=x,x,x,/etc/init.d/(servicenamehere) restart,root,root" > /etc/chkserv.d/(servicenamehere)
echo "(servicenamehere):1" >> /etc/chkserv.d/chkservd.conf
/usr/local/cpanel/bin/tailwatchd restart 

WordPress Solutions & fixes

Changeing a Wordpress sites domain
To change the domain on a wordpress site do the following, edit the wp-config file and change the folling lines to the new url.

define('WP_HOME','http://domain.com');
define('WP_SITEURL','http://domain.com');

Then login to their whm and go into PHPmyadmin and then find the database, and modify the site url to the correct domain. (located under the wp-options table as the siteurl description)

Now for the fun part we get to edit their Database contents, first dump the database.

mysqldump dbname > dbname.sql

Now make a backup of it just incase we foobar it up.

cp dbname.sql dbname.sql.bak

Then we will have to run a sed statement to change the links to the new url.

sed -i 's/old url/newurl/g' dbname.sql

Then you have to re-import the .sql

mysql dbname < dbname.sql

Everything should be fine now to test the site you will not be able to use the http://ip/~user link as this will break their code, please add the domain to your hosts file and veiw the domain from the correct URL to test if needed.

YUM problems

First off always check this location

ls -lah /etc/yum.repos.d

And if it lists anything MORE than the following please mv everything else out of this folder.

root@host [/usr/local/cpanel/logs/easy/apache]# ls -lah /etc/yum.repos.d
total 20K
drwxr-xr-x   2 root     root     4.0K Nov 14 19:08 ./
drwxr-xr-x  63 root     root      12K Nov 14 20:02 ../
-rw-r--r--   1 systuser systuser  660 Mar  2  2005 yum.system.repo

if you see anything more than this please move all other repos out of this folder and try again. If you problem still occurs please proceed on. Next check you yum.conf to make sure it is correct should look like the following.

[root@Shooltz.net [~]$ cat /etc/yum.conf
[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=centos-release
tolerant=1
exactarch=1
retries=20
obsoletes=1
gpgcheck=1
exclude=apache* bind-chroot centos-yumconf courier* dovecot* exim* httpd* mod_ssl* mysql* nsd* perl* php* proftpd* pure-ftpd* ruby* spamassassin* squirrelmail*

If you yum.conf does not look lik ethat please back it up and replace it with what follows.

mv /etc/yum.conf /etc/yum.conf.bak
echo -e "[main]\ncachedir=/var/cache/yum\ndebuglevel=2\nlogfile=/var/log/yum.log\npkgpolicy=newest\ndistroverpkg=centos-release\ntolerant=1\nexactarch=1\nretries=20\nobsoletes=1\ngpgcheck=1\nexclude=apache* bind-chroot centos-yumconf courier* dovecot* exim* httpd* mod_ssl* mysql* nsd* perl* php* proftpd* pure-ftpd* ruby* spamassassin* squirrelmail*" > /etc/yum.conf

After this has been completed, and if it is still broken we will reset the rpm databases.

rm -f /var/lib/rpm/__db*
rpm -vv --rebuilddb