Skip to content

Instantly share code, notes, and snippets.

@alexander-danilenko
Last active April 30, 2024 21:56
Show Gist options
  • Save alexander-danilenko/175b15a02c419bdec9ccc4c83189e510 to your computer and use it in GitHub Desktop.
Save alexander-danilenko/175b15a02c419bdec9ccc4c83189e510 to your computer and use it in GitHub Desktop.
Debian/Ubuntu Cheatsheet

Debian/Ubuntu CheatSheet

Debian

Enable contrib and non-free repositories:

sudo apt-get install -y software-properties-common && \
sudo apt-add-repository contrib && \
sudo apt-add-repository non-free

Use closest local mirror for apt:

sudo apt install -y netselect-apt && sudo netselect-apt

Ubuntu

Enable universe and restricted repositories:

sudo apt-add-repository universe && \
sudo apt-add-repository restricted

Change GRUB resolution and enable os-prober (Windows lookup):

echo 'GRUB_GFXMODE=1024x768x32,auto' | sudo tee -a /etc/default/grub && \
echo 'GRUB_DISABLE_OS_PROBER=false' | sudo tee -a /etc/default/grub && \
sudo update-grub

Remember last GRUB choice and select it by default:

echo 'GRUB_DEFAULT=saved' | sudo tee -a /etc/default/grub && \
echo 'GRUB_SAVEDEFAULT=true' | sudo tee -a /etc/default/grub && \
sudo update-grub

Save alsamixer settings once set: this should save alsamixer configurations to /etc/asound.state which gets loaded every startup.

sudo alsactl store

Pop!_os

Add windows to bootloader:

sudo mkdir -p /mnt/tmp && \
sudo mount /dev/sdb1 /mnt/tmp && \
sudo cp -r /mnt/tmp/EFI/Microsoft /boot/efi/EFI && \
echo "timeout 10" | sudo tee -a /boot/efi/loader/loader.conf

Add needed codecs:

sudo apt install -y ubuntu-restricted-extras libavcodec-extra libdvd-pkg; sudo dpkg-reconfigure libdvd-pkg

Hardware

Keychron Keyboard FN keys

On Linux, the Keychron keyboards doesn’t register any of the F1-F12 function keys as actual F keys, instead, treating them as multimedia keys by default.

To fix this:

  1. Set the keyboard to Windows mode via the side switch

  2. Use Fn + X + L (hold for 4 seconds) to set the function key row to “Function” mode.

  3. Run the following in terminal:

    echo "options hid_apple fnmode=0" | sudo tee -a /etc/modprobe.d/hid_apple.conf && \
    sudo update-initramfs -u

Nvidia

Nvidia: Debian

sudo apt install nvidia-driver

⚠️ NOTE: contrib and non-free repositories needs to be added first

Nvidia: Ubuntu

sudo ubuntu-drivers autoinstall

xBox gamepad

