Spoofing your hostname with a random string

November 21, 2020 Reading time: 2 minutes

Systemd gives us a utility to change hostname with

https://www.freedesktop.org/software/systemd/man/hostnamectl.html

Inspiration taken from here -->

https://github.com/red0xff/hostnamespoof

Here is my code -->

File location: /usr/local/bin/rand_hostname.sh

#!/bin/bash

#Generate a random string and then use it as a hostname. Used in conjunction with randomising the
#network adapter MAC addresses to help keep you anonymous

#Generates a random string between 3 and 9 chars
hostname=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c$(< /dev/urandom tr -dc 3-9 | head -c1;echo;);echo;)

#Debug
#echo $hostname

#now set the new hostname
/usr/bin/hostnamectl set-hostname $hostname


Now to set up the systemd service.

File location: /etc/systemd/system/rand_hostname.service

[Unit]
Description=a tool randomizing hostname at each boot
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/rand_hostname.sh

[Install]
WantedBy=multi-user.target

Now to enable with

sudo systemctl enable rand_hostname.service

And reload

sudo systemctl daemon-reload rand_hostname.service


Stopping email address visibility in nextcloud contacts

November 7, 2020 Reading time: ~1 minute

From here --> https://help.nextcloud.com/t/change-default-profile-privacy-settings-email-hidding/22647/2

Edit this file more less in the line 308: “NCrootFolder”/lib/private/Accounts/AccountManager.php

Where it says:
self::PROPERTY_EMAIL =>
[
‘value’ => $user->getEMailAddress(),
‘scope’ => self::VISIBILITY_CONTACTS_ONLY,
‘verified’ => self::NOT_VERIFIED,
],

It should say:
self::PROPERTY_EMAIL =>
[
‘value’ => $user->getEMailAddress(),
‘scope’ => self::VISIBILITY_PRIVATE,
‘verified’ => self::NOT_VERIFIED,
],

The problem is that the file might be overwrited in an update.

I think this should be private by default, or at least, configurable.


nextcloud cron jobs intergration with systemd

October 30, 2020 Reading time: 2 minutes

From Nextcloud background jobs. 

In order to get systemd to run the cron job every 5 minutes you need to do the following. Here is my configuration for my nextcloud instance (public)

/etc/systemd/system/nextcloud_autotraining.service

[Unit]
Description=Nextcloud cron.php job

[Service]
User=www-data
ExecStart=/usr/bin/php -f /var/www/autotraining.duckdns.org/cron.php
root@raspberrypi:~# cat /etc/systemd/system/nextcloudcron_autotraining.timer
[Unit]
Description=Run Nextcloud cron.php every 5 minutes

[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
Unit=nextcloudcron_autotraining.service

[Install]
WantedBy=timers.target
root@raspberrypi:~# cat /etc/systemd/system/nextcloudcron_autotraining.service
[Unit]
Description=Nextcloud cron.php job

[Service]
User=www-data
ExecStart=/usr/bin/php -f /var/www/autotraining.duckdns.org/cron.php

Now the nextcloud_autotraining.timer

[Unit]
Description=Nextcloud cron.php job

[Service]
User=www-data
ExecStart=/usr/bin/php -f /var/www/autotraining.duckdns.org/cron.php
root@raspberrypi:~# cat /etc/systemd/system/nextcloudcron_autotraining.timer 
[Unit]
Description=Run Nextcloud cron.php every 5 minutes

[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
Unit=nextcloudcron_autotraining.service

[Install]
WantedBy=timers.target

This now needs to be activated by:

systemctl enable --now nextcloudcron_autotraining.timer

Now as long as your filenames are correct, it should all start and run :)


logrotate fails when mariadb is secured with a root account password...

October 9, 2020 Reading time: ~1 minute

Mariadb is recommended to run mysql_secure_installation to set a root password and disable access form the network and remove all the evaluation databases and users.

When I found the errors in the journal (systemd) that logrotate could not authenticate against the root mariadb account to complete the log rotate.

A lot of searching later I found this page --> https://mariadb.com/kb/en/authentication-plugin-unix-socket/

After a bit of reading I found the server needs to have the --unix-socket=ON option to allow the user of logrotate to access the password for the root account of the database.

the format of the /root/.my.cnf file is as follows:

[client]

user = root

password = "YOUR_PASSWORD"

And that's it...


Enabling systemd-journald logging service on Raspberry Pi

September 6, 2020 Reading time: ~1 minute

I have installed systemd on my Pi, since then I have found that there has been zero logging from May (it is now September) in syslog. I have discovered on the Pi, systemd was configured to have a non persistent logging facility. It seems that /etc/systemd/systemd-journald.conf is default commented out thus causing the logging to be non persistent and in /var/run/journal/ directory.

This is an issue when running a server, especially since mine has ssh exposure.

in order to change this you need to add Storage=persistent

This will add a directory called /var/log/journal/ where all journals are stored.

A reboot and all should be good. I did a bit different, I also created the journal directory before the reboot by

sudo mkdir -p /var/log/journal

sudo systemd-tmpfiles --create --prefix /var/log/journal

Now I have the following files in journal -->

drwxr-sr-x+ 2 root systemd-journal 4096 Sep  6 07:50 d3e79edd79094236b577249849bfdb93

which is proof it is working.


Code for converting pdf to csv

July 12, 2020 Reading time: ~1 minute

<code>

import tabula

#file = "/home/work/Documents/Unit_Reports/SFC-00428 Gaurang.pdf"
# output all the tables in the PDF to a CSV
#tabula.convert_into(file, "SFC-00428_Gaurang.csv", pages = "all")
tabula.convert_into_by_batch("/home/work/Documents/Unit_Reports/PDf/", output_format = "csv", pages = "all")

</code>


LazyCoderOZ

I am a Linux guy, been around for 20+ years using Linux as my daily driver.
This is my blog on my discoveries and notes so I don't forget how I have done things :)