1. View firewalld rules

sudo firewall-cmd --list-all

To see rules for all zones:

sudo firewall-cmd --list-all-zones

To see which zones are active:

sudo firewall-cmd --get-active-zones

For a specific zone:

sudo firewall-cmd --zone=public --list-all

2. Open a port temporarily

This lasts until firewalld is restarted/reloaded or the server reboots.

sudo firewall-cmd --add-port=8080/tcp

For UDP:

sudo firewall-cmd --add-port=8080/udp

For a specific zone:

sudo firewall-cmd --zone=public --add-port=8080/tcp

3. Open a port permanently

sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload

Verify:

sudo firewall-cmd --list-ports

4. Add a new user

sudo useradd username

Set their password:

sudo passwd username

Example:

sudo useradd john
sudo passwd john

5. Add a new user and add them to a group at the same time

For a supplementary group:

sudo useradd -G groupname username

Example:

sudo useradd -G developers john

For multiple groups:

sudo useradd -G developers,docker,admins john

If you want the specified group to be the user’s primary group instead:

sudo useradd -g groupname username

6. Add an existing user to a group

sudo usermod -aG groupname username

Example:

sudo usermod -aG developers john

For multiple groups:

sudo usermod -aG developers,docker,admins john

The -a is important. Without it, usermod -G can replace the user’s existing supplementary group memberships.

Check the result:

id john

or:

groups john

7. Extract part of a text file using starting and ending line numbers

Use sed:

sed -n 'START,ENDp' filename

For example, extract lines 100 through 150:

sed -n '100,150p' /path/to/file.txt

Save those lines to another file:

sed -n '100,150p' /path/to/file.txt > extracted.txt

A useful variant when inspecting logs is to include line numbers:

sed -n '100,150{=;p}' /path/to/file.txt

For the firewall-cmd commands, if your interface is assigned to a zone other than the default zone, specify it explicitly with --zone=<zone>.