Skip to content

Instantly share code, notes, and snippets.

@nhthai2005
Last active December 28, 2023 23:05
Show Gist options
  • Save nhthai2005/ce79dbb6782518bbf2ceb52ab644e507 to your computer and use it in GitHub Desktop.
Save nhthai2005/ce79dbb6782518bbf2ceb52ab644e507 to your computer and use it in GitHub Desktop.
Install neccessary tools and configure something on Ubuntu
#!/bin/bash
sudo add-apt-repository ppa:bamboo-engine/ibus-bamboo
sudo apt-get update
# Install all necessary tools with the following command
sudo apt install vim htop terminator meld glogg curl git totem keepass2 \
kazam ksnip maven remmina libreoffice network-manager-l2tp-gnome \
ibus-bamboo gnome-calendar gnome-weather gnome-clocks \
qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager -y; \
sudo snap install skype krita gimp chromium; \
sudo snap install codium --classic
# Check ufw status
sudo ufw status
# Enable ufw
sudo ufw enable
# Check ufw status again
sudo ufw status
# To set the default UFW incoming policy to deny
sudo ufw default deny incoming
# To set the default UFW outgoing policy to allow
sudo ufw default allow outgoing
# Check configuration again
sudo ufw status verbose
# Install docker, docker-compose
sudo apt-get update -y && sudo apt-get install -y docker.io
sudo systemctl enable docker.socket docker.service
sudo systemctl start docker.socket docker.service
sudo usermod -aG docker $USER
# docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod x /usr/local/bin/docker-compose
# Disable Wayland to use X11
sudo sed -i 's/# WaylandEnable=false/WaylandEnable=false/' /etc/gdm3/custom.conf

Install neccessary tools on Ubuntu

sudo add-apt-repository ppa:bamboo-engine/ibus-bamboo
sudo apt-get update

# Install all necessary tools with the following command
sudo apt install vim htop terminator meld glogg curl git totem keepass2 \
     kazam ksnip maven remmina libreoffice network-manager-l2tp-gnome \
     ibus-bamboo gnome-calendar gnome-weather gnome-clocks \
     qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager -y; \
     sudo snap install skype krita gimp chromium; \
     sudo snap install codium --classic

# Or install each tool as below:
# Editor on terminal - CLI
sudo apt install vim

# Terminal for command line
sudo apt install terminator

# Monitor CPU/Mem
sudo apt install htop

# Read, filter, compare logs
sudo apt install meld glogg

# Store password offline - password manager
sudo apt install keepass2

# Capture picture and video from screen
sudo apt install kazam ksnip

# Tools for developer: curl git maven
sudo apt install curl git maven
# sudo apt install curl git maven=3.6.3-5 if it is specified version for maven

# Remote desktop
sudo apt install remmina

# Play video - Gnome Video
sudo apt install totem

# Vietnamese Input Method Engine
sudo apt install ibus-bamboo

# Calendar application for GNOME
sudo apt install gnome-calendar

# access current conditions and forecasts
sudo apt install gnome-weather

# Simple GNOME app with stopwatch, timer, and world clock support
sudo apt install gnome-clocks

# Office tools like MS Word, Excel, Powerpoint
sudo apt install libreoffice

# L2TP plugin GNOME GUI
sudo apt install network-manager-l2tp-gnome

# KVM, QEMU and libvirt
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager

# Group chat
sudo snap install skype

# Chromium web browser, open-source version of Chrome
sudo snap install chromium

# Code editing. Redefined like vscode
sudo snap install codium --classic

# Digital Painting, Creative Freedom
sudo snap install krita

# GNU Image Manipulation Program
sudo snap install gimp

Enable ufw firewall

# Check ufw status
sudo ufw status

# Enable ufw
sudo ufw enable

# Check ufw status again
sudo ufw status

# To set the default UFW incoming policy to deny
sudo ufw default deny incoming

# To set the default UFW outgoing policy to allow
sudo ufw default allow outgoing

# Check configuration again
sudo ufw status verbose
Output:
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), deny (routed)

How to change user password

passwd

How to change LUKS password

sudo lsblk
# See sda4_crypt

sudo cryptsetup luksChangeKey /dev/sda4
Enter LUKS passphrase to be changed:
Enter new LUKS passphrase:

Configure Vietnamese Input Method Engine

Settings > Keyboard > Input Sources > > Vietnamese > Vietname (Unikey)

Tools depend on user needs

  • Google Chrome:

  • Forticlient VPN

  • Visual Studio Code:

    • Download .deb: https://code.visualstudio.com/download

    • Install by CLI: sudo apt install ./code_1.61.2-1634656828_amd64.deb

    • Extensions: Ansible, CodeSnap, GitLens

    • Configure: edit ~/.config/Code/User/settings.json (shortcut Ctrl ,)

      {
          "workbench.colorTheme": "Default Dark ",
          "terminal.integrated.fontFamily": "MesloLGS NF",
          "ansible.ansible.path": "/home/shant/App/ans/bin/ansible",
          "ansible.ansible.useFullyQualifiedCollectionNames": true,
          "ansible.ansibleLint.enabled": true,
          "ansible.ansibleLint.path": "/home/shant/App/ans/bin/ansible-lint",
          "ansible.python.activationScript": "/home/shant/App/ans/bin/activate",
          "ansible.python.interpreterPath": "/usr/bin/python3",
          "security.workspace.trust.untrustedFiles": "open",
          "git.autofetch": true,
          "editor.tabSize": 2,
          "redhat.telemetry.enabled": false,
          "[ansible]": {
              "editor.detectIndentation": true,
              "editor.insertSpaces": true,
              "editor.tabSize": 2,
              "editor.quickSuggestions": {
                  "comments": true,
                  "other": true,
                  "strings": true
              }
          },
          "files.associations": {
              "*.yml": "ansible",
              "*.j2": "ansible-jinja",
              "**/templates/**": "ansible-jinja"
          },
      }
      
  • Sublime text:

    • Install:
      # Install the GPG key:
      wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/sublimehq-archive.gpg > /dev/null
      
      # Ensure apt is set up to work with https sources:
      sudo apt-get install apt-transport-https
      
      # Select the channel to use:
      echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
      
      # Update apt sources and install Sublime Text
      sudo apt-get update
      sudo apt-get install sublime-text
      
    • Packages: Package Control, Vn Ime, Alignment, MarkdownPreview
    • Confgure: Preferences > Settings
      {
        "font_size": 12,
        "ignored_packages":
        [
          "Vintage",
        ],
        "telex": true,
        "font_face": "Arial Bold",
        "tab_size": 2,
      }
      
  • Excalidraw: https://excalidraw.com/

  • Eclipse IDE

  • IntelliJ IDEA

    • Install:

      # Step 1: Start by opening a terminal window and execution of the bellow apt command. Select your preferred version to install:
      $ sudo snap install intellij-idea-community --classic
      OR
      $ sudo snap install intellij-idea-ultimate --classic
      OR
      $ sudo snap install intellij-idea-educational --classic
      
      # Step 2: start the IntelliJ IDEA using the below command:
      $ intellij-idea-community
      OR
      $ intellij-idea-ultimate
      OR
      $ intellij-idea-educational
      
    • Configure: Open IDE → Edit → Preferences → Editor → Color Scheme → Console Font. Select Use console font instead of the default and set the font name to MesloLGS NF.

  • Reference:

  • SmartGit (Git GUI)

  • Beekeeper Studio (SQL Editor)

    # Install our GPG key
    wget --quiet -O - https://deb.beekeeperstudio.io/beekeeper.key | sudo apt-key add -
    
    # add our repo to your apt lists directory
    echo "deb https://deb.beekeeperstudio.io stable main" | sudo tee /etc/apt/sources.list.d/beekeeper-studio-app.list
    
    # Update apt and install
    sudo apt update
    sudo apt install beekeeper-studio
    
  • pgAdmin4

    # Prerequisites: docker is installed. 
    # Check the following to get howto install docker
    
    docker run --rm --name pgadmin -p 5050:80 \
    -e '[email protected]' \
    -e 'PGADMIN_DEFAULT_PASSWORD=SuperSecret' \
    dpage/pgadmin4
    
    # Access pgAdmin with web browser http://localhost:5050 with:
    # username: [email protected]
    # password: SuperSecret
    
  • Microsoft Teams:

  • LibreOffice (Office Tools like word, exel ...)

    This step should be passed if your computer installed the necessary tools above!

  • WPS Office: If you don't like LibreOffice and want to have the office tools like MS Office then try WPS Office

  • Docker and docker-compose

    # Install docker, docker-compose
    sudo apt-get update -y && sudo apt-get install -y docker.io
    
    sudo systemctl enable docker.socket docker.service
    sudo systemctl start docker.socket docker.service
    
    sudo usermod -aG docker user
    
    # docker-compose
    sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    sudo chmod  x /usr/local/bin/docker-compose
    
  • ansible

    # Howto install ansible on Ubuntu
    python3 -m venv ansible
    
    # if Debian/Ubuntu, then:
    # sudo apt install python3.10-venv
    # python3.10 -m venv ansible
    
    # To access your project
    source ansible/bin/activate
    
    # Install ansible
    pip install ansible
    # if you want to install ansible with the specified version
    # pip install ansible==2.9.9
    
    # Add alias to .bashrc or .zshrc to activate ansible conveniently.
    echo alias source-ansible=\"source $(dirname $(which ansible))/activate\" >> ~/.bashrc #if using bash
    echo alias source-ansible=\"source $(dirname $(which ansible))/activate\" >> ~/.zshrc  #if using zsh
    
    # To exit your project
    deactivate
    
    # Try accessing your project with alias by closing and re-openning your terminal then run the following command
    source-ansible
    ansible --version
    
  • kubectl and helm

    • Install

      # Instgall kubectl
      
      curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
      chmod  x ./kubectl
      sudo mv ./kubectl /usr/local/bin/kubectl
      kubectl version
      
      # Install helm
      
      curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
      helm version
      
    • Configure:

      • Append the following into ~/.zshrc

        # Kubernetes completion script
        source <(kubectl completion zsh)
        alias k=kubectl
        complete -F __start_kubectl k
        alias kns='kubectl config set-context --current --namespace'
        alias kurrent='kubectl config view --minify -o "jsonpath={..namespace}" | xargs -I %s echo "Current Namespace: %s"'
        alias kcurrent=kurrent
        alias nodetop='k get nodes | grep Ready | cut -d" " -f1 | xargs kubectl describe node | grep -E "Name: |cpu |memory "'
        alias ktop=nodetop
        export KUBECONFIG=$HOME/.kube/config
        
        # Helm completion zsh
        source <(helm completion zsh)
        
      • Append the following into ~/.bashrc

        # Kubectl Autocomplete
        source <(kubectl completion bash)
        alias k=kubectl
        complete -F __start_kubectl k
        alias kns='kubectl config set-context --current --namespace'
        alias kurrent='kubectl config view --minify -o "jsonpath={..namespace}" | xargs -I %s echo "Current Namespace: %s"'
        alias kcurrent=kurrent
        alias nodetop='k get nodes | grep Ready | cut -d" " -f1 | xargs kubectl describe node | grep -E "Name: |cpu |memory "'
        alias ktop=nodetop
        export KUBECONFIG=$HOME/.kube/config
        
        # Helm completion bash
        source <(helm completion bash)
        
  • OBS Studio (video recording and live streaming)

    • Prerequisites for all versions:

      • xserver-xorg version 1.18.4 or newer is recommended to avoid potential performance issues with certain features in OBS, such as the fullscreen projector.

      • OpenGL 3.3 (or later) support is required to use OBS Studio on Linux. You can check what version of OpenGL is supported by your system by typing glxinfo | grep "OpenGL" on Terminal.

    • For virtual camera support, you need the v4l2loopback-dkms module installed. You can install it with the following command: sudo apt install v4l2loopback-dkms

    • Install:

      sudo add-apt-repository ppa:obsproject/obs-studio
      sudo apt update
      sudo apt install obs-studio
      

    Troubleshooting: if you face up the black screen, the fix it by disabling Wayland

    sudo vi /etc/gdm3/custom.conf
    
    # Edit: comment out the following --> save --> Logout and login again
    WaylandEnable=false
    
  • Freeplane (like mindmap, used to brainstorm)

    • Install: sudo apt install freeplane

