Various Linux notes

posted in Linux Administration
in section Various
published at 2014-12-06
created at 2014-12-06
written by Ivan Stana

Mostly copied from various places and authors., documentation, ...

Compressing with 7zip

-mtc add create and access times to the archive. But remember, 7zip don't store permissions, but still it is very useful for archiving stuff.

$ 7z a -t7z -m0=LZMA2 -mtc=on myarchive.7z mydirectory/

Making bootable things

It is forever problem to make disc bootable and adapt to media size simultaneously. It is because each time MBR must be adapted, which is sort of black magic. At least less documented.

One of the useful utilities is ms-sys. (I've probably copied following from somewhere)

Needed (for Windows):

  • Modified SETUPLDR.BIN
  • Special stuff in the bootsector of the partition (use ms-sys).
  • Modified copy of txtsetup.sif copied to the root level
  • NTDETECT.COM copied to root level

In which packages is HW information stored

There are stored mappings from USB uids, manufacturers to names and such things.

  • hwdata
  • discover-data
  • hwinfo
  • libhd16

Monitoring utilities

Run linux commands via SSH from file (or series)

Still this solution is sometimes pain in the ass.

ssh '/bin/sh -s' < file_with_commands

Bash hotkeys

Bash provides many hot keys to ease use. Like:

  • ctrl-l -- clear screen
  • ctrl-r -- does a search in the previously given commands so that you don't have to repeat long command.
  • ctrl-u -- clears the typing before the hotkey.
  • ctrl-a -- takes you to the begining of the command you are currently typing.
  • ctrl-e -- takes you to the end of the command you are currently typing in.
  • esc-b -- takes you back by one word while typing a command.
  • ctrl-c -- kills the current command or process.
  • ctrl-d -- kills the shell.
  • ctrl-h -- deletes one letter at a time from the command you are typing in.
  • ctrl-z -- puts the currently running process in background, the process can be brought back to run state by using fg command.
  • esc-p -- like ctrl-r lets you search through the previously given commands.
  • esc-. -- gives the last command you typed.

How to move Linux to another partition?

I remember the first example didn't helped me much. I was too lazy to investigate why, I decided to go with fresh install.

cp --archive --sparse=always --verbose --one-file-system --target-directory=/mnt/sdb5 /

rsync --archive --inplace --hard-links --acls --xattrs --devices --specials --one-file-system --8-bit-output --human-readable --progress / /mnt/sdb5

List files in tarball

tar is stream packer and don't have index of files present (by default) in a archive. So it must be scanned through to get content. You can decompress the archive or decompress it to /dev/null.

tar -tvzf my_tar.tar.gz >/dev/null

gunzip -c file.tar.gz | tar t > /dev/null

Rsync quick notes

recursive, preserve modification times, verbose. Use --delete to delete files on destination.

rsync -rtv source/ destination/ - content of source, like source/*
rsync -rtv source destination/ - copies whole source

Ban MAC address in iptables

iptables -I INPUT -m mac --mac-source 00:25:d3:81:ff:e1 -j DROP

## if ip forwarding is enabled
iptables -I FORWARD -m mac --mac-source 00:25:d3:81:ff:e1 -j DROP

Ban SMTP for all computers and all destinations

This is needed, otherwise you will be after a few minutes on blacklist on spamhaus. It is impossible to manage all devices on the network and viruses and malware use this to spam people. It is useful to enable some servers like and big hosting providers in the country.

iptables -I FORWARD -o eth1 -p tcp --dport 25 -j REJECT
iptables -I FORWARD -o eth1 -p tcp --dport 25 -d -j ACCEPT

Testing SMTP by hand

This is LOGIN method, I think. Or PLAIN?

perl -MMIME::Base64 -e 'print encode_base64("username\0username\0password");'

See certificate details from HTTPS

I still find this command unintuitive and stupid.

openssl s_client -connect

Setting up routes manually

Routes will be lost after restart. To persist, use /etc/network/interfaces.

route add -net netmask gw
ip route add default via

Compile the Linux kernel old way

I would use make-kpkg these days.

make bzImage
make modules
make modules install

GCC variables

  • compiler: CC=gcc
  • compiler flags: CXXFLAGS
  • linker flags: LDFLAGS

Grepping UTF-8 strings

cat wordlist | ruby -ne 'print if /^\p{Alpha}+?$/'

Your glamor is not working properly

llvmpipe is software acceleration.

hrdina@witch:~$ glxinfo|grep render
direct rendering: Yes
OpenGL renderer string: Gallium 0.4 on llvmpipe (LLVM 3.3, 256 bits)
    GL_NV_conditional_render, GL_NV_fog_distance, GL_NV_light_max_expon

wstring, wcout

wstring and wcout and other wsomething is used in Windows. It is UTF-16LE I think. Really irritating to work with it, especially to create multiplatform programs.

Pack series of images into DjVU + OCR

for i in *.jpg; do convert $i $i.pbm; done
for i in *.pbm; do cjb2 -clean $i $i.djvu; done
djvm -c secretbook.djvu *.djvu
ocrodjvu --engine=tesseract --in-place secretbook.djvu 

PekWM multimedia keys support

# .pekwm/keys

# Multimedia
KeyPress = "XF86AudioMute" { Actions = "Exec amixer set Master toggle" }
KeyPress = "XF86AudioLowerVolume" { Actions = "Exec amixer set Master 5%- unmute" }
KeyPress = "XF86AudioRaiseVolume" { Actions = "Exec amixer set Master 5%+ unmute" }
KeyPress = "XF86AudioPrev" { Actions = "Exec mpc prev" }
KeyPress = "XF86AudioPlay" { Actions = "Exec mpc toggle" }
KeyPress = "XF86AudioNext" { Actions = "Exec mpc next" }

Persistent touchpad configuration in light desktop

First - edit configuration via synclient or synaptiks (gui). Save it with synclient -l > touchpad-settings.

Restore with (add to autostart):

if  -f touchpad-settings ; then
  synclient `cat touchpad-settings | sed 's/\s//g' | tail -n +2`

Password to the SSH key is not required in each action

Filezilla too can use this, just leave the password blank.

ssh-add ~/.ssh/myrtanoid

Linuxové štandardy na desktope

Linux standard base (LSB) - definuje API v niektorých knižniciach ako libtar, cesty k interpretu perlu či pythonu a ich správanie. Samotný štandard má viac častí - core, c++, desktop, printing a polooficiálne je multimédia. Súčasná stabilná verzia 4.1 z roku 2011 je pekne stará a imho ani neberie do úvahy existenciu pythonu 2 a 3 a pracuje s QT3. Štandard sa odkazuje na manuál (pythonu) pri definíciách operátorov a v prípade iných knižníc sú zobrazené hlavičky a štruktúry.

XCB - knižnica na kecanie s X serverom (protokol), ktorá chce nahradiť Xlib (tiež libX11). Nie je štandard, ale pletie sa s XDG. XCB rieši problémy s libX11, ktorá sa ťažko debugguje a je zmes asynchrónnych a synchrónnych volaní.

File Hierarchy Standard (FHS) - posledná verzia 2.3 je z roku 2004. Definuje štandardné zložky ako /etc, /tmp a názvy niektorých súborov, ak daná služba je k dispozícii - resolv.conf, hosts.allow, ...

ICCCM + NetHW - spolupráca medzi window managerom a X serverom a aplikáciami bežiacimi v ňom ako systray alebo dock.

Create encrypted partition

cryptsetup --cipher camellia-xts-plain64 -h sha256 -s 256 luksFormat /dev/sda22

Where are all X sessions registered

VISITORS 24H: 0 48H: 0 1W: 0 1M: 0 Since 2016/01/13: 3347 || PAGEVIEWS 24H: 0 48H: 0 1W:0 1M: 0 Since 2016/01/13: 50430 || BOT ACTIVITY:???