Category: Linux

  • Determine the Default Time Zone on Linux

    Determine the Default Time Zone on Linux

    To find the timezone of your Linux server, you can use the command

    date +"%Z %z"
    Linux Timezone using date

    You can also use the command

    timedatectl
    timedatectl Timezone

    To find a list of all available timezones, use the command

    timedatectl list-timezones

    Timezone is stored at

    /etc/timezone

    See Time

  • How to remove a package without removing dependencies in RHEL

    How to remove a package without removing dependencies in RHEL

    When you remove a package with the command

    yum remove PKG_NAME
    

    yum will remove all other packages that are dependent on the package you are removing.

    To remove a package without removing its dependency on Red Hat Linux or RHEL based distributions like CentOS, AlmaLinux, Rocky Linux or Oracle Linux, you can run the command

    rpm -e --nodeps PKG_NAME
    

    If you want to keep files, just remove the entry, use

    rpm -e --nodeps --justdb PKG_NAME
    

    Back to rpm

  • 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.

  • growpart: command not found

    growpart: command not found

    When trying to resize a disk on Debian 8, I got the following error

    root@rescue:~# growpart /dev/nvme0n1 1
    -bash: growpart: command not found
    root@rescue:~#

    Fixed by installing cloud-utils package

    apt install cloud-utils

    On newer versions of Debian/Ubuntu, you need to install cloud-guest-utils package.

    apt install cloud-guest-utils

    On RHEL/AlmaLinux/CentOS, growpart command is provided by the package cloud-utils-growpart to install, run the command:

    yum install cloud-utils-growpart
  • 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

  • How to reset CyberPanel MySQL root Password

    How to reset CyberPanel MySQL root Password

    CyberPanel is a free hosting control panel. To find MySQL root password on CyberPanel server, run

    cat /etc/cyberpanel/mysqlPassword
    

    If you want to change MySQL root password on a CyberPanel server, reset MySQL root password as per

    Reset MySQL root Password

    Once the MySQL root password is reset, you need to modify the file

    /usr/local/CyberCP/CyberCP/settings.py
    

    Add the new password for user root and cyberpanel

    CyberPanel mysql root password

    Restart CyberPanel service with command

    systemctl restart lscpd
    

    See CyberPanel

  • CentOS 8 Error: Failed to download metadata for repo ‘appstream’

    CentOS 8 Error: Failed to download metadata for repo ‘appstream’

    When updating packages on CentOS 8 server, I got the following error

    [root@instance-20220409-2340 ~]# dnf update
    Failed loading plugin "osmsplugin": No module named 'librepo'
    CentOS Linux 8 - AppStream                                                                                                                                                  51  B/s |  38  B     00:00    
    Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist
    [root@instance-20220409-2340 ~]# 
    

    This is because CentOS 8 have reached its End of life.

    To fix the dnf error, you can change the repository baseurl to vault.centos.org

    sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
    sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*
    

    You may need to convert CentOS 8 to one of the supported Linux distributions.

    Convert CentOS 8 to CentOS 8 Stream

    To convert CentOS 8 to CentOS 8 Stream, run

    dnf --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos
    dnf distro-sync
    

    Convert CentOS 8 to AlmaLinux 8

    AlmaLinux is RHEL 8 based (same as CentOS 8) Linux operating system. They provide easy way to convert CentOS 8 server to AlmaLinux.

    How to Migrate CentOS 8 to AlmaLinux

    Convert CentOS 8 to Rocky Linux 8

    Rocky Linux is an open-source enterprise operating system designed to be 100% bug-for-bug compatible with Red Hat Enterprise Linux.

    How to Convert CentOS 8 to Rocky Linux

    Convert CentOS 8 to Oracle Linux 8

    Oracle Linux 8 is free and open source, based on RHEL 8

    https://docs.oracle.com/en/learn/switch_centos8_linux8/index.html

    Convert CentOS 8 to RHEL 8

    RedHat provides Convert2RHEL script to convert CentOS 8 to RHEL 8. RHEL is now FREE for production up to 16 servers.

    https://www.redhat.com/en/technologies/linux-platforms/enterprise-linux/migration-process/convert2rhel-how-to-convert-from-centos-linux-to-red-hat-enterprise-linux

    See CentOS 8

  • How to install NVIDIA CUDA on Debian 10

    How to install NVIDIA CUDA on Debian 10

    CUDA® is a parallel computing platform and programming model developed by NVIDIA for general computing on graphical processing units (GPUs). With CUDA, developers are able to dramatically speed up computing applications by harnessing the power of GPUs.

    We will install NVIDIA CUDA on a Debian 10 server. Run the following commands as user root. If you are logged in with sudo user, you can run the command “sudo su” to become user root.

    Add NVIDIA repository

    apt install software-properties-common -y
    add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/debian10/x86_64/ /"
    apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/debian10/x86_64/7fa2af80.pub
    

    Enable the contrib repository

    add-apt-repository contrib
    

    Update the apt cache

    apt-get --allow-releaseinfo-change update
    

    Install cuda

    apt-get -y install cuda
    

    To find Nvidia driver version, you can run the command cat /proc/driver/nvidia/version

    root@sok-1:~# cat /proc/driver/nvidia/version
    NVRM version: NVIDIA UNIX x86_64 Kernel Module  470.103.01  Thu Jan  6 12:10:04 UTC 2022
    GCC version:  gcc version 8.3.0 (Debian 8.3.0-6) 
    root@sok-1:~#
    

    cuda installed in folder /usr/local/cuda-11.4/bin/, to find version, run

    root@sok-1:~# /usr/local/cuda-11.4/bin/nvcc -V
    nvcc: NVIDIA (R) Cuda compiler driver
    Copyright (c) 2005-2021 NVIDIA Corporation
    Built on Mon_Oct_11_21:27:02_PDT_2021
    Cuda compilation tools, release 11.4, V11.4.152
    Build cuda_11.4.r11.4/compiler.30521435_0
    root@sok-1:~# 
    

    Add the folder to PATH, edit the file

    vi ~/.bashrc
    

    Add following

    if [ -d "/usr/local/cuda-11.4/bin/" ]; then
        export PATH=/usr/local/cuda-11.4/bin${PATH:+:${PATH}}
        export LD_LIBRARY_PATH=/usr/local/cuda-11.4/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    fi
    

    Save and exit the file. Reload .bashrc with

    source ~/.bashrc
    

    You can find more info on NVIDIA driver with the command

    nvidia-smi
    

    NVIDIA CUDA command line

  • ipset

    Allow CloudFlare IP addresses with ipset

    To list

    ipset list
    ipset list -n -t
    ipset list -n
    ipset list -t
    
  • Allow CloudFlare IP addresses with ipset

    Allow CloudFlare IP addresses with ipset

    IP sets are a framework inside the Linux kernel, which can be administered by the ipset utility. Depending on the type, an IP set may store IP addresses, networks, (TCP/UDP) port numbers, MAC addresses, interface names or combinations of them in a way, which ensures lightning speed when matching an entry against a set.

    To allow all Cloudflare IP addresses, you can use

    apt install ipset
    ipset create cf4 hash:net
    for x in $(curl https://www.cloudflare.com/ips-v4); do ipset add cf4 $x; done
    iptables -A INPUT -m set –match-set cf4 src -p tcp -m multiport –dports http,https -j ACCEPT
    
  • r1soft get-module segmentation fault

    r1soft get-module segmentation fault

    When installing r1soft kernel module, I got the following error

    root@localhost:~# serverbackup-setup --get-module
    Failed to find headers at `/lib/modules/4.19.0-20-amd64/build`.
    Get module failed.
    Falling back to old get-module ...
    signal: segmentation fault
    root@localhost:~# 
    

    This was on a Debian server with 4.19.0-20-amd64 kernel.

    root@localhost:~# uname -a
    Linux localhost 4.19.0-20-amd64 #1 SMP Debian 4.19.235-1 (2022-03-17) x86_64 GNU/Linux
    root@localhost:~# uname -r
    4.19.0-20-amd64
    root@localhost:~#
    

    To fix the error message, install linux-headers package.

    apt install linux-headers-4.19.0-20-amd64
    

    See r1soft backup