Necessary extensions for Google Chrome

Howto add passphrase into the existing private key

# Add passphrase into the existing ssh private key
ssh-keygen -p -f ~/.ssh/id_rsa

# Check the ssh private key
ssh-keygen -y -f ~/.ssh/id_rsa

Customize PS1 and bash history

Append the following content into ~/.bashrc


# User specific aliases and functions
export PS1='\[\033[32m\]\u@\h \[\033[93m\]\w\[\033[96m\] `__git_ps1 "(%s)"`\[\033[00m\]\n\\$ '
export HISTTIMEFORMAT="%d/%m/%y %H:%M "

Customize touchpad

  • Make a script touchpad.sh

    #!/bin/bash
    # touchpad.sh
    
    if [ "$1" == "on" ] || [ "$1" == "enabled" ]; then
        gsettings set org.gnome.desktop.peripherals.touchpad send-events enabled
        echo Touchpad is enabled.
    elif [ "$1" == "off" ] || [ "$1" == "disabled" ]; then
        gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled
        echo Touchpad is disabled.
    elif [ "$1" == "disabled-on-external-mouse" ]; then
        gsettings set org.gnome.desktop.peripherals.touchpad send-events disabled-on-external-mouse
        echo Touchpad would be disabled when plug-in external mouse.
    else
        echo "touchpad.sh [OPTION]"
        echo
        echo "OPTION:"
        echo "on, enabled           : Enable touchpad"
        echo "off, disabled         : Disable touchpad"
        echo "disabled-on-external-mouse    : Touchpad would be only disabled when plug-in external mouse."
    fi
    
  • Make executy, move to /usr/local/bin/touchpad.sh and run it.

    chmod  x touchpad.sh
    sudo mv touchpad.sh /usr/local/bin/
    
    # Disable touchpad
    touchpad.sh off
    
    # Enable touchpad
    touchpad.sh on
    
    # Touchpad would be only disabled when plug-in external mouse.
    touchpad.sh disabled-on-external-mouse
    