sudo apt install -y dkms linux-headers-$(uname -r) && \
cd $(mktemp -d) && \
git clone https://github.com/atar-axis/xpadneo.git --branch=master xpadneo && \
cd xpadneo && \
chmod +rwx ./*.sh && \
sudo ./install.sh

Terminal

Prerequisites

sudo apt install -y curl wget gnupg2 git jq

ZSH

ZSH is a UNIX command interpreter (shell) usable as an interactive login shell and as a shell script command processor.

Install zsh:

sudo apt install -y zsh

Set it as default for current user:

chsh -s $(which zsh) && sudo !!

ZSH Antigen: Package manager

Antigen is a small set of functions that help you easily manage your shell (zsh) plugins, called bundles. The concept is pretty much the same as bundles in a typical vim+pathogen setup. Antigen is to zsh, what Vundle is to vim.

Install and apply config:

mkdir -p $HOME/.antigen/ && \
curl -L# -o $HOME/.antigen/antigen.zsh git.io/antigen --create-dirs  && \
curl -L# -o $HOME/.profile https://raw.githubusercontent.com/alexander-danilenko/dotfiles/main/.profile && \
curl -L# -o $HOME/.zshrc https://raw.githubusercontent.com/alexander-danilenko/dotfiles/main/.zshrc

Fish is a smart and user-friendly command line shell for Linux, macOS, and the rest of the family.

Install fish:

sudo apt install -y fish

Set it as default for current user:

chsh -s $(which fish) && sudo !!

Copy configs:

mkdir -p $HOME/.config/fish/ && \
curl -L# -o $HOME/.config/fish/config.fish https://raw.githubusercontent.com/alexander-danilenko/dotfiles/main/.config/fish/config.fish && \
curl -L# -o $HOME/.config/fish/fish_variables https://raw.githubusercontent.com/alexander-danilenko/dotfiles/main/.config/fish/fish_variables

Oh My Fish: Package manager

Oh My Fish provides core infrastructure to allow you to install packages which extend or modify the look of your shell. It's fast, extensible and easy to use..

Install oh-my-fish:

curl https://raw.githubusercontent.com/oh-my-fish/oh-my-fish/master/bin/install | fish

Run fish and install plugins:

omf install (curl https://raw.githubusercontent.com/alexander-danilenko/fedora-environment/main/config.yml | yq -rc '.fish.packages[]')

Development

Python

Python is an interpreted, interactive, object-oriented programming language that combines remarkable power with very clear syntax.

Install Python and its package manager

sudo apt install python3 python3-pip

Install yq for parsing yml files format.

pip install yq

Install packages:

curl https://raw.githubusercontent.com/alexander-danilenko/fedora-environment/main/config.yml | yq -rc '.python3.pip3_global_packages[]' | xargs pip install

Node.JS

NVM allows you to quickly install and use different versions of node via the command line.

Install NVM:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash

Install LTS and set as default:

NODE_VERSION=16 && nvm install $NODE_VERSION && nvm alias default "$NODE_VERSION"

Install global packages:

curl https://raw.githubusercontent.com/alexander-danilenko/fedora-environment/main/config.yml | yq -cr '.node.npm_global_packages[]' | xargs npm install --global

⚠️ NOTE: yq python package is required

PHP

sudo apt install -y php-{common,cli,curl,gd,json,mbstring,mysqli,opcache,pdo,xml,zip}

Composer

mkdir -p $HOME/.composer && \
sudo curl -#fsSL https://getcomposer.org/composer-stable.phar -o /usr/local/bin/composer && \
sudo chmod 755 /usr/local/bin/composer && \
composer --version && \
composer global require drupal/coder squizlabs/php_codesniffer friendsofphp/php-cs-fixer && \
cp -rf \
  ~/.composer/vendor/drupal/coder/coder_sniffer/Drupal* \
  ~/.composer/vendor/squizlabs/php_codesniffer/src/Standards

JetBrains Toolbox

curl -Ls https://raw.githubusercontent.com/nagygergo/jetbrains-toolbox-install/master/jetbrains-toolbox.sh | sudo bash

Extend inotify

⚠️ https://youtrack.jetbrains.com/articles/IDEA-A-2/Inotify-Watches-Limit

Inotify requires a "watch handle" to be set for each directory in the project. Unfortunately, the default limit of watch handles may not be enough for reasonably sized projects, and reaching the limit will force IntelliJ platform to fall back to recursive scans of directory trees.

To prevent this situation it is recommended to increase the watches limit (to, say, 512K)

grep '^fs.inotify.max_user_watches=524288' /etc/sysctl.conf || \
echo  'fs.inotify.max_user_watches=524288' | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Visual Studio Code

Add rpm repo and install code package

sudo apt-get install wget gpg && \
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg && \
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg && \
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list' && \
rm -f packages.microsoft.gpg && \
sudo apt update && sudo apt install code

Install extensions

curl https://raw.githubusercontent.com/alexander-danilenko/fedora-environment/main/config.yml | yq .apps.visual_studio_code.extensions[] -cr | while read extension; do code --install-extension $extension --force; done

⚠️ NOTE: yq python package is required

Sublime Apps

curl -fsSL https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add - && \
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime.list && \
sudo apt update && \
sudo apt install -y sublime-{text,merge} && \
curl -L# -o $HOME/.config/sublime-text-3/Packages/User/Preferences.sublime-settings --create-dirs https://raw.githubusercontent.com/alexander-danilenko/dotfiles/main/.config/sublime-text-3/Packages/User/Preferences.sublime-settings

Packages

APT

PACKAGES=(
  # System/CLI apps
  curl        # Command line tool for transferring data with URL syntax
  gnupg2
  default-{jre,jdk} # Java Runtime + development kit
  #exfat-{fuse,utils} # Read and write exFAT driver
  heif-{gdk-pixbuf,thumbnailer}  # Apple HEIF/HEIC decoder support 
  htop        # Terminal system monitor
  jq          # Takes JSON input and retrieves data by query.
  mc          # Two panel terminal file manager
  neofetch    # Shows Linux System Information with Distribution Logo
  net-tools   # Base network tools
  nfs-common  # Package for work with NFS shares
  stacer      # Cool CleanMyMac alternative
  tree        # Displays an indented directory tree, in color
  #grub-customizer # GUI for GRUB settings management

  # Archive formats support
  arj         # arj archiver
  lhasa       # lzh unarchiver
  rar         # rar archiver
  unrar       # rar unarchiver
  unzip       # zip unarchiver
  zip         # zip archiver

  # Office
  libreoffice
  libreoffice-base-drivers    # Base drivers
  libreoffice-help-{en-us,ru} # Help: English, Russian
  libreoffice-l10n-{ru,uk}    # Localization: Russian, Ukrainian
  evolution{,-ews}            # Outlook alternative + Exchange support

  fonts-{dejavu,hack,open-sans,roboto,ubuntu}
) && sudo apt install -y ${PACKAGES[*]}

DEB

DEB_URLS=(
  https://downloads.1password.com/linux/debian/amd64/stable/1password-latest.deb
  https://repo.skype.com/latest/skypeforlinux-64.deb
  https://download.anydesk.com/linux/anydesk_6.2.0-1_amd64.deb
  #https://download.teamviewer.com/download/linux/teamviewer_amd64.deb
  #https://fortinetweb.s3.amazonaws.com/forticlient/downloads/FortiClientFullVPNInstaller_6.4.3.0959_amd64.deb
) && cd $(mktemp -d) && wget -q --continue --show-progress ${DEB_URLS[*]} && sudo dpkg -i *.deb && sudo apt-get -f install && cd -

Flatpak

Flatpak is a tool for managing applications and the runtimes they use. In the Flatpak model, applications can be built and distributed independently from the host system they are used on, and they are isolated from the host system ('sandboxed') to some degree, at runtime.

Install flatpak:

sudo apt install flatpak

Add flathub remote:

flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo

Install apps:

curl https://raw.githubusercontent.com/alexander-danilenko/fedora-environment/main/config.yml | yq -rc '.apps.flatpak[]' | xargs flatpak install -y --user

⚠️ NOTE: yq python package is required

Fix cursors:

flatpak --user override --filesystem=/home/$USER/.icons/:ro && \
flatpak --user override --filesystem=/home/$USER/.local/share/:ro

Wireguard VPN

Server

Quick setup script: https://github.com/Nyr/wireguard-install

wget https://git.io/wireguard -O wireguard-install.sh && bash wireguard-install.sh

Client (Ubuntu)

  • Install prerequisites:
    sudo apt install wireguard resolvconf
  • Copy config to /etc/wireguard/wg0.conf file
    • or copy: sudo cp -f ~/.keys/vpn/personal-wireguard/*.conf /etc/wireguard/
  • ⚠️ Make sure port from config is whitelisted in firewall: sudo ufw allow 58320/udp
  • Enable autostart: sudo systemctl enable wg-quick@wg0
  • Disable autostart: sudo systemctl disable wg-quick@wg0
  • Start: sudo systemctl start wg-quick@wg0
  • Stop: sudo systemctl stop wg-quick@wg0
  • Status: sudo systemctl status wg-quick@wg0
#!/usr/bin/env python3

import click
import subprocess

@click.command(help='Manages Wireguard VPN.')
@click.argument('action', type=click.Choice(['start', 'stop', 'enable', 'disable', 'status']))
@click.option('--config', help='Config name.', default='wg0')
def wireguard_manager(action, config):
    if action in ['start', 'stop', 'enable', 'disable', 'status']:
        subprocess.call(f'set -ex && sudo systemctl {action} wg-quick@{config}', shell=True)

if __name__ == '__main__':
    wireguard_manager()

Containerization

Docker

Make sure current release version added in: https://download.docker.com/linux/fedora/

source /etc/os-release && \
sudo mkdir -p /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu $UBUNTU_CODENAME stable" | sudo tee /etc/apt/sources.list.d/docker-ce.list && \
sudo apt update && \
sudo apt install -y docker-{ce,compose} && \
sudo usermod -aG docker $USER  && \
sudo systemctl enable docker && \
sudo systemctl restart docker && \
newgrp docker

Docksal

bash <(curl -fsSL https://get.docksal.io)

Desktop

Themes installer: https://github.com/alexander-danilenko/ubuntu-themes-installer

OCS-url: https://www.opendesktop.org/p/1136805/#files-panel

GTK Themes

Gnome Shell themes

Icons

Cursors

Google Fonts

List fonts available to install:

curl https://gwfh.mranftl.com/api/fonts | jq '.[].id' -cr | sort

Install needed fonts:

FONTS_DIR="$HOME/.fonts"
FONTS=(
  jetbrains-mono
  open-sans
  roboto
  roboto-mono
  roboto-slab
  ubuntu
  ubuntu-mono
) && \
mkdir -p $FONTS_DIR && \ 
for FONT in ${FONTS[@]}; do
  DOWNLOAD_URL="https://google-webfonts-helper.herokuapp.com/api/fonts/${FONT}?download=zip&formats=ttf"
  FILE_PATH="/tmp/$FONT-ttf.zip"
  curl "$DOWNLOAD_URL" -o "$FILE_PATH"
  unzip -o $FILE_PATH -d $FONTS_DIR
done

Update fonts cache (may take a while): sudo fc-cache -f -v

Gnome

Gnome Tweaks:

sudo apt install -y gnome-tweaks

Gnome Extensions

Name Description
Battery Percentage (for laptops) Show battery remaining power percentage at the top panel
Blyr Blur Effect to GNOME Shell UI elements
Compiz alike magic lamp effect Magic lamp effect for minimizing windows
Compiz windows effect Compiz wobbly windows effect
Dash to Dock This extension moves the dash out of the overview transforming it in a dock for an easier launching of applications and a faster switching between windows and desktops
Dash to Panel Moves the dash into the gnome main panel so that the application launchers and system tray are combined into a single panel, similar to that found in KDE Plasma and Windows 7+
Emoji Selector Provides a parametrable popup menu displaying most emojis, clicking on an emoji copies it to the clipboard
Hide Activities Button Hides the Activities button from the status bar
Notification Alert Whenever there is an unread notification (e.g. chat messages), blinks the message in the user's menu with a color chosen by the user
Sound Input & Output Device Chooser Shows a list of sound output and input devices (similar to gnome sound settings) in the status menu below the volume slider
Tray Icons: Reloaded Bring back Tray Icons to top panel, with additional features
User Themes Gnome Shell themes support
Wireless HID Shows the battery of the wireless keyboards, mice, and game controllers in percentages and colors

General tips and code snippets

NFS Shares

Prerequisite packages:

sudo apt install -y nfs-common

Create directories before mounting:

sudo mkdir -p /mnt/{D,E} /mnt/NAS/{Books,Homes,Install,Music,Videos,Downloads}

Add to /etc/fstab:

192.168.50.123:/volume1/homes     /mnt/NAS/Homes      nfs defaults 0 0
192.168.50.123:/volume1/downloads /mnt/NAS/Downloads  nfs defaults 0 0
192.168.50.123:/volume1/Music     /mnt/NAS/Music      nfs defaults 0 0
192.168.50.123:/volume1/Videos    /mnt/NAS/Videos     nfs defaults 0 0
192.168.50.123:/volume1/Books     /mnt/NAS/Books      nfs defaults 0 0
192.168.50.123:/volume1/Install   /mnt/NAS/Install    nfs defaults 0 0

UUID=4A764FAE764F9A19 /mnt/E ntfs-3g nosuid,nodev,nofail,x-gvfs-show 0 0
UUID=36CEFCE4CEFC9D75 /mnt/D ntfs-3g nosuid,nodev,nofail,x-gvfs-show 0 0

SWAP

Set swap to 16GB:

# Create swap.
SWAP_SIZE='16G' && \
SWAP_FILE='/swapfile' && \
sudo swapoff -a && \
sudo rm -rf ${SWAP_FILE} && \
sudo fallocate -l ${SWAP_SIZE} ${SWAP_FILE} && \
sudo chmod 600 ${SWAP_FILE} && \
sudo mkswap ${SWAP_FILE} && \
sudo swapon ${SWAP_FILE} && \
sudo swapon -a

# Mount swap on each system load. 
grep -q "$SWAP_FILE" /etc/fstab || echo "$SWAP_FILE none swap sw 0 0" | sudo tee -a /etc/fstab

Backup home directory

Navigate to external drive or NAS mounted dir and make archive:

#!/usr/bin/env bash

backupDate=$(date +%F)
backupTime=$(date +%k-%M-%S)
mkdir -p "$backupDate"

exclude=(
  --exclude=".cache/*"
  --exclude=".config/*"
  --exclude=".mozilla/*"
  --exclude=".gcp/google-cloud-sdk"
  --exclude=".local/share/*"
  --exclude=".npm/*"
  --exclude=".SynologyDrive/*"
  --exclude=".yarn/*"
  --exclude=".var/*"
  --exclude="**/node_modules/*"
  --exclude="Projects"
  --exclude="snap/*"
  --exclude="SynologyDrive/*"
)

secrets=(
  $HOME/.aws
  $HOME/.bash*
  $HOME/.gcp
  $HOME/.git*
  $HOME/.gnupg
  $HOME/.keys
  $HOME/.profile*
  $HOME/.ssh
  $HOME/.terraform*
  $HOME/.zsh*
)

tar ${exclude[*]} -cvpzf "$backupDate/$backupTime-$USER-secrets.tar.gz"  ${secrets[*]} 
tar               -cvpzf "$backupDate/$backupTime-$USER-config.tar.gz"   $HOME/.config $HOME/.var $HOME/.mozilla
tar               -cvpzf "$backupDate/$backupTime-$USER-projects.tar.gz" $HOME/Projects
tar ${exclude[*]} -cvpzf "$backupDate/$backupTime-$USER-home.tar.gz"     $HOME

Troubleshooting

Linux Bootloader is gone after Windows install

Documentation: https://help.ubuntu.com/community/Boot-Repair

sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt update
sudo apt install -y boot-repair && boot-repair
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment