2>&1 Website under construction!

"Linux" on https://aligot-death.space, available at https://aligot-death.space/wiki/linux-en

wiki/sysadmin system administration


Linux tips and notes.

Read it aloud: play pause stop


Linux performance monitoring tools#

See http://www.brendangregg.com/linuxperf.html

Simple log analyzer for web traffic#

sudo apt install goaccess

Then use like:

sudo goaccess /var/log/nginx/access.log.1 -c

Using SSH as a VPN#

1 ssh -NTCD 12345 SSH_remote_host_IP

Then in firefox Preference > Network Setting > Settingsā€¦ proxy as socks with 127.1:12345 Or for a SSH

1 ssh -o ProxyCommand='nc -x localhost:12345 %h %p' username@Far_Away_Host

from: https://blog.gwlab.page/vpn-over-ssh-the-socks-proxy-8a8d7bdc7028

or sshuttle

Avoid have to type SSH passphrase everytime#

from How to avoid being asked passphrase each time I push to Bitbucket

1 ssh-add


Add current user to sudo:

1 usermod nemecle -aG sudo

To install missing firmware (as printed during boot sequence), this command might be enough:

1  sudo apt install firmware

Basic packages to install:

1 sudo apt install vim sysstat mlocate tmux python3-pip htop rofi xbindkeys
2 keepassxc rsync fd-find hwinfo gparted curl

Easy network management from terminal#

the nmcli utility is very easy and useful to manage network settings, including Wi-fi connections.

For instance, listing available Wi-Fi networks:

1 nmcli d wifi list

Connecting to a wifi network:

1 nmcli d wifi connect "Super Wifi" password "John19970612"

Mounting secondary drive on boot#

  1. sudo blkid
  2. sudo umount /mnt/xxx
  3. vim /etc/fstab: if in doubt, just pu UUID, mount point, FS type and "defaults 0 0"

Recovering from deleted /boot/efi (dual boot)#

the "/boot/efi" partition used to boot is not exclusive to Linux: it is shared with Windows, and thus you can (and should) provide it to utility tools that fix boot. It is usually on /dev/sda2. You can ls -l /boot/efi from a functioning linux to check its content.

The command to "install" grub requires to provide the disk, not a specific partition (e.g. /dev/sda, not /dev/sda2)

The following lines are a crude hint, the full operation might require some other mounting.

First, create a live USB/CD system, and boot on it.

Then we mount the dead system to be able to work with it:

1 for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do sudo mount -B /mnt$i; done

And we chroot to act as if we were on the dead system:

1 chroot /mnt

Then we mount the EFI partition:

1 mount /dev/sda2 /boot/efi

And finally we execute the "grub-install" command: The bootloader-id argument will be the name appearing in the EFI boot list if you go to the boot menu. Type the following command very carefully, a lot of people online seem to have errors simply due to typos:

1 sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=debian --recheck --debug /dev/sda

You may eventually do (once you left chroot with exit like any shell instance):

1 update-grub

vim battle hardened config#

set encoding=utf-8
syntax on
set nu
set rnu
set hls
set sm
set smarttab
set nocompatible
set clipboard=unnamed
set scrolloff=30
set backspace=indent,eol,start " backspace over everything in insert mode
set ignorecase  " do case insensitive search
set incsearch   " show incremental search results as you type

" colorscheme peachpuff
highlight LineNr ctermfg=black ctermbg=grey
let g:indentLine_color_term = 239

noremap <space> :
nnoremap <F2> za " Enable folding with F2

" Always show statusline
set laststatus=2
set t_Co=256"

set foldmethod=indent
set foldlevel=99

set tabstop=4
set softtabstop=4
set shiftwidth=4
set textwidth=79
set wrapmargin=0
set expandtab
set autoindent
set fileformat=unix

" web
au BufNewFile,BufRead *.html,*.css,*js
    \ set tabstop=2 |
    \ set softtabstop=2 |
    \ set shiftwidth=2

autocmd BufRead,BufNewFile /etc/nginx/sites-*/* setfiletype conf

" to test
" Bind  key to run python3
" map  :w\|!python3 %
" " Bind  key to run doctests in a python3 module
" map  :w\|!python3 -m doctest %
" " Bind  key to run doctests with verbose output
" map  :w\|!python3 -m doctest -v %
" " Bind  key to run pep8 Python style checker
" map  :w\|!pep8 %

Changing the theme for GTK from CLI#

(for instance, If you use typical GTK utilities in i3)

1 vim $HOME/.config/gtk-3.0/settings.ini

Example config:

1 [Settings]
2 gtk-icon-theme-name = Paper
3 gtk-theme-name = Arc-Darker
4 gtk-font-name = DejaVu Sans 11


Creating a timelapse#

1080p/30i with jpg files:

1 ffmpeg -framerate 30 -pattern_type glob -i '*.jpg' -c:v libx264 -r 30 -pix_fmt yuv420p -s hd1080 out.mp4

Concatenate ".ts" files from local record#

For instance, if you made a local record using OBS

Create file list:

File order might be wrong, to fix

1 (for %i in (*.ts) do @echo file '%i') > mylist.txt

Then concatenate to a single mp4 file:

1 ffmpeg -f concat -i mylist.txt -c copy output.mp4

Wacom tablet configuration#

CLI commands for left-handed, second screen excluded:

1 xsetwacom set "Wacom Bamboo 16FG 4x5 Pen stylus" rotate HALF
2 xsetwacom set "Wacom Bamboo 16FG 4x5 Pen eraser" rotate HALF
3 xsetwacom set "Wacom Bamboo 16FG 4x5 Pen stylus" MapToOutPut 1920x1080+0+0
4 xsetwacom set "Wacom Bamboo 16FG 4x5 Pen eraser" MapToOutPut 1920x1080+0+0

To debug: (from Measuring level of pressure in wacom, tablets or other devices)

the GIMP configuration: https://digimend.github.io/support/howto/apps/gimp/

"can't read superblock"#

Not necessarly a drive fault, can for instance mean that it doesn't have enough power for external drive https://askubuntu.com/questions/539880/cant-mount-an-ide-hdd-cant-read-superblock-error-message

debugging CLI software#

Set LD_DEBUG environment variable

Emergency mode#

Happened to me as I changed my DATA HDD. because I added it to /etc/fstab and the disk wasn't the same anymore, the system would drop into emergency mode.

Once connected, try mounting all mount points and see errors:

mount -a

Safe bash script boilerplate#

from full boilerplate here https://betterdev.blog/minimal-safe-bash-script-template/

Add right after shebang:

1 set -Eeuo pipefail

Direct kernel communication through key combo#

Can be useful in case of partially stalled or locked system

Alt, press SysRq (The SysRq being the Print Screen key), release SysRq, press <command key>, Hit ALT-SysRq-<command key>, release everything.

Or if possible,

1 echo t > /proc/sysrq-trigger

with t being the command key.

See the wikipedia page for full command key list.

Can't beat a tool that has a "Perform a system crash" feature.

Managing multiple screens from CLI/i3wm#

install xrandr. On debian, do:

sudo apt install x11-xserver-utils

More often than not, this is enough:

xrandr --auto

to see possible settings, type:


to add a second screen next to a 2560x1440, plugged on HDMI2:

xrandr --output HDMI-2 --pos 2560x0 --mode 1920x1080 --rate 60

Remove a screen:

xrandr --output HDMI-2 --off