Linux

Boot

add boot entry

remove boot entries

If you can boot into Linux in UEFI mode, use efibootmgr:

If you can boot into Windows in UEFI mode, use bcdedit:

special distro behaviour

Ubuntu

Browser graphic issue:

application shortcut

[Desktop Entry]
Name=Visual Studio Code
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=/usr/share/code/code --unity-launch %F
Icon=vscode
Type=Application
StartupNotify=false
StartupWMClass=Code
Categories=TextEditor;Development;IDE;
MimeType=text/plain;inode/directory;application/x-code-workspace;
Actions=new-empty-window;
Keywords=vscode;

[Desktop Action new-empty-window]
Name=New Empty Window
Exec=/usr/share/code/code --new-window %F
Icon=vscode

manjaro

vmware screen resolution bug

sudo sh -c '(crontab -l; echo "@reboot sleep 5 && systemctl restart vmtoolsd") | sort -u | crontab -'

old, not working/necessary

or create autostart desktop entry:

Raspberry pi

configs

mount exfat USB

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install exfat-fuse
sudo apt-get install exfat-utils

Mounting an exFAT Drive Manually from Terminal:

auto mount on boot for exFAT drives

linux mint (cinnemon)

Fedora

Updates

different locale

Shell

bash basics

default text editor

echo "export VISUAL=nano\nexport EDITOR=nano" >> ~/.bashrc
echo "export VISUAL=nano\nexport EDITOR=nano" >> ~/.zshrc

sudo sh -c "echo -e \"export VISUAL=nano\nexport EDITOR=nano\" >> ~/.bashrc"
sudo sh -c "echo -e \"export VISUAL=nano\nexport EDITOR=nano\" >> ~/.zshrc"

login message:

add for example:

#shell login message
echo -e "\n\n You are working on: \t\e[41m>>> subdomain.my-server.com <<<\e[49m\n\n"

custom shell prompt:

add for example:

#shell login message
alias PS1="\e[0;32m[\u@\h \w]\$ \e[0m"

[test@ubuntu1 ~]$ <- in green

PS3 for select prompt

https://www.thegeekstuff.com/2008/09/bash-shell-take-control-of-ps1-ps2-ps3-ps4-and-prompt_command/

Terminal colors

The first number in the color code specifies the typeface:

The second number indicates the color you want:

color background text
black \e[0;40m \e[0;30m
Red \e[0;41m \e[0;31m
Green \e[0;42m \e[0;32m
Brown \e[0;43m \e[0;33m
Blue \e[0;44m \e[0;34m
Purple \e[0;45m \e[0;35m
Cyan \e[0;46m \e[0;36m
Light gray \e[0;47m \e[0;37m

output redirection

          || visible in terminal ||   visible in file   || existing
  Syntax  ||  StdOut  |  StdErr  ||  StdOut  |  StdErr  ||   file   
==========++==========+==========++==========+==========++===========
    >     ||    no    |   yes    ||   yes    |    no    || overwrite
    >>    ||    no    |   yes    ||   yes    |    no    ||  append
          ||          |          ||          |          ||
   2>     ||   yes    |    no    ||    no    |   yes    || overwrite
   2>>    ||   yes    |    no    ||    no    |   yes    ||  append
          ||          |          ||          |          ||
   &>     ||    no    |    no    ||   yes    |   yes    || overwrite
   &>>    ||    no    |    no    ||   yes    |   yes    ||  append
          ||          |          ||          |          ||
 | tee    ||   yes    |   yes    ||   yes    |    no    || overwrite
 | tee -a ||   yes    |   yes    ||   yes    |    no    ||  append
          ||          |          ||          |          ||
|& tee    ||   yes    |   yes    ||   yes    |   yes    || overwrite
|& tee -a ||   yes    |   yes    ||   yes    |   yes    ||  append

zsh

all in one script

if test -f ~/.zshrc; then
  echo "Installing zsh with oh my zsh and powerlevel10kTheme"

  sudo apt update && sudo apt install curl git zsh
  sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
  git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
  sed -i '/ZSH_THEME="/c\ZSH_THEME="powerlevel10k/powerlevel10k"' ~/.zshrc
fi

To customize prompt, run p10k configure or edit ~/.p10k.zsh.

install zsh

Oh My Zsh Cheatsheet

install powerlevel 10k theme
edit for visual studio code

terminal emulator

terminator

documentation

Shell scripting

cheatsheets:

bash basics

$? last result

conditions

find biggest folders of current directory

du -hs * | sort -rh | head -5

Network

settings

set static ip address

auto ens18
iface ens18 inet static
  address 192.168.0.2
  netmask 255.255.255.0
  gateway 192.168.0.1
  dns-nameservers 89.207.128.252 89.207.130.252

check local network settings

linux commands

restart network

dnsmasq

network analyse

https://armann-systems.com/wiki/netzwerkdiagnose-tools-unter-linux-ein-umfassender-leitfaden/

check open ports

ss -ltup

netstat

nmap

missing

proxy settings

global settings in /etc/environment

http_proxy=http://www-zproxy.myproxy.com:80/
https_proxy=http://www-zproxy.myproxy.com:80/
ftp_proxy=ftp://www-zproxy.myproxy.com:80/
no_proxy=localhost,myproxy.com,.myproxy.com,10.0.0.0/8,127.0.0.1
soap_use_proxy=on

Permissions, Groups

TODO

https://www.pluralsight.com/blog/it-ops/linux-file-permissions

groups

desc:

chmod

chown

DE Desktop environments

gnome

taskbar changes

Gnome Taskbar extentions

other interesting extentions

Different issues and settings

time

time sync

CLI tools

CLI tools

find, search, grep

find

use cases:

more examples

find /path -name *.txt
find /path -type f -name test.txt
find /path -name failed*.* -type f
find /path -type f -not -name "*.html"
find / -name "file.txt" -size +4M
find /dev/ -type b -name "sda*"
find ./*file*

grep

grep [OPTION]... PATTERNS [FILE]...

examples

sed

sed -i 's/SEARCH_REGEX/REPLACEMENT/g' INPUTFILE

CLI tools

Cronjob, tar, autostart, sudo, ln

cronjob

tar

useage: tar [OPTION...] [FILE]...

autostart

sudo

add user to sudo

su -
usermod -aG sudo <username>

no password sudo

CLI tools

CLI Editor

nano

cli parameters/flags

set defaults by editing /etc/nanorc or in ~/.nanorc: (some recommendations)

## Constantly display the cursor position in the status bar or minibar.
set constantshow

## Display line numbers to the left (and any anchors in the margin).
set linenumbers

## Enable mouse support, if available for your system.  When enabled,
## mouse clicks can be used to place the cursor, set the mark (with a
## double click), and execute shortcuts.  The mouse will work in the
## X Window System, and on the console when gpm is running.
set mouse

## Make the Home key smarter: when Home is pressed anywhere but at the
## very beginning of non-whitespace characters on a line, the cursor
## will jump to that beginning (either forwards or backwards).  If the
## cursor is already at that position, it will jump to the true start
## of the line (the left edge).
# set smarthome

## Spread overlong lines over multiple screen lines.
# set softwrap

userful short cuts

shortcuts are displayed on the bottom, maximize to see more

vim

tutorials

vim modes

base commands

movement

text editing

find and replace

searching only

example: /Linux\c + Enter

find and replace

:[range]s/{pattern}/{string}/[flags]

CLI tools

user management

create user

CLI tools

disk/file management

disk

show disk size

show folder size

find biggest folders of current directory

du -hs * | sort -rh | head -5

file movements

rsync

options

local to remote server

rsync [option] [source] user@hostname-or-ip:[destination path]
rsync -avhz /home/source-rsync/ user@your-remote-server.com:/home/dest-rsync/

remote to local server

rsync -avhz user@your-remote-server.com:/home/dest-rsync/ /home/source-rsync/

scp

scp <Optionen> <Quellpfad> <Zielpfad>

example:

scp -r srv01-local_draab:/var/lib/docker/volumes/wireguard_wireguard-config/_data/ /home/danielraab/wireguard/
CLI tools

tmux

tutorial cheatsheet

configs

edit file ~/.tmux.conf as you like

-> gpakosz github

keyboard shortcuts

Ctrl + b ? - show keyboard shortcut overview

pane

windows

modes

CTRL+b then [ Enter copy mode. q Exit copy mode. SPACE Start text selection in copy mode. ENTER Copy the selected text. ESC Clear the selected text and exit the copy mode. CTRL+b then ] Paste the copied text. h Move the cursor left. j Move the cursor down. k Move the cursor up. l Move the cursor right. w Move the cursor one word forward. b Move the cursor one word backward. CTRL+u Scroll up half a page. CTRL+d Scroll down half a page. PgUp Scroll up full page. PgDn Scroll down full page.

configs

adaption for zsh powershell10k

Your tmux has two issues.

It cannot display 256 colors. To fix this, create ~/.tmux.conf with set -g default-terminal screen-256color in it and reboot your machine.

It cannot display non-ascii characters. To fix this, install and enable a UTF-8 locale in your OS and reboot your machine.

You can verify that you've fixed tmux by running the following command:

print -P -- '--> %F{70}\u276E\u276F%f <--'
CLI tools

basic

suspend and continue

special tools

bpftrace

homepage docs

sudo bpftrace --unsafe -e 'tracepoint:signal:signal_generate /args->sig ==9/ {
printf("SIGKILL: target pid=%d sender pid=%d processname=", args->pid, pid);
system("ps -p %d -o comm | sed -n \"2 p\"", pid);
}'

New Server Setup

#!/usr/bin/bash
sudo apt update && sudo apt upgrade
sudo apt -y install fail2ban ufw git curl zsh

cat >> ~/.ssh/authorized_keys << EOF
---pub ssh key---
EOF

echo "vps2" > /etc/hostname

cat >> /etc/hosts << EOF
127.0.0.1       vps2
46.38.233.182   vps2.draab.at vps2
EOF

printf "[sshd]\nenabled = true\nbanaction = iptables-multiport" > /etc/fail2ban/jail.local
systemctl enable fail2ban
ufw allow 222
ufw enable

sed -i -e '/^\(#\|\)PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i -e '/^\(#\|\)PasswordAuthentication/s/^.*$/PasswordAuthentication no/' /etc/ssh/sshd_config
sed -i -e '/^\(#\|\)Port/s/^.*$/Port 222/' /etc/ssh/sshd_config
sed -i -e '/^\(#\|\)KbdInteractiveAuthentication/s/^.*$/KbdInteractiveAuthentication no/' /etc/ssh/sshd_config
sed -i -e '/^\(#\|\)ChallengeResponseAuthentication/s/^.*$/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config
sed -i -e '/^\(#\|\)MaxAuthTries/s/^.*$/MaxAuthTries 2/' /etc/ssh/sshd_config
sed -i -e '/^\(#\|\)AllowTcpForwarding/s/^.*$/AllowTcpForwarding yes/' /etc/ssh/sshd_config
sed -i -e '/^\(#\|\)X11Forwarding/s/^.*$/X11Forwarding no/' /etc/ssh/sshd_config
sed -i -e '/^\(#\|\)AllowAgentForwarding/s/^.*$/AllowAgentForwarding no/' /etc/ssh/sshd_config
sed -i -e '/^\(#\|\)AuthorizedKeysFile/s/^.*$/AuthorizedKeysFile .ssh\/authorized_keys/' /etc/ssh/sshd_config
sed -i '$a AllowUsers danielraab' /etc/ssh/sshd_config

curl -sSL https://get.docker.com | sh
usermod -aG docker danielraab
newgrp docker

#  - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
#  - \. "$HOME/.nvm/nvm.sh"
#  - nvm install 22

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended

reboot