Author: admin

  • Enable HTTP Strict Transport Security (HSTS) on Apache HTTPD

    This guide explains how to enable HTTP Strict Transport Security (HSTS) on Apache HTTPD.

    • The first step is to verify that Apache HTTPD headers module is enabled. Check the following text in /etc/httpd/conf.modules.d/00-base.conf or /etc/httpd/conf/httpd.conf.

    LoadModule headers_module modules/mod_headers.so

    • Add the following text in /etc/httpd/conf.d/ssl.conf to <VirtualHost *:443> virtual host or for each SSL enabled virtual host.

    Header always set Strict-Transport-Security "max-age=58099000; includeSubDomains"

    • The final step is to redirect traffic from the non-encrypted virtual host to HTTPS as follows:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    </IfModule>

    • Restart HTTPD service as follows:

    systemctl restart httpd

  • YUM Command Cheat Sheet

    YUM command is used for installing, querying, deleting, and managing CentOS/AlmaLinux packages in local and remote repositories. Use the following YUM Cheat Sheet as a quick reference for commands and options.

    [ninja_tables id=”6707″]

  • How to restrict find command within current filesystem?

    Use the below command to find files above 200M in / or in /opt. You can specify certain file system on the command line replacing / or /opt/

    # find / -xdev -size +200M

    # find /opt -xdev -size +200M

  • How to find files with specific permissions?

    You may need to find files with specific permissions in a Linux server for audit and security reasons. You can use the Linux find command to achieve this task.

    • The following command can be used to find files with (group or other or both) writable permission and SET UID set.

    # find / -perm /022 -and -perm -4000 -exec ls -ldb {} ;
                            ^^^^                       ^
                            | | | |                           |– So the SUID is 4
                            | | | |– Other is writable (2)
                            | | |–Group permission is writable (2)
                            | |– No owner permission mentioned (0)
                           |– As the logic is OR – group or other or both

    • You can use the following command to list files with other writable excluding sticky bit sets.

    # find / -perm -002 -and -perm -1000 -exec ls -ldb {} ;

    • Use the following command to list files with other writable excluding sticky bit set.

    # find / -perm -002 -not -perm -1000 -exec ls -ldb {} ;

    • The following command can be used to list files with (group + other) writable and SET GID set.

    # find / -perm -2022 -exec ls -ldb {} ;

    • The Find command to list files with (group + other) writable permission and SET UID set.

    # find / -perm -4022 -exec ls -ldb {} ;

    • Command to list files with other writable and sticky bit sets.

    # find / -perm -1002 -exec ls -ldb {} ;

    • Command to list files with other writable excluding sticky bit set.

    # find / -perm -002 -not -perm -1000 -exec ls -ldb {} ;

  • Find the largest directories sorted by disk space

    Use the du command to list firectories with largest disk space. Replace DIREC in the following commands with a starting directory (e.g; / or /etc)

    # du -sh $DIREC/* | sort -r --human-numeric-sort | head -n10

    In the above command, head -n10 option can be changed to list few or more results in the output.

    Another example is given below.

    # du -sh /* | sort -r --human-numeric-sort | head -n10

  • Are all numeric usernames allowed in AlmaLinux 8

    All numeric login names are not supported in AlmaLinux and CentOS. usernames that begin with a digit and also contain letters are not known to have any issue. However, in CentOS 7 version, some system tools can make varying assumptions.

    In Almalinux 8 and future releases, ALL numeric usernames are not supported. For more details check the man page of useradd. An excerpt is given below:

    Usernames may contain only lower and upper case letters, digits, underscores, or dashes. They can end with a dollar sign. Dashes are not allowed at the beginning of the username. Fully numeric usernames and usernames . or .. are also disallowed. It is not recommended to use
    usernames beginning with . character as their home directories will be hidden in the ls output. In regular expression terms: [a-zA-Z0-9_.][a-zA-Z0-9_.-]*[$]?

    In CentOS 7, user and group names consisting of only digits, while permitted by shadow-utils,  should best be avoided. OS tools, getent, setfacl, and chown can’t recognize ALL numeric login names. If you still want to create ALL numeric usernames shadow-utils will require the SHADOW_ALLOW_ALL_NUMERIC_USER environment variable to be set to any value so as to allow useradd to make ALL numeric usernames.

    POSIX does not forbid ALL numeric user names but it can introduce certain issues. Some programs only manipulate a string or an integer but CLI tools get their input as strings. They have to decide whether 3OO1 should be treated as a string username or an integer UID. 

     

  • How to disable delayed ACKs

    TCP throughput (SCP) from a remote host is slow. By looking at the trace, it is noticed that the CentOS server is waiting for up to 40ms before sending an ACK.

    In CentOS releases before 7.2, delayed Acks can only be reduced by cannot be eliminated. In CentOS 7.2, quickacks are tunable on a per route basis. By enabling quickacks delayed, The kernel disables aCKs. You can allow quickacks by executing ip route change based on ip route show.

    # ip route show
    default via 192.168.1.254 dev ens1 proto static metric 100
    192.168.1.0/24 dev ens1 proto kernel scope link src 192.168.1.112 metric 100

    # ip route change default via 192.168.1.254 dev ens1 proto static metric 100 quickack 1

    # ip route change 192.168.1.0/24 dev ens1 proto kernel scope link src 192.168.1.112 metric 100 quickack 1

    # ip route show
    default via 192.168.1.254 dev ens1 proto static metric 100 quickack 1
    192.168.1.0/24 dev ens3 proto kernel scope link src 192.168.1.112 metric 100 quickack 1

  • How to check if FANOTIFY is enabled in Kernel

    You can verify if the FANOTIFY is enabled in the kernel by using the following command.

    # cat /boot/config-$(uname -r) | grep FANOTIFY
    CONFIG_FANOTIFY=y
    CONFIG_FANOTIFY_ACCESS_PERMISSIONS=y

    FANOTIFY is built in the kernel, so there is no need to load other modules. It is enabled by default in CentOS 7,8 and AlmaLinux 8.

  • How to calculate free space in thin pool LV

    You can calculate free space in thinpool LVM by using the following command:

    # dmsetup status
    [... ]
    vg1-poolB-tpool: 0 45135824 thin-pool 1 4773/178944 90879/206109 - rw discard_passdown queue_if_no_space - 1024

    In the above output, 206109 are the total available extents and 90879 are the free extents. You can now find the chunk size as follows:

    # lvs -o chunk_size vg1/poolB
    Chunk
    64.00k

    Then total free space should be 5,816,256k.

  • How many simultaneous VNC sessions can run on a Linux server

    VNC is one of the most common methods to access servers remotely by multiple users simultaneously. VNC is usually configured as a systems service that is always on, serving a GUI session for a single or multiple users simultaneously. There is no limit on the number of VNC sessions in a Linux-based server, but constraints are based on available server resources that can be used effectively.

    Simultaneous VNC sessions are limited by three primary resources in a server: CPU, RAM, and bandwidth. In a VNC user session, software-based rendering renders the Graphical User Interface (GUI) to the video frame buffer used for remote connectivity.

    As such, a VNC session typically consumes high CPU resources than a local console. Similar resources utilization affects the RAM and bandwidth, as the VNC session uses system RAM for Its video frame buffer instead of video RAM.

    VNC sessions constrain network bandwidth, as it uses video compression techniques for desktop display, which is less efficient. It should be noted that running videos or graphics video editors on a VNC session will increase resource utilization.

    Generally, you can allocate 1 CPU core, 4GB RAM, and 10Mbps network bandwidth for each VNC session. It is recommended that for 8 VNC users, an 8-Core CPU, 32GB RAM, and 300Mbbps network connection is required.

    Some mitigation strategies are given below if you have limited hardware resources on a VNC server and serve multiple VNC users.

    • Instead of using GNOME sessions, use minimal X sessions to reduce VNC server load.
    • Reduce screen geometry with geometry options such as geometry=800×600.
    • Enable QoS (Quality of Service) to prioritize VNC over regular user sessions.
    • Limit VNC sessions to single tasks instead of running multiple processes simultaneously.