Category: Ubuntu

  • How to Set Up Software RAID 1

    How to Set Up Software RAID 1

    mdadm is used to manage software RAID. Install mdadm package with

    apt install mdadm

    To set up RAID 1 (mirror), you need 2 drives or partitions of the same size

    Setup Partition

    Create a partition with the following commands on both the drives used for RAID 1.

    parted /dev/sdX mklabel gpt
    parted /dev/sdX mkpart primary ext4 0% 100%
    parted /dev/sdX set 1 raid on
    parted /dev/sdX print

    Replace /dev/sdX with device name of the drive you will be using for the RAID.

    Create RAID 1

    To create a RAID 1 mirror, use the following command

    mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

    In the above command, replace /dev/md0 with the device name of the RAID array you need. If your system already has a raid array with this name, use another name, for example: /dev/md1.

    /dev/sdb1 and /dev/sdc1 = replace these with the device name of the drives you will be using for the RAID 1

    To see the raid status, use the command

    cat /proc/mdstat

    To find details, use the command:

    mdadm --detail /dev/md0

    Formatting the RAID drive

    Once you created a RAID array, you need to format it with the command

    mkfs.ext4 /dev/mdX

    /dev/mdX = replace it with the actual device name used while creating the RAID array.

    mkfs.ext4 will format the drive with EXT4 file system. To use other supported file systems replace mkfs.ext4 with other available file system types. For example mkfs.xfs

    Mount the Drive

    To mount the drive, use the following commands

    mkdir /backup
    mount /dev/md0 /backup

    This will mount /dev/md0 as /backup. Change the mount point and device name as needed.

    Auto Assemble RAID on the boot

    To ensure the array is reassembled automatically at boot, update the mdadm configuration file:

    mdadm --detail --scan

    Add entry for the RAID array in file /etc/mdadm/mdadm.conf

    Update the initramfs:

    update-initramfs -u

    Make the Drive auto-mount

    To automount the drive on boot, edit /etc/fstab

    vi /etc/fstab

    Add the following line

    /dev/md0 /backup ext4 defaults 0 2

    Verify it is mounting properly with the command

    mount -a

    Back to RAID

  • How to extract .deb file in Ubuntu?

    You can use dpkg-deb command to extract the contents of a .deb file in the Ubuntu or Debian system.

    dpkg-deb -x file.deb folder

    Example:

    dpkg-deb -x anydesk_6.3.2-1_amd64.deb anydesk

    Here we extract the content of the file anydesk_6.3.2-1_amd64.deb to the directory “anydesk’.

    Back to dpkg

  • Keeping Ubuntu Secure with Unattended-Upgrades

    Keeping Ubuntu Secure with Unattended-Upgrades

    Keeping your operating system up-to-date is crucial for maintaining security and stability. For Ubuntu/Debian users, the unattended-upgrades package offers a solution to automate this essential task

    Unattended-upgrades is a package for Ubuntu and other Debian-based Linux distributions that automates the process of keeping your system up-to-date. Its primary purpose is to automatically install security updates without requiring manual intervention from the system administrator.

    To install unattended-upgrades, run

    sudo apt install unattended-upgrades

    To configure, edit file

    sudo vi /etc/apt/apt.conf.d/50unattended-upgrades

    Uncomment the line

    //      "${distro_id}:${distro_codename}-updates";

    To make it look like

    Unattended-Upgrade::Allowed-Origins {
            "${distro_id}:${distro_codename}";
            "${distro_id}:${distro_codename}-security";
            // Extended Security Maintenance; doesn't necessarily exist for
            // every release and this system may not have it installed, but if
            // available, the policy for updates is such that unattended-upgrades
            // should also install from here by default.
            "${distro_id}ESMApps:${distro_codename}-apps-security";
            "${distro_id}ESM:${distro_codename}-infra-security";
            "${distro_id}:${distro_codename}-updates";
    //      "${distro_id}:${distro_codename}-proposed";
    //      "${distro_id}:${distro_codename}-backports";
    };

    Uncomment the following line, this helps if you need a quick reboot while an upgrade is running, good for desktops/workstations.

    //Unattended-Upgrade::MinimalSteps "true";

    Another configuration file is /etc/apt/apt.conf.d/20auto-upgrades, default values are fine for this.

    sudo vi /etc/apt/apt.conf.d/20auto-upgrades

    To debug unattended upgrade, run

    sudo unattended-upgrade --dry-run --debug

    Back to Ubuntu

  • DHCP

    DHCP

    DHCP, or Dynamic Host Configuration Protocol, is a network management protocol that automates the process of assigning IP addresses and other network configuration parameters to devices on a network. This crucial technology plays a vital role in modern network infrastructure, from small home networks to large enterprise environments.

    In essence, DHCP eliminates the need for manual IP address configuration, making it easier for devices to join and communicate on a network. It dynamically assigns IP addresses, subnet masks, default gateways, and other network settings to client devices, streamlining network administration and reducing the potential for configuration errors.

    dhclient

    On Ubuntu systems, dhclient works in conjunction with NetworkManager for easier network configuration management.

    Configuration file located at /etc/dhcp/dhclient.conf

    To view IP lease info, run “dhclient -v” command

    root@sok-mysql-fix:~# dhclient -v
    Internet Systems Consortium DHCP Client 4.4.1
    Copyright 2004-2018 Internet Systems Consortium.
    All rights reserved.
    For info, please visit https://www.isc.org/software/dhcp/
    
    Listening on LPF/eth0/00:16:3e:bf:97:d0
    Sending on   LPF/eth0/00:16:3e:bf:97:d0
    Sending on   Socket/fallback
    DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3 (xid=0xc266324)
    DHCPOFFER of 10.18.211.81 from 10.18.211.1
    DHCPREQUEST for 10.18.211.81 on eth0 to 255.255.255.255 port 67 (xid=0x2463260c)
    DHCPACK of 10.18.211.81 from 10.18.211.1 (xid=0xc266324)
    RTNETLINK answers: File exists
    bound to 10.18.211.81 -- renewal in 1759 seconds.
    root@sok-mysql-fix:~# 

    Or check the content of file /var/lib/dhcp/dhclient.leases

    root@sok-mysql-fix:~# cat /var/lib/dhcp/dhclient.leases
    lease {
      interface "eth0";
      fixed-address 10.18.211.81;
      option subnet-mask 255.255.255.0;
      option routers 10.18.211.1;
      option dhcp-lease-time 3600;
      option dhcp-message-type 5;
      option domain-name-servers 10.18.211.1;
      option dhcp-server-identifier 10.18.211.1;
      option dhcp-renewal-time 1800;
      option broadcast-address 10.18.211.255;
      option dhcp-rebinding-time 3150;
      option host-name "sok-mysql-fix";
      option domain-name "lxd";
      renew 0 2024/07/07 17:47:55;
      rebind 0 2024/07/07 18:11:06;
      expire 0 2024/07/07 18:18:36;
    }
    root@sok-mysql-fix:~# 

    To manually request a lease

     dhclient <interface>

    To release an IP address

     dhclient -r <interface>
  • How to Disable apt Ubuntu Pro Advertisement

    How to Disable apt Ubuntu Pro Advertisement

    On running “apt upgrade” command on Ubuntu 20.04 and newer, Ubuntu shows an advertisement about Ubuntu Pro subscription.

    apt Ubuntu Pro advertisement

    To disable the Ubuntu Pro advertisement that appears when updating apt, run

    sudo mv /etc/apt/apt.conf.d/20apt-esm-hook.conf /etc/apt/apt.conf.d/20apt-esm-hook.conf.bak
    sudo touch /etc/apt/apt.conf.d/20apt-esm-hook.conf

    After running these commands, running “apt upgrade”, you won’t get the Ubuntu Pro advertisement.

    apt ubuntu pro advertisements disabled

    Back to Ubuntu

  • Install MATE desktop with xrdp on Ubuntu Server

    Install MATE desktop with xrdp on Ubuntu Server

    Login to ubuntu server using SSH and run the following command to install MATE desktop environment

    apt install ubuntu-mate-desktop
    

    Create a normal user. We will use this user to login to XRDP desktop.

    useradd -m -s /bin/bash desktop
    

    You can change user name “desktop” to any other username you need. Make the user super user

    usermod -aG sudo desktop
    

    Switch to desktop user

    su - desktop
    

    Create .xsession file

    echo "mate-session" > ~/.xsession
    

    Exit back to user root

    exit
    

    Install xrdp package

    apt install xrdp
    

    Create file

    vi /etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla
    

    with following content

    [Allow Colord all Users]
    Identity=unix-user:*
    Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile
    ResultAny=no
    ResultInactive=no
    ResultActive=yes
    

    Restart xrdp

    systemctl restart xrdp
    

    Now you should be able to connect to remote ubuntu server using RDP.

    back to xrdp

  • How to change varnish port in Ubuntu

    How to change varnish port in Ubuntu

    To change the varnish port, run the command

    systemctl edit varnish
    

    It opens an editor, in the editor, paste the following

    [Service]
    ExecStart=
    ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
    

    This will change varnish listening port to 80. If you need to change to another port, change “-a :80” to whatever port you want to use. Save and exit the editot.

    Now resart varnish

    systemctl restart varnish
    

    Back to Varnish

  • rsyslog Unsafe symlinks encountered in /var/log, refusing

    rsyslog Unsafe symlinks encountered in /var/log, refusing

    When updating packages on an Ubuntu server, I got the error “Unsafe symlinks encountered in /var/log, refusing.”.

    root@ip-172-31-45-33:/var# apt upgrade -y
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    Calculating upgrade... Done
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    1 not fully installed or removed.
    After this operation, 0 B of additional disk space will be used.
    Setting up rsyslog (8.32.0-1ubuntu4.2) ...
    The user `syslog' is already a member of `adm'.
    Unsafe symlinks encountered in /var/log, refusing.
    dpkg: error processing package rsyslog (--configure):
     installed rsyslog package post-installation script subprocess returned error exit status 1
    Errors were encountered while processing:
     rsyslog
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    root@ip-172-31-45-33:/var#
    

    This is due to wrong file ownership for /var/log folder.

    I found the directory “/var” was owned by user www-data

    root@ip-172-31-45-33:/var# ls -l / | grep var
    drwxr-xr-x  15 www-data www-data  4096 Sep  1  2021 var
    root@ip-172-31-45-33:/var#
    

    To fix the error I changed ownership of /var directory to root user.

    chown root:root /var
    

    IMPORTANT: Do not use chown -R as the /var folder contains files owned by different users, if you change all file/folder ownership to root, it will mess up the system. For example /var/log/mysql need to be owned by user “mysql”, if you change it to the user “root”, MySQL will fail to start.

    You may also need to check ownership of folder /var/log and files inside. You can compare it with another Ubuntu server to make sure directory/file ownerships are correct.

    Back to apt

  • apt error doesn’t support architecture ‘i386’

    apt error doesn’t support architecture ‘i386’

    On an Ubuntu server, when running “apt update” command, I got the following error message

    root@s196379:~# apt update
    Hit:1 http://mirror.fcix.net/ubuntu focal InRelease
    Hit:2 http://mirror.fcix.net/ubuntu focal-updates InRelease                
    Hit:3 http://security.ubuntu.com/ubuntu focal-security InRelease           
    Hit:4 https://mirror.rackspace.com/mariadb/repo/10.5/ubuntu focal InRelease
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    All packages are up to date.
    N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://mirror.rackspace.com/mariadb/repo/10.5/ubuntu focal InRelease' doesn't support architecture 'i386'
    root@s196379:~# 
    

    This error is because the repository do not support i386. To fix the error, edit the file

    vi /etc/apt/sources.list
    

    Find

    deb https://mirror.rackspace.com/mariadb/repo/10.5/ubuntu focal main
    

    Replace with

    Find

    deb [arch=amd64] https://mirror.rackspace.com/mariadb/repo/10.5/ubuntu focal main
    

    Solution 2: Remove i386 support

    Check your architecture

    dpkg --print-architecture 
    

    If you are using 64 bit OS, you will see amd64.

    Check if multiarch is enabled

    dpkg --print-foreign-architectures
    

    If you get “i386”, you have multiarch enabled.

    If you don’t have any i386 applications running, you can remove i386 support with

    dpkg --remove-architecture i386
    

    If you want to enable i386 support, you can run

    dpkg --add-architecture i386
    

    Back to apt

  • How to install dropbear SSH server

    How to install dropbear SSH server

    Dropbear is a Lightweight SSH server. You can use it as openssh server alternative. Dropbear is particularly useful for embedded type Linux systems, such as wireless routers.

    I have used this when I have a problem with openssh server, after an apt upgrade, openssh server stopped working. I installed dropbear and made it run on an alternative port, so I can debug openssh server problem without worrying about disconnecting from the server.

    To install dropbear on Ubuntu, run

    apt install dropbear
    

    Dropbear SSH configuration

    Let’s change SSH port to non default port by editing the file

    vi /etc/default/dropbear
    

    Find

    DROPBEAR_PORT=22
    

    Replace 22 with your custom port, I will use port 2222

    DROPBEAR_PORT=2222
    

    Find

    NO_START=1
    

    Replace with

    NO_START=0
    

    That completes the basic dropbear ssh configuration.

    Using Dropbear SSH Server

    Let’s restart dropbear service with

    systemctl restart dropbear
    

    Verify dropbear is working with command

    ss -lntp | grep dropbear
    

    dropbear ssh server

    As you can see dropbear is listening on port 2222. You will be able to login to the server using the custom port

    ssh -p 2222 user@IP_ADDR
    

    See SSH

  • Reset nextcloud admin password (snap install)

    Reset nextcloud admin password (snap install)

    To reset the admin password of a nextcloud installed using the snap package, run

    sudo nextcloud.occ user:resetpassword USER_NAME_HERE
    

    It will ask for the new password, once you enter the password and confirmed it your nextcloud admin password will be changed.

  • How to install .NET SDK in Ubuntu 20.04

    How to install .NET SDK in Ubuntu 20.04

    To install .NET on ubuntu 20.04, run the following commands

    wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
    sudo dpkg -i packages-microsoft-prod.deb
    rm packages-microsoft-prod.deb
    sudo apt-get update
    sudo apt-get install -y apt-transport-https
    sudo apt-get update
    

    To find all versions of .NET SDK available, run

    apt-cache search dotnet-sdk
    

    dotnet sdk ubuntu

    To install .NET SDK version 6, run

    apt install dotnet-sdk-6.0
    

    For .NET SDK 5, run

    apt install dotnet-sdk-5.0
    

    For .NET SDK 3.1, run

    apt install dotnet-sdk-3.1
    

    For .NET SDK 2.1, run

    apt install dotnet-sdk-2.1
    

    Back to dotnet