Linux Notes

1. DNF

Only for RHEL
  • Perform the following steps to install the DNF package manager which is the successor to the yum package manager:

1.1. Install the DNF Package Manager

  1. Install the DNF package manager (not required on RedHat 8/CentOS 8)

    sudo yum install -y dnf
  2. Install EPEL repository

    sudo dnf install -y epel-release

    If the previous command failed, try this one:

    sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
  3. Make the DNF cache

    sudo dnf makecache

1.2. Update the DNF Package Manager

  1. Add the EPEL Repo:

    sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
  2. Add the Remi Repo:

    sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
  3. Install dnf-utils Package:

    sudo dnf install dnf-utils
  4. Update Software packages:

    sudo dnf update
    This may take a while to complete…​

2. Install the Latest Updates

  1. Run the following to view the available updates

    apt list --upgradable
  2. Run the following to update the system

    sudo apt -y dist-upgrade

3. Enable root account

  1. Execute the following:

    sudo passwd root
    sudo passwd -u root
  2. Update this file:

    1. Edit this file

      sudo vi /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf
    2. Append this text at the end:

      greeter-show-manual-login = true
  3. Update this file too:

    1. Edit this file

      sudo vi /etc/ssh/sshd_config
    2. Append this test at the end:

      PermitRootLogin yes
    3. Restart the ssh server

      sudo systemctl restart sshd
  4. Reboot!

    sudo shutdown -r now

4. List IP Addresses

sudo nmcli device show | grep IP4.ADDRESS | grep 192.168.1

5. List Ports

sudo ss -ltpn | cat

6. Create an Archive via Tar

  • Create

    tar -czvf archive.tgz source
  • Extract

    tar -xzvf archive.tgz

7. WEB

  • default pages are here:

    /var/www/html

8. Firewall

8.1. Ports

  • Open a Port

    Expand for Fedora instructions
    1. Check status

      sudo firewall-cmd --state
    2. Open Port

      sudo firewall-cmd --add-port=3389/tcp --permanent
    3. Reload FW Rules

      sudo firewall-cmd --reload
    4. Show rules

      sudo firewall-cmd --list-all
    5. Remove a port

      1. Remove

        sudo firewall-cmd --remove-port=3389/tcp
      2. Make persistent

        sudo firewall-cmd --runtime-to-permanent
    Expand for Ubuntu instructions
    1. Enable FW

      sudo systemctl enable ufw --now
    2. Open Port 3389

      sudo ufw allow 3389/tcp
    3. Reload FW rules

      sudo ufw reload

8.2. Stop/Start Firewall

  1. Stop

    sudo systemctl stop firewalld
  2. Stop

    sudo systemctl start firewalld

8.3. Check Port Access

  1. Using ncat

    nc -v remotehost 11434

9. GPU

  1. Status

    sudo gpustat -c -p

10. IPMI

  1. To discover IPMI devices

    command
    ipmiutil discover
    result
    discover ver 1.11
    Discovering IPMI Devices:
    01| response from |  192.168.0.1      |
    02| response from |  192.168.0.2      |

11. Shells

11.1. zsh

11.1.1. Install

  1. Install

    sudo apt-get update && sudo apt -y install zsh
  2. Set as default shell

    chsh -s /usr/bin/zsh

11.1.2. Customize via Oh My Zsh

  1. Install Oh My Zsh

    sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
  2. Change Theme

    1. Edit conf

      vi .zshrc
    2. Change the value of the ZSH_THEME

      Example
      ZSH_THEME="agnoster"

12. GIT

12.1. Install on RHEL:

sudo dnf install git-all

12.2. Install on Ubuntu:

sudo apt -y install git-all

13. Visual Studio Code

13.1. Install

Refer to the VSC doc.

14. .Net 6.x.x

Expand for Ubuntu
Must have version 22.04+ of Ubuntu
  • Reference doc is here.

  • Install

    sudo apt update && sudo apt install dotnet6

15. Docker

15.1. RHEL

  • Emulate Docker CLI using podman.

    • RedHat uses podman as its command line interface to manage the container ecosystem. So, instead of using the docker cli command you would now use podman in its place.

    • However most container related documentation will reference the docker cli command so in order to simplify things and use docker or podman on RedHat, do the following:

      1. Become root

        su
      2. Try to run docker which won’t be found but should offer to install the podman-docker package:

        docker
        
        bash: docker: command not found...
        Install package 'podman-docker' to provide command 'docker'? [N/y] y
      3. Continue with the install…​

  • Emulate docker-compose via podman-compose.

    • The above installation will only give you the Docker cli but if you need docker-compose you’ll have to use podman-compose, however this is not available at default.

    • Install

      1. Become root

        su
      2. Try to run podman-compose which won’t be found but should offer to install the podman-compose package:

        podman-compose
        bash: podman-compose: command not found...
        Install package 'podman-compose' to provide command 'podman-compose'? [N/y] y
      3. Continue with the install…​

    • Now you can use podman-compose as a direct replacement for docker-compose.

16. Temporarily Mount Windows Share

