~ overflow ~

Tag: ssh

Server overload warning

by z3n on Dec.27, 2011, under Linux Happyness, Tips & Hints

Problem:

So i have this shitty server that keeps overloading, although i have all sort of monitors around, many screens, etc I really can’t keep looking at the graphs all day long, but yet i’m almost of the time on the computer.

So why not have a sound trigger when server load go over 10?

Solution:

This php script solves it:

// (c) z3n - R1V1@111227 - www.overflow.biz - rodrigo.orph@gmail.com

while (true) {
	$output = explode(" ", trim(substr(strstr(exec("uptime"), "load average:"), 13)));
        if (substr($output[0], 0, -1) > 10)
		@ passthru("echo -e -n \\\\a");

	echo "\r[" . date("Y-m-d H:i:s") . "] " . implode(" ", $output);
	sleep(5);
}
Leave a Comment :, , , , more...

ssh timeout fix

by z3n on Dec.25, 2009, under Linux Happyness

Problem:

When using regular linux ssh it keeps timeouting or simply freezes when no inputs/outputs happen.

Solution:

Usually ssh has a TCP keep alive switch which you can enable to avoid this, although depending on your router and other network odds this might not help, also you may need to send keep alives in a shorter time than what’s the default of ssh. So, in order to have this working you need to edit /etc/ssh/ssh_config adding this to Host *, assuming you want to have this settings globally for every host.

ServerAliveInterval 60
ServerAliveCountMax 99999999999999

Why so many 9’s? There’s no way to do a endless keep alive, if you put 0 it will just drop the connection after the first keep alive, -1 is invalid, so we go high…….

Leave a Comment :, , , more...

Search in files and count lines

by z3n on Oct.27, 2009, under Linux Happyness

Problem:

I wanted to know how many occurences of a string appears on a log file, by ssh.

Solution:

cat file.ext | grep search_string | wc -l

cat will print the whole file contents, grep will search for the string, wc -l will count the lines.

Leave a Comment :, , , , , , , more...

Search in files and replace by bash

by z3n on Oct.26, 2009, under Coding, Linux Happyness, Tips & Hints

Problem:

How to change a string on several files by bash without opening one by one.

Solution:

for i in $(find . -type f); do sed ’s/find/replace/g’ $i > $i-tmp; mv $i $i-backup; mv $i-tmp $i; done

Yes, it’s just a copy paste from the source, i don’t have time to explain each command.

Source:

CodeSnippets

Leave a Comment :, , , , more...

Tar over SSH (Pipe Tar)

by z3n on May.05, 2009, under Linux Happyness, Tips & Hints

Problem:

Copy over 10 million files to a different server perserving the permissions, ownership, paths etc.


Solution:

tar -zcf – /path/to/local/dir | ssh remoteuser@remotehost.tld tar -C /path/to/remote/dir -zxf -

this will send a compressed (z parameter) stream to stdout (-) wich will be sent by ssh and uncompressed on the remote server. If you are on a local network you can supress the z parameter in order to keep it faster.

Many people would say that rsync is a better solution, however, rsync don’t work well with many files, specially million files. rsync tends to do a checksum of each file and time/date comparsions which slowdown the process and create lots of disk I/Os, in my case, it was impossible to rsync, the remote server loads were so high that it eventually got stuck and crashed. Tar wasn’t only faster but more effective, making the server able to serve pages while doing it.

Tar will also preserve the ownership and permissions of the files, just what you need to have an exact copy.

Sources:

Tar @ Wikipedia

Hosting Geek Article

Leave a Comment :, , , more...

How to change SSHD port

by z3n on Mar.30, 2009, under Linux Happyness

Problem:

how to change sshd port in order to avoid script kiddies attacks and lower your cpu usage (brute force password attacks)

Solution:

vi /etc/ssh/sshd_config

change Port XX value

service sshd restart

Now you should test ssh with the new port, i don’t need to say that you shouldn’t disconnect the first session in case something goes wrong.

If the ssh don’t work for you on the new port you probably got selinux rule for the ssh enabled, to check try this:

semanage port -l | grep ssh

if you have the selinux rule enabled for ssh, this command will return this:

ssh_port_t                     tcp      22

now we should add a new rule (since it’s impossible to remove the default one) for the ssh, allow it to listen on a different port of your choice:

semanage port -a -t ssh_port_t -p tcp ####

where #### is the port you configurated for sshd (doh!)

then now all you have to do is restart sshd and done!

Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!