Skip to content

Instantly share code, notes, and snippets.

@alexander-danilenko
Last active October 6, 2024 14:52
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

Prerequisites

Musthave packages:

sudo apt install -y curl wget git gnupg mc jq yq cifs-utils nfs-common python3-full python3-pip

Enable additional 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

Hardware

Nvidia

https://wiki.debian.org/NvidiaGraphicsDrivers

sudo apt install nvidia-driver firmware-misc-nonfree nvidia-cuda-dev nvidia-cuda-toolkit

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

Software

Terminal

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

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 bobthefish bass nvm aws;
omf theme bobthefish

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.
  yq          # Takes YAML 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:

FLATPAKS=(
  com.getpostman.Postman     # API debugging tool
  com.redis.RedisInsight     # Redis GUI client
  com.slack.Slack            # Slack messenger
  com.synology.SynologyDrive # Synology Drive Client
  com.xnview.XnViewMP        # Image viewer
  org.remmina.Remmina        # Remote desktop client (RDP, VNC)
  org.telegram.desktop       # Best IM!
) && flatpak install ${FLATPAKS[*]}

Fix cursors

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

Fix Flatpak Postman crash

postmanlabs/postman-app-support#12330 (comment)

cd ~/.var/app/com.getpostman.Postman/config/Postman/proxy && openssl req -subj '/C=US/CN=Postman Proxy' -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -keyout postman-proxy-ca.key -out postman-proxy-ca.crt && cd -

Development

Python

Conda

https://docs.anaconda.com/miniconda/

conda is a package and environment management tool primarily used in data science and machine learning, allowing you to install, manage, and update packages across multiple programming languages. It enables the creation of isolated environments with specific dependencies to avoid conflicts between projects.

conda is popular for managing Python, R, and other scientific libraries efficiently.

Install conda:

mkdir -p ~/miniconda3 && \
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh && \
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 && \
rm -rf ~/miniconda3/miniconda.sh

After installing, initialize your newly-installed Miniconda. The following commands initialize for bash and fish shells:

~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init fish

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/master/install.sh | bash

Install LTS and set as default:

NODE_VERSION=20 && \
nvm install $NODE_VERSION && \
nvm alias default "$NODE_VERSION"

Install global packages:

NPM_PACKAGES=(
  '@nestjs/cli' # Nest.JS CLI
  contentful-cli # Contentful.com CLI
  dynamodb-admin # Handy Web-UI for viewing local DynamoDB data
  eslint
  eslint-config-airbnb
  eslint-config-google
  eslint-config-standard
  eslint-plugin-import
  eslint-plugin-jsx-a11y
  eslint-plugin-node
  eslint-plugin-promise
  eslint-plugin-react
  eslint-plugin-react-hooks
  firebase-tools
  http-server # Simple HTTP server for static files in directory
  snyk # snyk.com CLI
  typescript
) && npm install --global ${NPM_PACKAGES[@]}

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 | bash

Extend inotify

Note

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

https://code.visualstudio.com/docs/setup/linux#_debian-and-ubuntu-based-distributions

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

Download config:

curl https://raw.githubusercontent.com/alexander-danilenko/dotfiles/main/.config/Code/User/settings.json > ~/.config/Code/User/settings.json

Install extensions

CODE_EXTENSIONS=(
  GitHub.copilot                       # GitHub Copilot!
  GitHub.vscode-github-actions         # Github Actions support
  acarreiro.calculate                  # Calculates inline math expr
  christian-kohler.path-intellisense   # File path autocomplete
  dakara.transformer                   # Filter, Sort, Unique, Reverse, Align, CSV, Line Selection, Text Transformations and Macros
  dotenv.dotenv-vscode                 # .env support
  editorconfig.editorconfig            # EditorConfig support
  golang.go                            # Golang support
  ms-azuretools.vscode-docker          # Docker support
  ms-python.python                     # Python support
  ms-vscode-remote.remote-ssh          # SSH support
  tommasov.hosts                       # Hosts file syntax highlighter
  tyriar.lorem-ipsum                   # Lorem Ipsum generator
  yzhang.markdown-all-in-one           # Markdown tools
  #redhat.ansible                      # Ansible support

  # Node/NPM/Yarn specific extensions
  christian-kohler.npm-intellisense # NPM better autocomplete
  dbaeumer.vscode-eslint            # Eslint support
  
  # Themes
  github.github-vscode-theme    # GitHub color theme
  pkief.material-icon-theme     # Material Icon Theme
  rokoroku.vscode-theme-darcula # JetBrains-like theme
) && for extension in "${CODE_EXTENSIONS[@]}"; do
  code --install-extension "$extension" --force
