Table of Contents
Mixed up staff
Quite anything from anywhere or all the uncategorized stuff.
su
Passwordless su if the useres are in the same group. Just edit the /etc/pam.d/su. It should lool like this:
#%PAM-1.0 auth sufficient pam_rootok.so # Uncomment the following line to implicitly trust users in the "wheel" group. #auth sufficient pam_wheel.so trust use_uid # Uncomment the following line to require a user to be in the "wheel" group. #auth required pam_wheel.so use_uid auth [success=ignore default=1] pam_succeed_if.so user ingroup MYGROUP auth sufficient pam_succeed_if.so use_uid user ingroup MYGROUP auth substack system-auth auth include postlogin account sufficient pam_succeed_if.so uid = 0 use_uid quiet account include system-auth password include system-auth session include system-auth session include postlogin session optional pam_xauth.so
Firewalld
Block a network with all ports and block a network with only a port:
# firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='61.177.0.0/16' reject" # # firewall-cmd --add-rich-rule="rule family='ipv4' source address='87.139.0.0/16' port port="22" protocol="tcp" drop" --permanent
Fail2ban
Three usefull commands, when useing fail2ban and firewalld:
# firewall-cmd --direct --get-all-rules # fail2ban-client status # ipset list fail2ban-sshd
Cleaning BTRFS Device Errors
server:~ # btrfs device stats -z / [/dev/mapper/system-root].write_io_errs 2 [/dev/mapper/system-root].read_io_errs 0 [/dev/mapper/system-root].flush_io_errs 0 [/dev/mapper/system-root].corruption_errs 0 [/dev/mapper/system-root].generation_errs 0 server:~ # btrfs device stats / [/dev/mapper/system-root].write_io_errs 0 [/dev/mapper/system-root].read_io_errs 0 [/dev/mapper/system-root].flush_io_errs 0 [/dev/mapper/system-root].corruption_errs 0 [/dev/mapper/system-root].generation_errs 0 server:~ #
Functions and aliases go in .bashrc Paths and so on .bash_profile
Wiki for setting up a mailserver: http://andrewpuschak.com/dokuwiki/doku.php?id=centos_6_email_server
Fedy
Das Tool um zusätzliche Programme auf Fedora zu installieren. https://www.folkswithhats.org/
Simple P2V
dd if=/dev/sda | ssh 10.11.12.13 "dd of=/mnt/server.img status=progress" # Convert the raw image to a qcow2 image. qemu-img convert -f raw -O qcow2 /mnt/server.img /mnt/server.qcow2
Install RHEL/CentOS 7 via VNC
Insert the DVD/CD or what ever and boot from this media. Befor pressing enter to install, press TAB and type in some extra settings at the end of the line to reach your server via VNC. Here is the link to Anaconda where you can find all possible options.
inst.vnc ip=10.11.12.13 netmask=255.255.255.0 gateway=10.11.12.1 resolution=1000x800
If you do not have direct access to the server and you must use a jumphost, following command will help:
ssh -L11000:10.11.12.13:5901 jumphost
rpm -qa --queryformat '%{NAME}\n'
dd if=/mint/iso/image of=/dev/sdb1 oflag=direct
mailserver: http://andrewpuschak.com/dokuwiki/doku.php?id=centos_6_email_server
Alte multipaths löschen:
echo 1 > /sys/class/scsi_device/h:c:t:l/device/delete
ODER die ätere Version
echo "scsi remove-single-device 0 0 0 0" > /proc/scsi/scsi
RH-Kännele hinzufügen:
rhn-channel --add --channel="rhel-x86_64-server-optional-6" -u rhn-username -p rhn-password
Rechnen in der bash: https://www.shell-tips.com/2010/06/14/performing-math-calculation-in-bash/
yum timeout erhöhen:
sed -i 's/self.timeout = 60.0/self.timeout = 300.0/' /usr/lib/yum-plugins/rhnplugin.py
Hashes beim grep ausblenden:
grep '^[^#]' main.cf
Leere Zeilen ausblenden:
sed '/^$/d' inputfile
REPOs von rhel6 für rhel5 verwenden unterschidliche Signaturen. Darum muss beim repo-anlegen ein anderer algorithmus verwendet werden.
createrepo -v -s sha1 /var/www/html/repo/centos/5.3/updates
find command
Files nur auf der derzeitigen Disk finden (-xdev)
find . -type f -xdev -size +10000000c -exec ls -lsa {} \;
find . -type f -exec ls -lad {} \; | sort -n -k 5,5
XML, LOG oder Dateien finden in denen core vorkommt.
find . -name '*.xml*' -size +1000000c -exec ls -lsa {} \;
find . -name '*.log*' -size +1000000c -exec ls -lsa {} \;
find . -name '*core*' -size +1000000c -exec ls -lsa {} \;
Files von einem User suchen
find /home -user tom find /home -user tom -type d find /home -user tom -type f -name "*.c" find /sales -group vip
Files suchen die älter als 30 Tage oder 1 Tag sind
find . -mtime +30 -exec ls -l {} \;
find . -mtime +1 -exec ls -l {} \;
Files die älter als 30 Tage sind löschen und einen gewissen string enthalten
find /pfad -mtime +30 -exec rm {} \;
find . -name '*xml*' -mtime +0 -exec rm {} \;
FIND . -NAME '*tr*' -MTIME +30 -EXEC RM {} \;
find . -name '*tr*' -mtime +0 -exec rm {} \;
Big Files in / finden
find / -xdev -size +100000 -exec ls -rtl {} \; | grep -v "^cr" | grep -v "^br"
gconftool-2 -R /desktop/gnome/session/required_components
- drwxrwxrwt - Sticky Bits - chmod 1777
- drwsrwxrwx - SUID set - chmod 4777
- drwxrwsrwx - SGID set - chmod 2777
Cronjob Syntax
01 * * * * root echo "This command is run at one min past every hour" 17 8 * * * root echo "This command is run daily at 8:17 am" 17 20 * * * root echo "This command is run daily at 8:17 pm" 00 4 * * 0 root echo "This command is run at 4 am every Sunday" * 4 * * Sun root echo "So is this" 42 4 1 * * root echo "This command is run 4:42 am every 1st of the month" 01 * 19 07 * root echo "This command is run hourly on the 19th of July"
for-Schleife:
for i in $(cat /etc/passwd|grep ":D;"|cut -d : -f 1)
> do
> echo $i
> echo ""
> done
ODER:
for i in $(cat copy.list); do echo $i; scp exim_476* $i:/root/.; echo ""; done
for I in {1..10}; do echo $I; done
for I in 1 2 3 4 5 6 7 8 9 10; do echo $I; done
for I in $(seq 1 10); do echo $I; done
for ((I=1; I <= 10 ; I++)); do echo $I; done
how to split und compress files and get then together again.
tar -cvj /home/username/large-files.txt | split -b 650m -d large-files.tar.bz. cat large-files.tar.bz.* > large-files.tar.bz tar -xzvj large-file.tar.bz
GPS:
gpsd -F /dev/ttyACM0
boot image auf usbstick schreiben
livecd-iso-to-disk the_image.iso /dev/sdX1
Die Verbindungen vom NetworkManager löschen: alle Zahlenordner im /home/ulrich/.gconf/system/networking/connections löschen und den Network Manager neustarten oder vielleicht sogar den ganzen laptop.
mit tar entpacken und packen
tar xvpzf datei.tar tar cvfz ziel quelle tar cvfz test.tar.gz irgendeineDatei.txt
keyring scheiße zurücksetzten:
rm -rf /home/ulrich/.gnome2/keyrings #oder so ähnlich
IPTables
listet die aktuellen Regeln
iptables --list
wirft die Pakete von der Adresse weg
iptables -A INPUT -s IPADRESSE -j DROP
wie oben nur an einer anderen Stelle in der Liste
iptables -I INPUT -s IPADRESSE -j DROP
entfernt die Regel für die IPAdresse wieder
iptables -D INPUT -s IPADRESSE -j DROP
Umgebungsvariable setzten:
export CANDLEHOME=/home/candle
die Variable candlehome hat jetzt den Pfad nach /home/candle
neue disks scannen:
echo "- - -" > /sys/class/scsi_host/host2/scan
softlink
ln -s quelle ziel
minütlich einen crontab job ausführen
*/1 * * * * /tmp/test.sh
Am ESX die LUN-ID finden: Im Verzeichnis /vmfs/devices/disks ein ls -al | grep vmhbaX:X:X absetzten
rsync -avP /daten/isos/freebsd.iso 10.11.22.33:/diverses/
Nagiosadmin Passwort für das Webinterace ändern. In das Verzeiochnis /usr/local/nagios/etc wechseln (oder wo auch immer das File htpasswd.users liegt) und
htpasswd htpasswd.users nagiosadmin
absetzten.
Putty-Sessions sichern: regedit /e d:\puttynew.reg HKEYCURRENTUSER\Software\SimonTatham\PuTTY
sdtool -e … schaltet den cluster(Shutdown Daemon) ab Shutdown Facility sdtool -b … schaltet den cluster wieder ein
partprobe … liest die Partionstabelle neu ein.
gfs filesystem check: gfsfsck -v -y /dev/vgname/lvdatalarge
neue platte:
- neues phsical volume (pv) anlegen: pvcreate /dev/irgentwas
- neue volume group (vg) anlegen: vgcreate -vvv -s 16m einevg /dev/irgendwas - neues logical vloume (lv) anlegen: lvcreate -L 800M -n lvname /dev/einevg - bei einem Spiegel: lvcreate -l 15999 -m 1 -n lvdata3 –corelog /dev/vgdbmirror /dev/mpath/mpath34 /dev/mpath/mpath35
aus der platte ein gfs machen: auf allen nodes des gfs muss das lv angelgt sein gfsmkfs -t gfs-cluster:clustername -p lockdlm -j 5(anzahl der nodes im cluster) /dev/eine-vg/lv-name z.B.: gfsmkfs -t gfs-cluster:data10 -p lockdlm -j 6 /dev/vgdball3/lvdata10
platten checken:
cd /usr/local/sbin/ ql-dynamic-tgt-lun-disc.sh
danach ein pvscan…man sollte die neuen platte dann sehen
Listener stoppen
/etc/init.d/Listener stop
multipath -l –
> zeigt die multipath's an
vgs …zeigt informationen über volume group lvs …teigt infos über logical volume
schleife:
while true; do netstat -an | grep :161; sleep 3; done
logrotate
Für das Logfile das das rotiert werden soll muss im Verzeichniss /etc/logrotate.d/ ein config-File angelegt werden. in diesem Fall heißt es tcp.
# vi /etc/logrotate.d/tcp
/var/log/tcp { #dort liegt das log-File
daily #wird täglich rotiert kan auch weekly oder monthly sein
rotate 5 # es werden 5 Ableger aufbewahrt tcp.1, tcp.2, usw.
compress #Das log-File wird komprimiert
delaycompress # es wird erst ab dem 2. Ableger komprimiert
create 644 root adm # die Rechte für die Ableger festlegen.
}
so wird in das logfile geschrieben legt man am besten einen ableger an tcp.1 und führt folgenden Befehl aus.
# logrotate -dfv /etc/logrotate.d/tcp
dadurch wird ein ganzer Rotationsvorgang durchgespielt und man sieht ob Fehler auftreten.
Busy Filesystem unmounten
fuser -f /Filesystem #oder fuser -m /Filesystem #oder lsof /filesystem #dann den Prosess killen #oder umount -l /filesystem # ist ein lazy unmount
ONLINE Erweiterung einer SAN-LUN
- Increase size of LUN in SAN
- Check with “multipath -ll” which devices belong to said LUN
- For each device above, do “echo 1 > /sys/block/sdX/device/rescan”
- Go to multipath command line with “multipathd -k”
- For each device, do “del path sdX”, “add path sdX” while hoping that the multipathing functionality works as advertised and fails over properly.(nicht unbedingt notwendig)
- “resize map multipath-map-name”
- Exit multipath command line (Ctrl-D), check with “multipath -ll” that new size is seen.
- pvresize, lvextend, resize2fs
- Profit!
Compare the rpms of two servers
#!/bin/sh
# Author: https://gist.github.com/jonjensen/6726674
test -n "$TMPDIR" || TMPDIR=/tmp
tmpfilebase="$TMPDIR/rpmdb-compare.$$"
if test $# -ne 2
then
echo "Usage: $0 [user@]server1 [user@]server2" >&2
echo "Special name localhost means this server, without ssh" >&2
exit 1
fi
for i in "$@"
do
tmpfile="$tmpfilebase.$i"
if test $i = localhost
then
rpm -qa --qf '%{NAME}.%{ARCH}\n' | sort > $tmpfile
else
ssh $i "rpm -qa --qf '%{NAME}.%{ARCH}\n'" | sort > $tmpfile
fi
done
echo "RPMs in $1 only:"
comm -23 "$tmpfilebase.$1" "$tmpfilebase.$2"
echo
echo "RPMs in $2 only:"
comm -13 "$tmpfilebase.$1" "$tmpfilebase.$2"
rm -f "$tmpfilebase.$1" "$tmpfilebase.$2
RPM
Which file belongs to which RPM?
# rpm -qf /bin/yum
Which files are in a specific RPM?
# rpm -ql yum-3.4.3-132.el7.noarch
Which files are in a RPM-File?
# rpm -qp yum-3.4.3-132.el7.noarch.rpm
QR codes
To share your WIFI credentials, you have some options.
Print the QR code in your terminal
qrencode -t ansiutf8 "WIFI:T:WPA;S:myWIFIname;P:mySecretPW;;"
Save the QR code as PNG
echo "WIFI:T:WPA;S:myWIFIname;P:mySecretPW;;" > wlan.txt qrencode -r wlan.txt -o wlan.png
