Apr 26

tux_guardThe Spamhaus Project is an international organization who track email spammers and spam-related activity.
The Spamhaus Project is also compiling very widely used anti-spam lists. One of these lists contains IP blocks from “verified spam sources”. These kind of sources are per default evil and I am not interested to communicate with theme so I wrote a little bash script which blocks all of these bad guys.

#!/bin/bash
# Generate automatic firewall rules to block bad IPs listed on spamhaus.org
FILE=/tmp/drop.lasso
wget -O $FILE http://www.spamhaus.org/drop/drop.lasso
iptables -F ; flush iptables, comment line if you use other rules 
for ipblock in `egrep -v '^;' $FILE | awk '{print $1}'`
do
 iptables -I INPUT -s $ipblock -j DROP 
done

written by d45id \\ tags: , , , ,

Mrz 28

TerminalAus gegebenen Anlass möchte ich aufzeigen wie sich Rechenoperationen auf UNIX/Linux CLI durchführen lassen. Diese Operationen lassen sich natürlich auch in Skripten verwenden.
Im folgenden möchte ich vier Möglichkeiten zur Berechnung vorstellen, die sich auf so ziemlich jedem aktuellen UNIX/Linux anwenden lassen. Continue reading »

written by d45id \\ tags: , , , , , , , ,

Jan 02

An easier way to update the firmware of your Raspberry Pi it to use rpi-update written by Hexxeh.

To install the tool, run the following command:

sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && 
sudo chmod +x /usr/bin/rpi-update

If you get errors relating to certificates, then the problem is likely due to one of two things. Either the time is set incorrectly on your Raspberry Pi, which you can fix by simply setting the time using NTP. The other possible issue is that you might not have the ca-certificates package installed, and so GitHub’s SSL certificate isn’t trusted. If you’re on Debian, you can resolve this by typing:

sudo apt-get install ca-certificates

To then update your firmware, simply run the following command:

sudo rpi-update

To upgrade/downgrade to a specific firmware revision, specify it’s Git hash as follows:

rpi-update <git hash> 

If you’d like to set a different GPU/ARM memory split, then define gpu_mem in /boot/config.txt.

written by d45id \\ tags: , , ,

Okt 01

Die Paketsammlung smartmontools bringt die beiden Programme smartctl und smartd mit, mit denen sich recht gut Festplatten analysieren und überwachen lassen. Hierzu wird auf das Self-Monitoring, Analysis and Reporting Technology System (S.M.A.R.T.) der Festplatte zugegriffen, welches in so gut wie allen aktuellen ATA und SCSI Platten verbaut ist.

smartmontools ist bei den meisten Linuxdistributionen in der Paketverwaltung enthalten und lässt sich unter Debian/Ubuntu über den Befehl

aptitude install smartmontools

installieren.

Des weiteren gibt es hier aber auch precompiled Pakete für eine menge weiterer Betriebssysteme .  Der aktuelle source tarball findet sich hier, sowie auch ein Windowsinstaller.

Kommen wir nun zur Verwendung des Programms. Continue reading »

written by d45id \\ tags: , , , ,

Jul 20

Hard disks are going to be cheaper and cheaper and we are going to need even more space. So why not build your own cheap storage? Thanks to linux 3.1 and 3.2 and its btrfs support is now very easy to setup a fully redundant, scalable, storage made of many hard drives. Set up a btrfs storage is really easy. I’m using btrfs because it performs really good in a lot of scenarios like oracle demonstrated. Do not rely on old benchmarks, Btrfs has been out from a while now, and early versions are not comparable with old ones. One of the best features of this filesystem is scalability: you can start with one disk and then attach new disks as soon you need them. You just attach and add to the btrfs volume the new hard disk. That’s it.

To create a fully redundant hard disk just do:

root@sid:~$ install btrfs-tools

root@sid:~$ mkfs.btrfs -d raid1 /dev/sdb /dev/sdc

You can see the newly created filesystem. You will see also the UUID. That’s an important information since we can setup automount at startup thanks to that info.

Suppose that you want to attach the newly created storage to /storage and you want it to be mounted by default as soon as the computer starts. You just do add this line to /etc/fstab:

root@sid:~$ sudo btrfs filesystem show

Label: none uuid: cace4a04-38e8-42-8581-82bfada35ea7
Total devices 2 FS bytes used 28.00KB
devid 1 size 1.0B used 212.75MB path /dev/sdb
devid 2 size 1.0GB used 212.75MB path /dev/sdc

Btrfs Btrfs v0.19

UUID=cace4a04-38e8-42-8581-82bfada35ea7 /storage btrfs defaults 0 0

written by d45id \\ tags: , , ,

Nov 29

Ich habe neulich auf Cowboy´s Linux-Blog ein Tutorial über “Verschlüsselte Container” unter Linux gefunden. Da es mir sehr gut gefallen hat gibt es nun hier ein Backup davon:

Ziel:

Ein verschlüsselter Container, den man bei Bedarf in das Dateisystem einbindet. Dies soll ohne Neukompilieren des Kernels funktionieren und keine besonderen Pakete benötigen – sowie in meinem Fall auch unter Debian Testing lauffähig sein.

Pakete:

Wir installieren cryptsetup und loop-aes-utils.

1. Erstellen der Containerdatei

An einem beliebigen Ort legen wir die Datei an, die unsere Daten speichern soll – hier 10 GB groß (mit Zufallsdaten gefüllt):