done

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

Cloud

AWS Cli

https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
unzip awscliv2.zip && \
sudo ./aws/install

Google Cloud

https://cloud.google.com/sdk/docs/install#deb

Add repository:

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg && \
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

Install packages:

GCLOUD_APPS=(
  google-cloud-cli
  # google-cloud-cli-anthos-auth
  # google-cloud-cli-app-engine-go
  # google-cloud-cli-app-engine-grpc
  # google-cloud-cli-app-engine-java
  # google-cloud-cli-app-engine-python
  # google-cloud-cli-app-engine-python-extras
  # google-cloud-cli-bigtable-emulator
  # google-cloud-cli-cbt
  # google-cloud-cli-cloud-build-local
  # google-cloud-cli-cloud-run-proxy
  # google-cloud-cli-config-connector
  # google-cloud-cli-datastore-emulator
  # google-cloud-cli-firestore-emulator
  # google-cloud-cli-gke-gcloud-auth-plugin
  # google-cloud-cli-kpt
  # google-cloud-cli-kubectl-oidc
  # google-cloud-cli-local-extract
  # google-cloud-cli-minikube
  # google-cloud-cli-nomos
  # google-cloud-cli-pubsub-emulator
  # google-cloud-cli-skaffold
  # google-cloud-cli-spanner-emulator
  # google-cloud-cli-terraform-validator
  # google-cloud-cli-tests
  # kubectl
) && sudo apt install ${GCLOUD_APPS[@]}

OpenTofu

https://opentofu.org/docs/intro/install/deb/#set-up-the-opentofu-repository

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://get.opentofu.org/opentofu.gpg | sudo tee /etc/apt/keyrings/opentofu.gpg >/dev/null && \
curl -fsSL https://packages.opentofu.org/opentofu/tofu/gpgkey | sudo gpg --no-tty --batch --dearmor -o /etc/apt/keyrings/opentofu-repo.gpg >/dev/null && \
sudo chmod a+r /etc/apt/keyrings/opentofu.gpg /etc/apt/keyrings/opentofu-repo.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main
deb-src [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main" \
sudo tee /etc/apt/sources.list.d/opentofu.list > /dev/null && \
sudo chmod a+r /etc/apt/sources.list.d/opentofu.list && \ 
sudo apt update && \
sudo apt install tofu

Terraform

https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli

wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null && \
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list && \
sudo apt update && \
sudo apt install terraform

Containerization

Docker

https://docs.docker.com/engine/install/debian/#install-using-the-repository

Add current user to docker group and ebnable docker service:

sudo usermod -aG docker $USER  && \
sudo systemctl enable docker && \
sudo systemctl restart docker && \
newgrp docker

Docksal

https://docksal.io/installation#linux-supported

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

Docker NVIDIA Conteiner Toolkit

  1. https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html#installing-with-apt
  2. https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html#configuring-docker

Desktop

Icons

Cursors

Gnome

Gnome Tweaks:

sudo apt install -y gnome-tweaks

Gnome Extensions

Name Description
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

KDE

KDE apps:

KDE_APPS=(
  kompare
  krename
  krusader
) && sudo apt install ${KDE_APPS[*]}

NFS Share automount

Prerequisite packages:

sudo apt install -y nfs-common

Create directories first:

sudo mkdir -p /mnt/NAS/{Homes,Media,Software} && \
sudo chmod 755 /mnt/NAS/{Homes,Media,Software}

Add to /etc/fstab:

192.168.50.123:/volume1/homes    /mnt/NAS/Homes     nfs defaults,nofail 0 0
192.168.50.123:/volume2/Media    /mnt/NAS/Media     nfs defaults,nofail 0 0
192.168.50.123:/volume3/Software /mnt/NAS/Software  nfs defaults,nofail 0 0

Tip

nofail allows the system to continue booting even if the file system cannot be mounted. This is especially useful for external or network disks that may not be available at boot time.

Tweaks

Alsamixer save configuration

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

sudo alsactl store

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

https://wiki.debian.org/Boot-Repair#Installation

Boot into last booted grub record

In /etc/default/grub

Set:

GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true

Then apply the grub updates to grub config:

sudo sudo update-grub -o /boot/grub/grub.cfg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment