Navigation

Copying large amout of files/dirs over SSH using RSYNC

To copy files from remote server to local:

rsync -vrplogDtH -e ssh user@remotehost:/remote/location /this/dir/

To copy files from local to remote server:

rsync -vrplogDtH /this/dir/ -e ssh user@remotehost:/remote/location

-v, --verbose increase verbosity
-r, --recursive recurse into directories
-p, --perms preserve permissions
-l, --links copy symlinks as symlinks
-o, --owner preserve owner (super-user only)

Find And Replace Text in Multiple File in Linux Console

find . -name '*.txt' | xargs perl -pi -e 's/oldtext/newtext/g'

examples:

find . -name '*.txt' | xargs perl -pi -e 's/From: root/From: csf\@donie\-centos5\.slowrock\.com/g'
find . -name '*.txt' | xargs perl -pi -e 's/To: root/To: donie\@slowrock\.com/g'

How to fix ssh timeout problems

If you use ssh a lot, you may have noticed that your ssh session times out and you’re logged out every once in a while.

For example while you were using SecureCRT, you got:

The semaphore timeout period has expired

The solution is to send a protocol NO-OP every few seconds to keep the connection alive.
Usually SSH clients have this feature disabled and you can enable it.
SecureCRT has this feature on:
Right click on host -> Properties
or
Right click on the host tab -> Session Options

Secure /tmp and /dev/shm partition

How To Secure /tmp and /dev/shm partition

Keep you server clean of rookits is a good idea to get a good security level. A sysadministrator can create a seperate partition for /tmp and mount it with noexec and nosuid parameters. And to do it is not necessary to reboot or repartition your drive.

1. First you should secure /tmp:

Make a 1GB file for /tmp parition and an ext3 filesystem for tmp:
[root@antg ~]# dd if=/dev/zero of=/usr/tmpDSK bs=1024 count=1024000
will take a while, just wait until finished.

Increase the size of tmpDSK (/tmp) in cPanel

You may have noticed that cPanel’s default partition size for /tmp is
512 MB, which in some cases can be way too small. And sometime you probably get this report email:

Drive Critical: /usr/tmpDSK (/tmp) is 100% full

Although cPanel automatically deletes the unused files, the /tmp would be getting full very quickly on a busy server.

The /tmp partition on cPanel servers, assuming it was the one cPanel created and not one you did yourself, is a file-based partition that can easily be resized.