Linux

How to re-encode your Audiobooks as Opus

Opus is a modern high-efficiency audio codec that is especially suited to encode speech with very low bitrates.

Therefore, it’s a good fit to compress your Audiobook library so it consumes much less space.

First, choose a bitrate for Opus. I recommend to use 24kbit/s (24k) for general use, or 32 kbit/s (32k) if you want to have higher quality audio, e.g. if you are listening using good-quality headphones.

You can use ffmpeg directly by using this syntax:

ffmpeg -i <input file> -c:a libopus -b:a bitrate <output file>

but I recommend to use this shell function instead:

function audioToOpus { ffmpeg -i "$2" -c:a libopus -b:a "$1" "${2%.*}.opus" ; }

Copy & paste it into your shell, then call it like this:

audioToOpus <bitrate> <input file>

Example:

audioToOpus 24k myaudiobook.mp3

This command will create myaudiobook.opus. myaudiobook.mp3 will not be deleted automatically.

In case you want to have this function available permanently, add the function definition to your ~/.bashrc or ~/.zshrc, depending on which shell you use.

Posted by Uli Köhler in Audio, Linux

How to disable syntax highlighting in nano

To temporarily disable syntax highlighting in GNU nano, use the -Ynone option:

Instead of

nano myfile.php

use

nano -Ynone myfile.php

In order to permanently disable nano syntax highlighting, run this command:

echo "alias nano='nano -Ynone'" >> ~/.$(echo $SHELL | rev | cut -d/ -f1 | rev)rc
source ~/.$(echo $SHELL | rev | cut -d/ -f1 | rev)rc # Reload immediately

This will add nano -Ynone as an alias for nano into your .bashrc or .zshrc

Posted by Uli Köhler in Linux

How to get current shell name (e.g. bash/zsh) on Linux

To get just the name of the shell, e.g. bash or zsh, use

echo $SHELL | rev | cut -d/ -f1 | rev

Example:

$ echo $SHELL | rev | cut -d/ -f1 | rev
bash

To get the full path of the current shell executable, use

echo $SHELL

Example:

$ echo $SHELL
/bin/zsh

 

Posted by Uli Köhler in Linux

How to install automated certbot/LetsEncrypt renewal in 30 seconds

Let’s Encrypt currently issues certificates for 3 months at a time only. For many users, this mandates automated renewal of Let’s Encrypt certificates, however many manuals how to install automated renewals on ordinary Linux servers are needlessly complicated.

I created a systemd-timer based daily renewal routine using TechOverflow’s Simple systemd timer generator.

Quick install using

wget -qO- https://techoverflow.net/scripts/install-renew-certbot.sh | bash

This is the script which automatically creates & installs both systemd config files.

#!/bin/sh
# This script installs automated certbot renewal onto systemd-based systems.
# It requires that certbot is installed in /usr/bin/certbot!
# This needs to be run using sudo!

cat >/etc/systemd/system/RenewCertbot.service <<EOF
[Unit]
Description=RenewCertbot

[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew
WorkingDirectory=/tmp
EOF

cat >/etc/systemd/system/RenewCertbot.timer <<EOF
[Unit]
Description=RenewCertbot

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target
EOF

# Enable and start service
systemctl enable RenewCertbot.timer && sudo systemctl start RenewCertbot.timer

To view logs, use

journalctl -xfu RenewCertbot.service

To view the status, use

sudo systemctl status RenewCertbot.timer

To immediately run a renewal, use

sudo systemctl start RenewCertbot.service
Posted by Uli Köhler in Linux, nginx

How to run docker container as current user & group

If you want to prevent your docker container creating files as root, use

--user $(id -u):$(id -g)

as an argument to docker run. Example:

docker run --user $(id -u):$(id -g) -it -v $(pwd):/app myimage

 

Posted by Uli Köhler in Container, Docker, Linux

How to recompress gzipped .gz files to .xz files on Linux

Copy and paste this shell function into your bash or zsh:

function gzToXz { zcat "$1" | xz -c - -ev9 > "${1%.*}.xz" ; }

This will decompress the file using zcat and pipe it into xz with the highest compression setting (-ev9). If you prefer less compression but more speed, use e.g. -5 instead of -ev9.

Use like this:

gzToXz my.gz

which will produce my.xz.

Posted by Uli Köhler in Linux, Shell

How to fix Wireshark "Couldn’t run /usr/bin/dumpcap in child process: Permission denied" on Linux

If you see an error message like this in Wireshark:

this is because your current user doesn’t have permission to capture packets from your network card.

This can be the case even if you have selected to allow normal users to capture packets during the Wireshark installation process. This is because the setting only takes effect after logging out and logging back in (or rebooting).

To fix the issue temporarily without logging out, run Wireshark as root: sudo wireshark

In order to fix the issue permanently, ensure your user is added to the wireshark group:

sudo usermod -a -G wireshark $USER

and then log out and log back in again (or reboot your computer).

Posted by Uli Köhler in Linux

How to fix LaTeX error File `environ.sty’ not found on Ubuntu

Problem:

You want to compile your LaTeX file on Ubuntu using latex or pdflatex but you see an error message like this:

! LaTeX Error: File `environ.sty' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)

Solution

sudo apt -y install texlive-latex-extra

This will install, among many other LaTeX files, environ.sty.

Posted by Uli Köhler in LaTeX, Linux

How to fix LaTeX error Package babel Error: Unknown option `ngerman’ on Ubuntu

Problem:

You want to compile your LaTeX file on Ubuntu using latex or pdflatex but you see an error message like this:

! Package babel Error: Unknown option `ngerman'. Either you misspelled it
(babel)                or the language definition file ngerman.ldf was not foun
d.

See the babel package documentation for explanation.
Type  H <return>  for immediate help

Solution

sudo apt -y install texlive-lang-german

This will install, among many other LaTeX files, the files for the ngerman language.

Posted by Uli Köhler in LaTeX, Linux

How to fix Ubuntu LaTeX ! I can’t find file `ecrm1200′.

Problem:

You want to compile your LaTeX file on Ubuntu using latex or pdflatex but you see an error message like this:

kpathsea: Running mktexmf ecrm1200
! I can't find file `ecrm1200'.
<*> ...ljfour; mag:=1; nonstopmode; input ecrm1200
                                                  
Please type another input file name
! Emergency stop.
<*> ...ljfour; mag:=1; nonstopmode; input ecrm1200
                                                  
Transcript written on mfput.log.
grep: ecrm1200.log: No such file or directory
mktextfm: `mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input ecrm1200' failed to make ecrm1200.tfm.
kpathsea: Appending font creation commands to missfont.log.

! Font T1/cmr/m/n/12=ecrm1200 at 12.0pt not loadable: Metric (TFM) file not fou
nd.
<to be read again> 
                   relax 
l.105 \fontencoding\encodingdefault\selectfont

Solution

sudo apt -y install texlive-fonts-recommended

This will install, among many other LaTeX files, ecrm1200.mf and ecrm1200.tfm.

.

Posted by Uli Köhler in LaTeX, Linux

How to fix LaTeX Error: File `scrartcl.cls’ not found on Ubuntu

Problem:

You want to compile your LaTeX file on Ubuntu using latex or pdflatex but you see an error message like this:

! LaTeX Error: File `scrartcl.cls' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: cls)

Solution

sudo apt -y install texlive-latex-recommended

This will install, among many other LaTeX files, scrartcl.cls.

Posted by Uli Köhler in LaTeX, Linux

How to check if secure boot is enabled on Ubuntu?

On the command line, run

sudo mokutil --sb-state​

This will tell you

SecureBoot enabled​_

if secure boot is currently active on your machine or

SecureBoot disabled

else.

In case you see an error message like

bash: command not found: mkoutil

you need to install mokutil first using

sudo apt install mokutil​_
Posted by Uli Köhler in Linux

How to install NodeJS 12.x on Ubuntu in 1 minute

Run these shell commands on your Ubuntu computer to install NodeJS 12.x:

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

Instead of setup_12.x you can also choose other versions like setup_8.x. However, using this method, you can’t install multiple versions of NodeJS in parallel.

Source: Official nodesource documentation

Posted by Uli Köhler in Linux, NodeJS

What does ‘lsusb’ do on Linux?

lsusb lists all the USB devices to your computer.

Example output:

Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 8087:0a2b Intel Corp. 
Bus 001 Device 002: ID 04f2:b5e8 Chicony Electronics Co., Ltd 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Each line represents a single USB device – but an USB device might also be internal to the computer and not connected to a physical USB port. For example, Bus 001 Device 003: ID 8087:0a2b Intel Corp. is an internal Bluetooth modem in my notebook.

Explanation:

  • Bus 001: The device is connected to the first USB bus (001) on the system
  • Device 003: In the aforementioned bus, the device has been assigned the ID 003.
  • ID 8087:0a2b: This is the ID assigned to that device. The first part (8087) is the Vendor ID (VID). The second part (0a2b) is the Product ID (PID). These IDs are assigned by the USB Implementer’s forum. This ID will always stay the same for any given device. If you buy a USB product multiple times, all of them will have the same ID.
  • Intel Corp.: This is the description of the device. Often Linux can show you more information, but in this case it’s just the name of the manufacturer.
Posted by Uli Köhler in Linux

What is a PPA on Linux?

A PPA (Personal Package Archive) is a repository where you can download packages, that is software, for Debian-based Linux distributions like Ubuntu.

In contrast to “normal” package source that are provided and maintained by distribution providers, PPAs can be created by anyone in order to publish one’s software or special versions of third-party software.

PPAs are hosted on Launchpad, a platform made and supported by Canonical, the company behind Ubuntu.

Are PPAs safe?

While in principle one could publish dangerous software on a PPA, in practice there is virtually no risk since:

  • Most often the PPA is provided by the original author of the software and can hence be trusted, if the software you want to install is trusted
  • PPAs are frequently used by amateurs and experts alike
  • You can only upload source DEB packages to the PPA which is built on Canonical’s server. This reduces the likelihood of smuggeling in binaries with malicious software.
  • Malicious PPAs are quickly removed once reported

Still it is good practice to keep in mind that installing software from anywhere – including PPAs – has a chance (although a very little one) to compromise your computer.

Posted by Uli Köhler in Linux

How to fix iotop ‘Netlink error: Operation not permitted (1)’

Problem:

You are trying to run iotop but you see an error message like

Netlink error: Operation not permitted (1)

The Linux kernel interfaces that iotop relies on now require root priviliges
or the NET_ADMIN capability. This change occured because a security issue
(CVE-2011-2494) was found that allows leakage of sensitive data across user
boundaries. If you require the ability to run iotop as a non-root user, please
configure sudo to allow you to run iotop as root.

Please do not file bugs on iotop about this.

Solution:

You need to run iotop as root:

sudo iotop

The reason for this is that iotop needs to access kernel interfaces that are only accessible to root users or if the user/process has the CAP_NET_ADMIN capability. In theory you could add this capability using sudo setcap cap_net_admin+ep /usr/sbin/iotop but on Ubuntu 18.04 this did not work for me.

 

Posted by Uli Köhler in Linux