Find files containing a given string


If you want to find files containing a specificly given string and you want to remove those files, you should simply use this oneliner (Only searching for files in the current directory):

Jeder Kunde erhält 10% Rabatt auf das gesamte Sortiment. - Gutschein-Code: soforteinloesen10
find . | xargs grep -l "STRING_TO_SEARCH_FOR" | awk '{print "rm -f "$1}' > remove.sh && chmod u+x remove.sh

After that, you only have to execute the script and the files containing the searched string will be removed. Attention: You should take a look at remove.sh before executing it, just avoiding that files will be removed accidentally.

./remove.sh

The post Find files containing a given string appeared first on Techwrk.

Zum Blog blog-busters

Listing files and folders well-arranged


Many people know the problem: You have to find something, but you’re having no idea where to find it. Of course, you can use “locate” or “find” and search for the file. But what’s the best possibility for getting an overview about directories, files, binaries or subdirectories?
YES – it’s using the “tree” command. But what are you going to do, if you’re working on a managed server without any root-access and without the possibility to install tree? 
Here’s a short solution for this problem:
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^/]*//--/g' -e 's/^/   /' -e 's/-/|/'

The post Listing files and folders well-arranged appeared first on Techwrk.

Zum Blog blog-busters

Mount a temporary ram partition


With this simple snippet you can mount a temporary ram partition: ( Be careful – please check if you’re having enough ramspace free )

mount -t tmpfs tmpfs /mnt -o size=128m

It’s also possible to write a similar command into /etc/fstab, so that the ram partition will be automatically mounted after a reboot.

The post Mount a temporary ram partition appeared first on Techwrk.

Zum Blog blog-busters

rkhunter


I want to introduce rkhunter – a very useful tool for protecting your server (Debian/Ubuntu).

apt-get install rkhunter

 

After that,  you should open the configfile with your preferred editor:

vi /etc/rkhunter.conf

 

Please change the emailadress to your emailadress:

MAIL-ON-WARNING="user@domain.tld"

Now you can do the first run:

rkhunter --check

 

For more informations about rkhunter please see:

rkhunter readme

The post rkhunter appeared first on Techwrk.

Zum Blog blog-busters

How to secure a Debian Server

I just want to show you some tools/methods for securing your Debian/Ubuntu-server.

Secure your SSH-login (please open /etc/ssh/sshd_config):

- forbid root-login

PermitRootLogin no

- only allow SSH-login with SSH-key (no password login)

PasswordAuthentication no

- change your SSH-port (for example Port 2020 instead of 22)

Port 2020

- if you have more than one IP-Adress which is accessible from everywhere, you should make your SSH-Daemon listen to only one IP-Adress

ListenAddress 1.2.3.4

(replace 1.2.3.4 with the IP-Adress you want your SSH-Daemon to listen to)

Install Updates regularly:

apt-get update && apt-get upgrade

Use fail2ban for prohibiting bruteforce-attacks:

- Simply install that tool via aptitude

Find rootkits with rkhunter: (rkhunter)

- You can install rkhunter via aptitude

If you did all these changes applying the SSH-settings and you installed fail2ban and rhunter you can say that your server is quite secure. Of course, this is no guarantee that your server won’t be hacked, but it makes it much harder.