Linux

How to use custom port for ZeroTier instead of 9993 on Linux

You can create /var/lib/zerotier-one/local.conf – by default it doesn’t exist, if it does, just add these settings:

{
  "settings": {
    "primaryPort": 9994
  }
}

 

Posted by Uli Köhler in Linux, Networking, ZeroTier

How to install gcsfuse on Ubuntu 22.04 (jammy)

If you try to install gcsfuse on Ubuntu 22.04, you will face two issues. First, the signature can’t be verified due to the new method of managing APT keys. Secondly, the gcsfuse repo does not have packages for Ubuntu 22.04 even 5 months after its release:

Err:10 http://packages.cloud.google.com/apt gcsfuse-jammy Release                                                                                                                  
  404  Not Found [IP: 64.233.161.101 80]

You can work around both issues by force-installing the bionic packages which appear to work fine for me.

export GCSFUSE_REPO=gcsfuse-bionic
echo "deb [signed-by=/usr/share/keyrings/gcsfuse.gpg] http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list
wget -qO- https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor --yes --output /usr/share/keyrings/gcsfuse.gpg

 

Posted by Uli Köhler in Linux

How to fix apt error: NO_PUBKEY FEEA9169307EA071 NO_PUBKEY 8B57C5C2836F4BEB

Problem:

When running apt update, you see the following error message:

Err:12 http://packages.cloud.google.com/apt gcsfuse-bionic InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY FEEA9169307EA071 NO_PUBKEY 8B57C5C2836F4BEB

Solution:

This error occurs due to the VirtualBox repo using the outdated (as of April 2022) apt-key method of importing keys.

You can import the key by just installing the gcsfuse repo again. The following commands are based on the official installation guide.

export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s`
echo "deb [signed-by=/usr/share/keyrings/gcsfuse.gpg] http://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list
wget -qO- https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor --yes --output /usr/share/keyrings/gcsfuse.gpg

and then running

apt update

again. Note that at the time of writing this post, gcsfuse is not available for Ubuntu 22.04 in the official repository.

You can work around this by installing the bionic packages instead of jammy. For more details, see our post

Posted by Uli Köhler in Linux

How to generate random hex string using OpenSSL

The following command will generate a 32-bytes long random hex string

openssl rand -hex 16

Example:

$ openssl rand -hex 16
122166dd9e2d617246da9af9d7d3cd6f

The command lists 16, not 32 because OpenSSL will generate 16 random binary bytes and then convert these 16 bytes into 32 hex characters.

Posted by Uli Köhler in Linux

How to print fingerprints of all SSH host keys

In oder to print new-style (SHA256) fingerprints such as Is7oLjYcKue/zRjPKy9gQma/9F24KGaMPHbGberPGAw, use

for i in /etc/ssh/ssh_host_*_key; do sudo ssh-keygen -l -E sha256 -f "$i"; done

Example output:

1024 SHA256:SAhM78NWwqoYS/nRByGs1oqJxrX8fZL/PR/F5oX3QWs [email protected] (DSA)
256 SHA256:V/+9872Yg1i2Q4i7Nt4ef5R06lAuzT6qKemaQEt8EJQ [email protected] (ECDSA)
256 SHA256:Is7oLjYcKue/zRjPKy9gQma/9F24KGaMPHbGberPGAw [email protected] (ED25519)
2048 SHA256:AORSBitRPpwXrbTQzP0Mb/OBXyK+V6gyWf0S4bIh7Ys [email protected] (RSA)

In order to print old-style (MD5) fingerprints such as 5c:19:8b:94:44:5e:b6:15:e6:32:cc:3c:9b:38:6b:4c, use this command:

for i in /etc/ssh/ssh_host_*_key; do sudo ssh-keygen -l -E md5 -f "$i"; done

Example output:

1024 MD5:6d:f8:17:9b:4a:f5:ec:14:04:68:22:9c:ca:2c:a1:19 [email protected] (DSA)
256 MD5:5c:19:8b:94:44:5e:b6:15:e6:32:cc:3c:9b:38:6b:4c [email protected] (ECDSA)
256 MD5:45:dd:7f:91:89:67:ab:2d:ee:a2:f8:9e:18:68:5b:0d [email protected] (ED25519)
2048 MD5:1b:b2:54:3a:10:51:17:b4:49:af:73:c2:da:d6:fc:df [email protected] (RSA)
Posted by Uli Köhler in Linux

How to fix Ubuntu PHP Uncaught Error: Call to undefined function simplexml_load_file()

Problem:

Your wordpress page or other PHP application displays a critical error, with the following message:

2022/09/17 04:11:49 [error] 98082#98082: *1053 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function simplexml_load_file() in /var/sites/mysite.com/wp-content/plugins/otgs-installer-plugin/vendor/otgs/installer/includes/class-wp-installer.php:870

Solution:

Install the php[VERSION]-xml package for the PHP version that is running wordpress.

For example:

sudo apt -y install php8.1-xml
Posted by Uli Köhler in Linux

How to fix Ubuntu PHP error: Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

Problem:

When loading your wordpress page, you see the following message:

Your PHP installation appears to be missing the MySQL extension which is required by WordPress.

Solution:

Install the php[VERSION]-mysql package for the PHP version that is running wordpress.

For example:

sudo apt -y install php8.1-mysql

 

Posted by Uli Köhler in Linux

bash cat EOF to file minimal example

cat <<EOF >/etc/dhcp/dhcpd.conf
authoritative;
default-lease-time 86400;
max-lease-time 86400;

subnet 192.168.99.0 netmask 255.255.255.0 {
  range 192.168.99.100 192.168.99.150;
  option routers 192.168.99.1;
  option domain-name-servers 192.168.99.1;
  option domain-name "local";
}
EOF

 

Posted by Uli Köhler in Linux

How to fix apt error: NO_PUBKEY A2F683C52980AECF

Problem:

When running apt update, you see the following error message:

Err:13 https://download.virtualbox.org/virtualbox/debian jammy InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY A2F683C52980AECF

Solution:

This error occurs due to the VirtualBox repo using the outdated (as of April 2022) apt-key method of importing keys.

You can import the key by just installing the tailscale repo again (these commands are based on the commands from the VirtualBox Linux downloads page):

wget -qO- https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --dearmor --yes --output /usr/share/keyrings/oracle-virtualbox-2016.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list

and then running

apt update

again.

 

Posted by Uli Köhler in Linux

How to fix apt error: NO_PUBKEY 458CA832957F5868

Problem:

When running apt update, you see the following error message:

Err:27 https://pkgs.tailscale.com/stable/ubuntu jammy InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 458CA832957F5868

 

Solution:

This error occurs due to the Tailscale repo using the outdated (as of April 2022) apt-key method of importing keys.

You can import the key by just installing the tailscale repo again (these commands are listed on the official tailscale installation page):

curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/jammy.noarmor.gpg | sudo tee /usr/share/keyrings/tailscale-archive-keyring.gpg >/dev/null
curl -fsSL https://pkgs.tailscale.com/stable/ubuntu/jammy.tailscale-keyring.list | sudo tee /etc/apt/sources.list.d/tailscale.list

and then running

apt update

again.

 

Posted by Uli Köhler in Linux

How to generate JSON with random password with pwgen and bash

This script will generate a random password stored in a JSON file:

echo "{\"secret\": \"$(pwgen 30 1)\"}" > secret.json

Example output

{"secret": "thie2uv6Ro3cah2oodohx2vai5Ahka"}

 

Posted by Uli Köhler in Linux

How to view software RAID status on Linux

You can simply view /proc/mdstat:

cat /proc/mdstat

Example output

Personalities : [raid1] [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid10] 
md2 : active raid5 sdb3[4] sdd3[0] sda3[2] sdc3[1]
      2111434752 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [UUU_]
      [===>.................]  recovery = 16.2% (114244316/703811584) finish=48.8min speed=201053K/sec
      bitmap: 2/6 pages [8KB], 65536KB chunk

md1 : active raid1 sdb2[3] sda2[2] sdd2[0] sdc2[1]
      1046528 blocks super 1.2 [4/4] [UUUU]
      
md3 : active raid5 sdb4[4] sda4[2] sdd4[0] sdc4[1]
      44661594624 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [UUU_]
        resync=DELAYED
      bitmap: 2/111 pages [8KB], 65536KB chunk

md0 : active raid1 sda1[2] sdb1[3] sdd1[0] sdc1[1]
      33520640 blocks super 1.2 [4/4] [UUUU]
      
unused devices: <none>

 

Posted by Uli Köhler in Linux

How to fix apt error: NO_PUBKEY 1F3045A5DF7587C3

Problem:

When running apt update, you see the following error message:

Err:14 https://repo.skype.com/deb stable InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 1F3045A5DF7587C3

Solution:

This error occurs due to the Skype repo using the outdated (as of April 2022) apt-key method of importing keys.

You can import the key using the following commands:

wget -qO- https://repo.skype.com/data/SKYPE-GPG-KEY | gpg --dearmor | sudo tee /usr/share/keyrings/skype-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/skype-archive-keyring.gpg] https://repo.skype.com/deb stable main" > /etc/apt/sources.list.d/skype-stable.list

and then running

apt update

again.

 

Posted by Uli Köhler in Linux

How to fix apt error: NO_PUBKEY C5E224500C1289C0

Problem:

When running apt update, you see the following error message:

Err:2 https://linux.teamviewer.com/deb stable InRelease                                                                                                                                
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY C5E224500C1289C0

Solution:

This error occurs due to the teamviewer repo using the outdated (as of April 2022) apt-key method of importing keys.

You can import the key using the following commands:

wget -q https://download.teamviewer.com/download/linux/signature/TeamViewer2017.asc -O- | gpg --dearmor | sudo tee /usr/share/keyrings/teamviewer-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/teamviewer-archive-keyring.gpg] https://linux.teamviewer.com/deb stable main" > /etc/apt/sources.list.d/teamviewer.list

and then running

apt update

again.

 

Posted by Uli Köhler in Linux

How to fix VFS: cifs_mount failed w/return code = -22

Problem:

When trying to mount a CIFS/SMB share, you see the following error log in dmesg:

[  139.680974] CIFS: Attempting to mount \\10.10.10.10\test
[  139.686714] CIFS: VFS: cifs_mount failed w/return code = -22

Solution:

This is a currently a bug in Samba or the Kernel but you can easily work around it by adding vers=2.0to the mount options, either in /etc/fstab or if using mount manually, by using the -o vers=2.0 option. This forces Samba to use SMB version 2.0 which does not have the bug.

Posted by Uli Köhler in Linux, Networking

How to find files with filename starting with a space on the command line

This simple bash script will recursively find files in the current directory which start with a space.

find . -name " *"

 

Posted by Uli Köhler in Linux

How to move all VCard files to other directory based on file content, ignoring the filename

This command will identify all VCard files in a directory by file content (not by file extensin recursively using the file command (looking for text/vcard MIME types) and move those to a different directory.

mkdir -p ../VCards && find . -type f -exec sh -c '
    case $( file -bi "$1" ) in (text/vcard*) exit 0; esac
    exit 1' sh {} \; -exec mv -v --backup=numbered {} ../VCards \;

Based on this StackExchange post. Also see How to move all images to other directory based on file content, ignoring the filename and How to move all videos to other directory based on file content, ignoring the filename and How to move all OOXML (Word .docx/Excel .xlsx) files to other directory based on file content, ignoring the filename

Posted by Uli Köhler in Linux

How to move all PDF files to other directory based on file content, ignoring the filename

This command will identify all PDF files in a directory by file content (not by file extensin recursively using the file command (looking for application/pdf MIME types) and move those to a different directory.

mkdir -p ../PDF && find . -type f -exec sh -c '
    case $( file -bi "$1" ) in (application/pdf*) exit 0; esac
    exit 1' sh {} \; -exec mv -v --backup=numbered {} ../PDF \;

Based on this StackExchange post. Also see How to move all images to other directory based on file content, ignoring the filename and How to move all videos to other directory based on file content, ignoring the filename and How to move all OOXML (Word .docx/Excel .xlsx) files to other directory based on file content, ignoring the filename

Posted by Uli Köhler in Linux

How to use xterm and picocom for serial VT52 emulation

First open xterm in VT52 mode:

xterm -ti vt52 -tn vt52

Inside the xterm terminal window, open picocom to access the serial port.

picocom -b 115200 /dev/ttyACM0

While the serial port access will be handled by picocom, the terminal emulation (i.e. escape code interpretation) will be handled by xterm.

Posted by Uli Köhler in Linux

How to set zsh as standard shell in Ubuntu

Install zsh

sudo apt install zsh

Add zsh to list of valid shells

sudo vim /etc/shells

Add to the list

/usr/bin/zsh

Set zsh as default shell

chsh -s /usr/bin/zsh

Double check

$ echo $SHELL

Now you might want to check out https://ohmyz.sh/#install to install a nice theme.

Posted by Joshua Simon in Linux