How to expand swap partition

Supposed that installing Ubuntu with LVM and Encrypted with LUKS default. So, current swap is 1G and /dev/sda4 is encrypted. You want to add 3G to become 4G.

# Open encrypted partition, it is /dev/sda4 in this case
sudo cryptsetup luksOpen /dev/sda4 encrypted
sudo vgscan
sudo vgchange --activate y vgubuntu
sudo pvs
sudo vgs
sudo lvs

# Check and reduce /dev/mapper/vgubuntu-root
sudo e2fsck -f /dev/mapper/vgubuntu-root
sudo resize2fs /dev/mapper/vgubuntu-root  5G
# Remember 5G > 3G to safely reduce LVM Logical Volume.
sudo lvreduce -L -3G /dev/mapper/vgubuntu-root
sudo resize2fs /dev/mapper/vgubuntu-root

# Extend /dev/mapper/vgubuntu-swap_1
sudo lvextend -l  100%FREE /dev/mapper/vgubuntu-swap_1
sudo  lvs
sudo mkswap /dev/mapper/vgubuntu-swap_1

# Close encrypted partition
sudo vgchange --activate n vgubuntu
sudo cryptsetup luksClose encrypted

# Reboot and check
df -h
free -h

Reference: https://sleeplessbeastie.eu/2020/07/29/how-to-expand-swap-partition-after-system-installation/

How to install Ubuntu with full disk encryption on multiple drives

