Linux

How to fix ufw [UFW BLOCK] message spamming syslog / dmesg

Problem:

In your syslog which you can see using

dmesg

you see a lot of [UFW BLOCK] messages like these:

[600810.355752] [UFW BLOCK] IN=enp0s3 OUT= MAC=02:00:17:02:76:ad:00:00:17:b9:55:d6:08:00 SRC=45.146.164.226 DST=10.0.0.130 LEN=40 TOS=0x00 PREC=0x00 TTL=251 ID=59316 PROTO=TCP SPT=48741 DPT=50713 WINDOW=1024 RES=0x00 SYN URGP=0 
[600831.477953] [UFW BLOCK] IN=enp0s3 OUT= MAC=02:00:17:02:76:ad:00:00:17:b9:55:d6:08:00 SRC=74.118.36.15 DST=10.0.0.130 LEN=40 TOS=0x00 PREC=0x00 TTL=58 ID=59050 PROTO=TCP SPT=7527 DPT=23 WINDOW=14663 RES=0x00 SYN URGP=0 
[600853.366152] [UFW BLOCK] IN=enp0s3 OUT= MAC=02:00:17:02:76:ad:00:00:17:b9:55:d6:08:00 SRC=34.77.162.17 DST=10.0.0.130 LEN=44 TOS=0x00 PREC=0x00 TTL=253 ID=51373 PROTO=TCP SPT=50218 DPT=5900 WINDOW=1024 RES=0x00 SYN URGP=0 
[600876.538979] [UFW BLOCK] IN=enp0s3 OUT= MAC=02:00:17:02:76:ad:00:00:17:b9:55:d6:08:00 SRC=74.118.36.15 DST=10.0.0.130 LEN=40 TOS=0x00 PREC=0x00 TTL=58 ID=59050 PROTO=TCP SPT=7527 DPT=23 WINDOW=14663 RES=0x00 SYN URGP=0 

Solution:

Disable ufw logging using

sudo ufw logging off

and no new messages should appear.

Posted by Uli Köhler in Linux, Networking

How to fix Failed to restart samba.service: Unit samba.service not found on Debian & Ubuntu

Problem:

When trying to restart the Samba service on Ubuntu or Debian using

sudo systemctl restart samba

you see this error message:

Failed to restart samba.service: Unit samba.service not found.

Solution:

The samba service is called smbd, not samba. Restart it using

sudo systemctl restart smbd
Posted by Uli Köhler in Linux

How to add public writeable Samba share via smb.conf

[my_files]
   comment = My files
   path = /home/myuser/myfiles
   writeable = yes
   browseable = yes
   public = yes
   create mask = 0644
   directory mask = 0755
   force user = myuser

 

Posted by Uli Köhler in Linux

How to install glib-2.0 development headers on Alpine Linux

First run

apk update

as root to update the list of available packages. After that, install the glib 2.0 development files using

apk add glib-dev

 

Posted by Uli Köhler in Alpine Linux

How to install pkg-config on Alpine Linux

First run

apk update

as root to update the list of available packages. After that, install pkg-config using

apk add pkgconfig
Posted by Uli Köhler in Alpine Linux

How to install CMake on Alpine Linux

Run

apk update

as root to update the list of available packages. Then, run

apk add cmake

to install CMake.

Posted by Uli Köhler in Alpine Linux

How to save systemd journalctl log to json file

Save your journalctl logs as pretty json to a file.

sudo journalctl -xu yourservice.service -o json-pretty  > ~/test_logs.json
Posted by Joshua Simon in Linux

How to install KiCAD 6.0 on Ubuntu

Run this to install KiCAD 6.0:

sudo add-apt-repository ppa:kicad/kicad-6.0-releases
sudo apt update -y
sudo apt -y install kicad

 

Posted by Uli Köhler in KiCAD, Linux

How to install nextcloud GUI client on Ubuntu using the PPA

The following script will install the nextcloud client and file manager integrations for all installed file managers. Run as root!

sudo add-apt-repository -y ppa:nextcloud-devs/client
sudo apt-get update
sudo apt -y install nextcloud-client

# Install Nautilus integration if nautilus is installed
dpkg --status nautilus > /dev/null 2>/dev/null
retVal=$?
if [ $retVal -eq 0 ]; then
    sudo apt -y install nautilus-nextcloud
fi

# Install Dolphin integration if nautilus is installed
dpkg --status dolphin > /dev/null 2>/dev/null
retVal=$?
if [ $retVal -eq 0 ]; then
    sudo apt -y install dolphin-nextcloud