dd if=/dev/urandom of=/home/user/daten.safe bs=1M count=10240

2. Loop-Device

Als root legen wir ein Device an, das einfach auf diese Datei verweist:

losetup /dev/loop0 /home/user/daten.safe

3. Verschlüsselung einrichten

Wir richten nun die Verschlüsselung (Standard: AES mit 256 Bit) auf diesem Device ein – dabei muss das Kennwort angegeben werden:

cryptsetup -y create datensafe /dev/loop0

4. Formatierung

Der Container ist nun im System unverschlüsselt unter /dev/mapper/datensafe vorhanden. Nun richten wir das Dateisystem ein (hier ext4):

mkfs.ext4 /dev/mapper/datensafe

5. Mount

Nach der Formatierung können wir das Device unter einem beliebigen Verzeichnis einhängen (das existieren muss):

mount -t ext4 /dev/mapper/datensafe /mnt/datensafe

Nun kann man auf /mnt/datensafe ganz normal arbeiten, also speziell auch Zugriffsberechtigungen (restriktiv) setzen.

6. Aushängen

umount funktioniert ganz normal, danach noch den Container schließen und das Loopdevice freigeben:

umount /mnt/datensafe/
cryptsetup remove datensafe
losetup -d /dev/loop0

Tipp: Automatisierung mit sudo

Der mount/umount-Prozess inklusive Öffnen/Schließen des Loopdevices und des Containers kann man in ein Skript packen (und auf einem Ubuntu-System dem User mit sudo die Rechte dafür geben).

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/sh
# datensafe_mount.sh

LOOPDEV=/dev/loop0
SAFE=/home/user/datensafe
CRYPTNAME=datensafe
MNT=/mnt/datensafe
FS=ext4

/sbin/losetup $LOOPDEV $SAFE
/sbin/cryptsetup create $CRYPTNAME $LOOPDEV
/bin/mount -t $FS /dev/mapper/$CRYPTNAME $MNT

und

1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
# datensafe_umount.sh

LOOPDEV=/dev/loop0
SAFE=/home/user/datensafe
CRYPTNAME=datensafe
MNT=/mnt/datensafe

/bin/umount $MNT
/sbin/cryptsetup remove $CRYPTNAME
/sbin/losetup -d $LOOPDEV

written by d45id \\ tags: , , , , ,

Aug 18

Getting in

start a new screen session with session name screen -S <name>
list running sessions/screens screen -ls
attach to a running session screen -r
… to session with name screen -r <name>
the “ultimate attach” screen -dRR (Attaches to a screen session. If the session is attached elsewhere, detaches that other display. If no session exists, creates one. If multiple sessions exist, uses the first one.)

Escape key

All screen commands are prefixed by an escape key, by default C-a (that’s Control-a, sometimes written ^a). To send a literal C-a to the programs in screen, use C-a a.

Getting out

detach C-a d
detach and logout (quick exit) C-a D D
exit screen “C-a : quit” or exit all of the programs in screen.
force-exit screen C-a C-\ (not recommended)

Help

See help C-a ? (lists keybindings)

The man page is the complete reference, but it’s very long.

Window Management

create new window C-a c
change to last-visited active window C-a C-a (commonly used to flip-flop between two windows)
change to window by number C-a <number> (only for windows 0 to 9)
change to window by number or name C-a ' <number or title>
change to next window in list C-a n or C-a <space>
change to previous window in list C-a p or C-a <backspace>
see window list C-a " (allows you to select a window to change to)
show window bar C-a w (if you don’t have window bar)
close current window Close all applications in the current window (including shell)
kill current window C-a k (not recommended)
kill all windows C-a \ (not recommended)
rename current window C-a A

Split screen

split display horizontally C-a S
split display vertically C-a |
jump to next display region C-a tab
remove current region C-a X
remove all regions but the current one C-a Q

Scripting

send a command to a named session screen -S <name> -X <command>
create a new window and run ping example.com screen -S <name> -X screen ping example.com
stuff characters into the input buffer
using bash to expand a newline character
(from here)
screen -S <name> [-p <page>] -X stuff $'quit\r'
a full example
# run bash within screen
screen -AmdS bash_shell bash
# run top within that bash session
screen -S bash_shell -p 0 -X stuff $'top\r'

# ... some time later

# stuff 'q' to tell top to quit
screen -S bash_shell -X stuff 'q'
# stuff 'exit\n' to exit bash session
screen -S bash_shell -X stuff $'exit\r'

Misc

redraw window C-a C-l
enter copy mode C-a [ or C-a <esc> (also used for viewing scrollback buffer)
paste C-a ]
monitor window for activity C-a M
monitor window for silence C-a _
enter digraph (for producing non-ASCII characters) C-a C-v
lock (password protect) display C-a x
enter screen command C-a :

written by d45id \\ tags: ,

Mai 20

Ich möchte einen Kalender (2-way) zwischen der Groupware meiner Wahl (SOGO - CalDAV Backend) und einem vorgegebenen Oracle Calendar (SyncML Backend) automatisch synchronisieren.

Möglich ist dies mit der Software SyncEvolution. Der CalDAV Support ist erst kürzlich mit der Version 1.2 hinzugekommen. Bei meinem Ubuntu 10.4 ist allerdings nur die Version 1.0 dabei. Zum Glück gibt es allerdings ein Repository mit fertigen Paketen. Als root einfach folgendes ausführen: Continue reading »

written by d45id \\ tags: , ,