This mount is temporary and will be lost upon system reboot.

  1. First install the cifs-utils package (this only needs to be done once):

    RHEL
    sudo dnf install cifs-utils
    Ubuntu
    sudo apt -y install cifs-utils
  2. Make a mount point

    sudo mkdir -p /mnt/Norco/Stuff
  3. Mount the windows share:

    sudo mount -t cifs -o username=<user@domain> //norco/Stuff /mnt/Norco/Stuff (1)
    Password for mattosd@dhante.local@//norco/Stuff:  **********
    $
    1 supply credentials that have access to the share.
  4. Confirm mount exists

    Command
    df -h
    Sample Output
    Filesystem             Size  Used Avail Use% Mounted on
    devtmpfs               841M     0  841M   0% /dev
    tmpfs                  870M     0  870M   0% /dev/shm
    tmpfs                  870M  9.1M  861M   2% /run
    tmpfs                  870M     0  870M   0% /sys/fs/cgroup
    /dev/mapper/rhel-root   17G  4.7G   13G  28% /
    /dev/sda1             1014M  242M  773M  24% /boot
    tmpfs                  174M   12K  174M   1% /run/user/42
    tmpfs                  174M  4.0K  174M   1% /run/user/1000
    //norco/Stuff          700G  520G  181G  75% /mnt/Norco/Stuff (1)
    [dhante@v-RedHat00 ~]$
    1 This is our mounted directory

17. Permanently Mount a Windows/Linux File Share

A shared folder must first exist on the remote Windows/Linux system before trying to mount that existing share locally.
  1. First (this only needs to be done once)

    Ubuntu
    sudo add-apt-repository universe
  2. Next install the cifs-utils package (this only needs to be done once):

    Ubuntu
    sudo apt install cifs-utils
    Fedora
    sudo dnf install cifs-utils
  3. Make a mount point

    Example
    sudo mkdir -p /mnt/p-ubuntu-norco/Backups
  4. Create a .mnt-cred file in the user’s home directory

    The file name is not important but must be the same as the name entered into the /etc/fstab file.

    1. Edit the file

      Example
      vi /home/mattosd/.mnt-cred
    2. Add credential related contents:

      These are credentials for the remote system.
      Example
      username=mattosd
      password=s3cret
  5. Add an entry to the /etc/fstab file:

    1. Edit

      sudo vi /etc/fstab
    2. Add one of the following:

      1. Windows file share:

        //p-winserv-norco/Backups           /mnt/p-ubuntu-norco/Backups                cifs credentials=/home/mattosd/.mnt-cred,_netdev      0 0 (1)
        1 The existing shared folder on the remote Norco server is named Backups.
        This is a long single line.
      2. Linux file share:

        //p-ubuntu-norco/Backups  /mnt/p-ubuntu-norco/Backups  cifs  guest,iocharset=utf8,file_mode=0777,dir_mode=0777,credentials=/home/mattosd/.mnt-cred (1)
        1 The existing shared folder on the remote p-ubuntu-norco server is named Backups.
        This is a long single line.
  6. Now mount:

    Ubuntu
    sudo mount -a
    Fedora
    sudo mount -a
    sudo systemctl daemon-reload

18. Log Files

  • List of log files can be found via this command:

    cat /etc/rsyslog.conf

19. Misc Commands

19.1. Reset an Ethernet Interface or Wi-Fi adapter

  1. Stop the Interface

    sudo ip link set dev <interface> stop
  2. Start the Interface

    sudo ip link set dev <interface> start

19.2. Find DHCP Server

  1. Use the nmap command

    sudo nmap --script broadcast-dhcp-discover
  2. Use the dhclient command

    sudo dhclient -d -nw eno1   (1)
    1 replace eno1 with the actual interface. use ifconfig to find

19.3. Check DNS entry

If the nslookup command is not found, install via:

sudo apt -y install dnsmasq

19.4. Check External Port

  • To confirm able to connect to an external port

    1. Use the netcat command

      Example to check google.com
      nc -v google.com 443

      If the nc command is not found, install via:

      sudo apt install -y netcat

19.5. Flush DNS

  • Exec the following

    sudo killall -USR2 systemd-resolved

19.6. Disk Space

  • Use df -h to display space used by file systems:

    [root@v-RedHat-MidPoint /]# df -h
    Filesystem                                 Size  Used Avail Use% Mounted on
    devtmpfs                                   1.4G     0  1.4G   0% /dev
    tmpfs                                      1.4G     0  1.4G   0% /dev/shm
    tmpfs                                      1.4G  155M  1.2G  12% /run
    tmpfs                                      1.4G     0  1.4G   0% /sys/fs/cgroup
    /dev/mapper/rhel_v--redhat--midpoint-root   17G   17G   20K 100% / (1)
    /dev/sda1                                 1014M  346M  669M  35% /boot
    tmpfs                                      275M   16K  275M   1% /run/user/42
    tmpfs                                      275M  4.0K  275M   1% /run/user/1000
    1 Here we can see the root file system is full with 17GB of data
  • Use du -h -s * to display space used by folders:

    [root@v-RedHat-MidPoint /]# du -h -s *
    0       bin
    306M    boot
    0       dev
    33M     etc
    360M    home
    0       lib
    0       lib64
    0       media
    0       mnt
    12G     opt (1)
    0       proc
    40K     root
    155M    run
    0       sbin
    0       srv
    0       sys
    36K     tmp
    4.4G    usr
    562M    var
    1 /opt is using 12G
  • Use du -cha --max-depth=1 /var | grep -E "M|G"

19.7. Watch GPU Performance

  1. Run

    watch -n 0.5 nvidia-smi

19.8. Reboot

  • To reboot immmediately:

    sudo shutdown -r now
  • Or:

    sudo systemctl reboot

19.9. SELinux (Security Enhanced Linux)

  • Temporarily disable SELinux and set it to permissive mode:

    Only valid for the current session.
    sudo setenforce 0

20. Troubleshooting

20.1. Temporary failure in name resolution

  1. Try the following

    sudo systemctl restart systemd-resolved.service

    This won’t work if using Pi-Hole as the DNS server

  2. Also check the following