1. View firewalld rules
sudo firewall-cmd --list-allTo see rules for all zones:
sudo firewall-cmd --list-all-zonesTo see which zones are active:
sudo firewall-cmd --get-active-zonesFor a specific zone:
sudo firewall-cmd --zone=public --list-all2. Open a port temporarily
This lasts until firewalld is restarted/reloaded or the server reboots.
sudo firewall-cmd --add-port=8080/tcpFor UDP:
sudo firewall-cmd --add-port=8080/udpFor a specific zone:
sudo firewall-cmd --zone=public --add-port=8080/tcp3. Open a port permanently
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reloadVerify:
sudo firewall-cmd --list-ports4. Add a new user
sudo useradd usernameSet their password:
sudo passwd usernameExample:
sudo useradd john
sudo passwd john5. Add a new user and add them to a group at the same time
For a supplementary group:
sudo useradd -G groupname usernameExample:
sudo useradd -G developers johnFor multiple groups:
sudo useradd -G developers,docker,admins johnIf you want the specified group to be the user’s primary group instead:
sudo useradd -g groupname username6. Add an existing user to a group
sudo usermod -aG groupname usernameExample:
sudo usermod -aG developers johnFor multiple groups:
sudo usermod -aG developers,docker,admins johnThe -a is important. Without it, usermod -G can replace the user’s existing supplementary group memberships.
Check the result:
id johnor:
groups john7. Extract part of a text file using starting and ending line numbers
Use sed:
sed -n 'START,ENDp' filenameFor example, extract lines 100 through 150:
sed -n '100,150p' /path/to/file.txtSave those lines to another file:
sed -n '100,150p' /path/to/file.txt > extracted.txtA useful variant when inspecting logs is to include line numbers:
sed -n '100,150{=;p}' /path/to/file.txtFor the firewall-cmd commands, if your interface is assigned to a zone other than the default zone, specify it explicitly with --zone=<zone>.