fi

# Install Caja integration if nautilus is installed
dpkg --status caja > /dev/null 2>/dev/null
retVal=$?
if [ $retVal -eq 0 ]; then
    sudo apt -y install caja-nextcloud
fi

# Install Nemo integration if nautilus is installed
dpkg --status nemo > /dev/null 2>/dev/null
retVal=$?
if [ $retVal -eq 0 ]; then
    sudo apt -y install nemo-nextcloud
fi

 

Posted by Uli Köhler in Linux

How to move all OOXML (Word .docx/Excel .xlsx) files to other directory based on file content, ignoring the filename

This command will identify all OOXML files such as .xlsx or .docx in a directory recursively using the file command (looking for application/vnd.openxmlformats-officedocument MIME types) and move those to a different directory.

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

 

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 PDF files to other directory based on file content, ignoring the filename

Posted by Uli Köhler in Linux

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

This command will identify all audio files such as MP3s in a directory recursively using the file command (looking for audio/* MIME types) and move those to a different directory.

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

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

Posted by Uli Köhler in Linux

How to delete all “Apple binary property list” files from directory

In backups you often see files like

0899d5d3c7f86344a8c085a053f5ca106482e6b8: Apple binary property list
089ce36beb618daa09263be95bd70880bd974dae: Apple binary property list
08b86c8bffdf6b12a0e4bd9f6807316afac51b53: Apple binary property list

without filename extension, that are not useful when you just care about the backupped files themselves and not any Apple-related metadata.

You can remove them using

file * | grep "Apple binary property list" | cut -f1 -d: | xargs rm -v

 

Posted by Uli Köhler in Linux

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

This command will identify all video files such as MP4s in a directory recursively using the file command (looking for video/* MIME types) and move those to a different directory.

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

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 audio files to other directory based on file content, ignoring the filename and How to move all PDF files to other directory based on file content, ignoring the filename

Posted by Uli Köhler in Linux

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

This command will identify all image files in a directory recursively using the file command (looking for image/* MIME types) and move those to a different directory.

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

 

Based on this StackExchange post. Also see How to move all audio files 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 PDF files to other directory based on file content, ignoring the filename

Posted by Uli Köhler in Linux

How to move files from deep subdirectory structure to toplevel directory on Linux

This command line approach is rather primitive but will not overwrite files.

Run this repeatedly until all files are gone:

mv --backup=numbered **/* . && rmdir *

 

Posted by Uli Köhler in Linux

How to remove all .thumb files on the command line

find . -name "*.thumb" -type f -exec rm -v {} \;

 

Posted by Uli Köhler in Linux

How to optimize all JPG/JPEG files in a directory using jpegoptim

This is very useful in optimizing photo archives etc without changing the directory structure:

find . -name "*.jpg" -exec jpegoptim {} \;
find . -name "*.jpeg" -exec jpegoptim {} \;
find . -name "*.JPG" -exec jpegoptim {} \;
find . -name "*.JPEG" -exec jpegoptim {} \;
Posted by Uli Köhler in Linux

How to use screen sessions in linux?

Step 0: Check if screen is installed

screen

If not run

sudo apt -y install screen

Step 1: Create a screen session with a meaningful session name

screen -S sessionname

Step 2: Check if you are in a screen session

$ echo $STY

If the result is something like this:

941609.sessionname

you are currently in a session.

Step 3: Exit and terminate screen session

$ exit

Step 4: Exit and keep screen session running (detach)

$ screen -d

Step 5: See existing screen sessions

$ screen -ls

Step 6: Reattach to existing screen sessions

$ screen -r sessionname
Posted by Joshua Simon in Linux

How I encode speech files using Opus

This saves about ~90% of space compared to Mono WAV files:

ffmpeg -i <input> -c:a libopus -vbr on -compression_level 10 -frame_duration 60 <output>

and will result in approximately 100kBit/s bitrate for many typical speech files.

In order to make it even smaller, use

ffmpeg -i <input> -c:a libopus -b:a 24K -frame_duration 60 <output>

This is still very high quality for typical speech (without too much music) and you will only notice differences in direct comparison. In a typical 1.1GB podcast file, it resulted in a filesize of 0.512% of the original WAV.

 

Posted by Uli Köhler in Linux

How to force diff to compare binary files

Use the --text flag to force diff to compare files in text mode even if it thinks they are binary files:

diff --text a.txt b.txt

 

Posted by Uli Köhler in Linux