Supposed that there are 2 disks, 120 GB SSD and 1000G HDD

  • First of all, install Ubuntu using the installer on the first physical volume (sda) with LUKS encryption and LVM, and later add the second volume.

  • Then set up LUKS on your second physical volume (sdb). You can either use a passphrase:

    cryptsetup luksFormat /dev/sdb1 # Assuming that sdb1 is the partition where
                                    # you want to create the LUKS container.
                                    # You can also use your entire drive (/dev/sdb)
                                    # and have no partition table.
    
  • Open the LUKS container that you just created: cryptsetup luksOpen /dev/sdb1 sdb1_crypt Now if you check dmsetup you should see two LUKS containers: one that was created during the Ubuntu installation (let's call it vgubuntu for simplicity, though the name will be different), and one that we just created:

    dmsetup ls --target=crypt
    sda4_crypt ...
    sdb1_crypt ...
    
  • Initialize the LUKS container for use with LVM: pvcreate /dev/mapper/sdb1_crypt

  • Create a new LVM volume group inside our new LVM physical volume: vgcreate vgdata /dev/mapper/sdb1_crypt Now vgs should list it alongside the volume group create during installation:

    vgs
    VG #PV #LV #SN Attr VSize VFree 
    vgubuntu 1 1 ...
    vgdata 1 0 ...
    
  • Create a new LVM logical volume inside the group:

    lvcreate -L<size> -n var var-vg # Choose a size for your volume group. You can
                                    # specify 100%, but I always recommend using a
                                    # fraction of the available space, because you
                                    # can always grow logical volumes and
                                    # filesystems online, but shrinking it is a
                                    # pain.
                                  
    # Supposed that /dev/sdb1 is 1000G, but you should increase gradually. Let start creating 100G first.
    
    lvcreate -L 100G -n home vgdata
    
  • And lvs should reflect our changes:

    LV   VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
    root vgubuntu -wi-ao---- ...
    home vgdata   -wi-a----- ...
    
  • Initialize an ext4 filesystem on that logical volume (or whatever filesystem type you prefer): mkfs.ext4 /dev/vgdata/home Confirm that the filesystem was created with lsblk.

  • Almost there! Now we need to tell Ubuntu to open mount the LUKS container and filesystem automatically on boot. In order to do that:

    • Add this line to /etc/crypttab: sdb1_crypt UUID=<uuid of /dev/sdb1> none luks,discard,keyscript=decrypt_keyctl You can get the UUID with lsblk -f. The keyscript=decrypt_keyctl is there so that you don't have to enter the same phassphrase twice on boot (in case your two LUKS containers are using the same phassprase).

    • Add this line to /etc/fstab: /dev/vgdata/home /home ext4 defaults 0 1

  • Migrate /home/user to new disk:

    cd /tmp
    sudo su
    mkdir home
    
    # Mount new disk to /tmp/home
    mount /dev/vgdata/home home
    
    # Migrate /home/user to /tmp/home
    mv /home/user home
    
    # Umount /tmp/home
    umount /tmp/home
    
    # Mount /dev/vgdata/home to /home
    mount -a
    
    # Remove /tmp/home
    rm -rf /tmp/home
    

    Now, let reboot and check again df -Th

How to install virtual environment for the Python project

python3 -m venv <your-python-project>

# if Debian/Ubuntu, then:
# sudo apt install python3.10-venv
# python3.10 -m venv <your-python-project>

# To access your project
source /path-to-your-python-project/bin/activate

# To exit your project
deactivate

Howto encrypt file with ansible-vault

  • Prerequisites: ansible is installed. Check above to get howto install ansible if not existing ansible in your computer.
  • Run the following commands to encrypt your data
# Check ansible-vault exsiting or not
ansible-vault --version

# Create hello.txt
echo Hello > hello.txt

# Encrypt hello.txt
ansible-vault encrypt hello.txt

# Show hello.txt encrypted with cat
cat hello.txt

# Open content of hello.txt
ansible-vault view hello.txt

# Edit content of hello.txt
ansible-vault edit hello.txt

# Reset password
ansible-vault rekey hello.txt

# Decrypt hello.txt persistantly
ansible-vault decrypt hello.txt

# Check hello.txt with cat
cat hello.txt

# Encrypt string
ansible-vault encrypt_string hello

If your data is very important, you should set complex password. Go to https://www.browserling.com/tools/random-string to generate password and store it into password manager (like Keepass or LastPass)

Howto encrypt data with VeraCrypt

Howto encrypt file with GPG

Reference: https://youtu.be/ZSa-d_9O5DA

Howto show password of the existing wifi and share it

nmcli device wifi show-password

Tip: To make CLI easily, append alias show-wifi-password='nmcli device wifi show-password' into ~/.zshrc or ~/.bashrc. And only type show-wifi-password in your terminal to get wifi password.

Troubleshooting

Can connect L2TP VPN on Ubuntu 21.10 or before but cannot on Ubuntu 22.04

sudo apt remove xl2tpd
curl -LO http://archive.ubuntu.com/ubuntu/pool/universe/x/xl2tpd/xl2tpd_1.3.12-1.1_amd64.deb
sudo apt install ./xl2tpd_1.3.12-1.1_amd64.deb
sudo apt-mark hold xl2tpd

Error when running AppImage on Ubuntu 22.04 LTS

dlopen(): error loading libfuse.so.2

AppImages require FUSE to run. 
You might still be able to extract the contents of this AppImage 
if you run it with the --appimage-extract option. 
See https://github.com/AppImage/AppImageKit/wiki/FUSE 
for more information

Install libfuse2 as a workaround: sudo apt install libfuse2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment