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.

TASKDESCRIPTIONCOMMAND

Manage YUM Repository

List enabled repositories on the server.repolist

Manage YUM Repository

Show information about enabled yum repositories.yum repoinfo centos-7-server-rpms

Manage YUM Repository

List packages in a repository.yum repo-pkgs seimaxim-rpms list

Manage YUM Repository

Install all packages in a seimaxim-rpms repository.yum repo-pkgs seimaxim-rpms install

Manage YUM Repository

Remove all packages from seimaxim-rpms repository.yum repo-pkgs seimaxim-rpms remove

Manage YUM Repository

Download the yum repository data in the cache.makecache

YUM Info

List yum options and commands.yum help

YUM Info

List all available & installed packages.yum list all

YUM Info

List all installed packages.yum list installed

YUM Info

Show all installed and available kernel packages.yum list kernel

YUM Info

Show info of ImageMagick package.yum info ImageMagick

YUM Info

Show package dependency.yum deplist ImageMagick

YUM Info

List package providing the queried file.yum provides "/sbin/adduser"

YUM Info

Search package by name.yum search finger

YUM Info

Show available and installed package groups.yum grouplist

YUM Info

Show contents and description of package groups.yum groupinfo "Web Server"

YUM Info

Show available updates in a repository.yum check-update

Installation, Removal, & Upgrade of Packages

Install the ImageMagick package.yum install vsftpd

Installation, Removal, & Upgrade of Packages

Update all packages installed on the server.yum update
yum -y update

Installation, Removal, & Upgrade of Packages

Update one package installed on the server.yum update httpd

Installation, Removal, & Upgrade of Packages

Upgrade all packages on the server.yum upgrade

Installation, Removal, & Upgrade of Packages

Update only security packages.yum update --security

Installation, Removal, & Upgrade of Packages

Update packages to a specific version.yum update-to

Installation, Removal, & Upgrade of Packages

Upgrade all packages on the server.yum upgrade

Installation, Removal, & Upgrade of Packages

Downgrade a package.yum downgrade vsftpd

Installation, Removal, & Upgrade of Packages

Remove a package (ftp) and install another (vsftpd).yum swap ftp vsftpd

Installation, Removal, & Upgrade of Packages

Erase a package and dependencies.yum remove lftp

Installation, Removal, & Upgrade of Packages

Erase a package and dependencies.yum erase lftp

Installation, Removal, & Upgrade of Packages

Erase a package and packages, not required.yum autoremove vsftpd

Installation, Removal, & Upgrade of Packages

Install all packages in selected group.yum groupinstall "Web Server"

Installation, Removal, & Upgrade of Packages

Install a package from http,ftp, or local file.yum localinstall xyz-2-2.x64.rpm
yum localinstall https://seimaxim-repo/xyz-2-2.x64.rpm

Troubleshoot YUM

Display yum update, install and erase commands.yum history list

Troubleshoot YUM

Display info of yum action 2.yum history info 2

Troubleshoot YUM

Undo yum action in transaction 2.yum history undo 2

Troubleshoot YUM

Redo yum action in transaction 2.yum history redo 2

Troubleshoot YUM

Useful for package updates rollback.yum fssnapshot

Useful YUM Commands

If prompted for install permission, assume no.yum --assumeno

Useful YUM Commands

Produce extra verbose output.yum -v

Useful YUM Commands

No verbose output.yum -q

Useful YUM Commands

Enable disabled repo.yum --enablerepo=
yum install ImageMagick --enablerepo=centos-7-server-rpm

Useful YUM Commands

Disable the enabled repo.yum list available --disablerepo=epel

Useful YUM Commands

Execute command without loading yum plugins.yum --noplugins

Useful YUM Commands

Show changelog details of a package.yum --changelog

Useful YUM Commands

List processes that have been updated and require a restart. Requires yum-utils package.yum needs-restarting

Useful YUM Commands

Show conflicted dependencies from the repository. Requires yum-utils package.yum repoclosure

Useful YUM Commands

Analyze consistency in local yum repository. Requires yum-utils package.yum verifytree

Useful YUM Commands

Complete yum actions that are not yet complete/failed. Requires yum-utils package.yum-complete-transaction

Useful YUM Commands

Change or check the yum database. Requires yum-utils package.yumdb

Useful YUM Commands

Download a package from a yum repository to a local server. Requires yum-utils package.yumdownloader

Useful YUM Commands

Download a package and its dependences. Requires yum-utils package.repotrack

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.