Category Archives: Linux

The following signatures were invalid: EXPKEYSIG B188E2B695BD4743

If you get this error message while apt-get update: The following signatures were invalid: EXPKEYSIG B188E2B695BD4743 DEB.SURY.ORGThe following signatures were invalid: EXPKEYSIG B188E2B695BD4743 DEB.SURY.ORG It means you need to update the APT signing key. To fix this issue just type this as root in your server: wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpgwget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg Then run […]

Make name server address permanent in /etc/resolv.conf

How to make name server address permanent in /etc/resolv.conf? If you do not have the package resolvconf installed, then it is easy: after changing it the way you like, issue the command: sudo chattr +i /etc/resolv.confsudo chattr +i /etc/resolv.conf The command changes the file attributes, making it immutable (the +i option). To view the attribute […]

How to List INPUT, FORWARD, OUTPUT Iptables Rules

To view INPUT, FORWARD, OUTPUT iptables rules just use: iptables -Siptables -S Here is an example output: -P INPUT ACCEPT -P FORWARD ACCEPT -P OUTPUT ACCEPT -A INPUT -i tun0 -j ACCEPT -A INPUT -i ens2 -p udp -m udp –dport 1194 -j ACCEPT -A FORWARD -i tun0 -o ens2 -j ACCEPT -A FORWARD -i […]

How to List All Iptables NAT Rules

Use this iptables command-line to view all NAT rules: iptables -t nat -Siptables -t nat -S Here is an example output: -P PREROUTING ACCEPT -P INPUT ACCEPT -P POSTROUTING ACCEPT -P OUTPUT ACCEPT -A POSTROUTING -s 10.8.0.0/24 -o ens2 -j MASQUERADE-P PREROUTING ACCEPT -P INPUT ACCEPT -P POSTROUTING ACCEPT -P OUTPUT ACCEPT -A POSTROUTING -s […]

How to Parse Command-Line Arguments in Bash

Need to parse command-line arguments in a bash script? Personally I always use this method: #!/bin/bash   while [[ "$#" -gt 0 ]]; do case $1 in -d|–deploy) deploy="$2"; shift ;; -u|–uglify) uglify=1 ;; *) echo "Unknown parameter passed: $1"; exit 1 ;; esac shift done   echo "Should deploy? $deploy" echo "Should uglify? $uglify"#!/bin/bash […]

How to Make Iptables Rules Persistent

There is Debian package named “iptables-persistent”. iptables-persistent makes sure iptables rules survive a reboot. To install it just type this command: apt-get -y install iptables-persistentapt-get -y install iptables-persistent To install it in an automated way check this: Bash Install Iptables-Persistent Automatically Other useful info can be found here: https://wiki.debian.org/iptables

Bash Install Iptables-Persistent Automatically

Check if iptables-persistent is installed, else install it: if [[ $(dpkg -s iptables-persistent) != *"Status: install ok installed"* ]]; then echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections apt-get -y install iptables-persistent fiif [[ $(dpkg -s iptables-persistent) != *"Status: install ok installed"* ]]; then echo iptables-persistent iptables-persistent/autosave_v4 […]

Route OpenVPN Connections Through Floating IP

Assuming you have a Hetzner VPS with a floating IP address: How to Configure a Floating IP in a VPS (Hetzner) Let’s say the floating IP address is 44.44.44.44 as example. And that you have installed OpenVPN via this guide: How to Install OpenVPN in Debian 10 Buster 1) Edit /etc/openvpn/server.conf and add: local 44.44.44.44local […]

How to Configure a Floating IP in a VPS (Hetzner)

First create a Hetzner VPS and attach a floating IP to it. I followed this guide to make sure the floating IP is persistent: How to Make Floating IP Persistent (Hetzner) In short, the procedure is like this: 1) Create a file named 60-my-floating-ip.cfg: vi /etc/network/interfaces.d/60-my-floating-ip.cfgvi /etc/network/interfaces.d/60-my-floating-ip.cfg 2) Paste the following configuration for IPv4: auto […]

Bash Trim Leading and Trailing Whitespace from a String

You can use awk to trim a string, example: echo " test " | awk ‘{$1=$1};1’echo " test " | awk ‘{$1=$1};1’ Another way is to use sed like this: echo " test " | sed -e ‘s/^[[:space:]]*//’ -e ‘s/[[:space:]]*$//’echo " test " | sed -e ‘s/^[[:space:]]*//’ -e ‘s/[[:space:]]*$//’ And also xargs can be used: […]