Getting a 4 workspace layout in a square on Ubuntu 18.04

I really like my 4 workspaces organized in a square layout, not to say that I can’t live without. It’s handy to work and super efficient. It was a bummer to find out that things were different under GNOME after installing the Ubuntu 18.04 LTS, but no worries, it’s easy to get back (here’s how). This is wat we want (again):

Using GNOME now, the first thing you want to do is making sure you have the GNOME Tweaks tool installed

$ sudo apt install gnome-tweak-tool

Next, you’ll be installing a GNOME Shell Extension through the Shell Extensions webpage (https://extensions.gnome.org/) and the most convenient way is using an Extension in your favorite browser (available for Firefox/Chrome/Opera). This will require the extension connector first of all

$ sudo apt-get install chrome-gnome-shell

Next you will be installing the browser extension.
-> Firefox: Mozilla Addons
-> Chrome: Chrome web store
-> Opera: Opera Addons

This allows you now to install the Workspace Grid extension, so you can organize the workspaces into (2) rows and (2) columns. Once the extension installed, configure it clicking the respective button in your browser, or open up the Tweaks tool and navigate to Extensions.

Configure 2 rows and 2 columns (more if you’d like) here

Last thing to do is to make them static through the Tweaks tool (menu option Workspaces)

Tick “Static Workspaces”

All done! Navigate using Ctrl+Alt+(left/right/up/down), move windows adding the Shift (Ctrl+Shift+Alt+[left/right/up/down]).

Overly large menu fonts with java 10 in Ubuntu

I’m running Ubuntu 16.04. In 18.04, the default java install will become Java 10, so for an upgrade project I installed it on my machine. Since I read Netbeans 8.2 isn’t compatible with Java 10, I upgraded it as well to Netbeans 9.0

 

Unfortunately, in Netbeans 9.0, the font used by the GUI (such as for the Menu bar) was HUGE, actually too large to be usable in practice.

 

Having spent considerable time looking on forums, trying a lot of additions to my netbeans.conf file, none was of any help unfortunately.

 

Then, I stumbled accross this bug: Java windows and fonts are huge running in openjdk-11-jre, which eventually allowed me to solve the issue.

 

On my machine, executing the command dconf read /com/ubuntu/user-interface/scale-factor yielded:

{'eDP-1': 16, 'DP-1': 8}

That 16 scale factor is actually the source of these huge fonts. To change it, do the following:
 
1. First, export your dconf settings into an editable format

dconf dump / > dconf-settings.ini

2. Now edit the exported dconf-settings.ini with your favorite editor. Specifically, find this line and change it into:

scale-factor={'eDP-1': 8, 'DP-1': 8}

3. Last thing to do, is to re-import this modified settings again:

dconf load / < dconf-settings.ini

 

It did cost me some time, so I wanted to share this solution to help out someone else...

Install Belgian eID software in Ubuntu 16.04

Partially as a reminder to myself, here the steps how to get your eID working in Ubuntu (tested on 16.04, but should be working for other versions, Debian and Linux Mint as well)

  1. Download the .deb package from the official site
  2. Install the package: sudo dpkg -i eid-archive_*_all.deb
  3. Open a terminal and update your indexes: sudo apt-get update
  4. Install your eID cardreader: sudo apt-get install -y libacr38u
  5. Install the middleware and the eID viewer: sudo apt-get install -y eid-mw eid-viewer
  6. Reboot your PC (don’t miss this step!)
  7. Connect your cardreader and insert an eID card. You can make sure you can read it out using the eID viewer application.

You’ll need to use Firefox (!) to get it to work in websites. Quite sure it’s a certificate issue in Chrome/Chromium, but for the times I use it, I didn’t bother finding it out. You can test your ability to login using this website.

Example to send an e-mail from your Java application (with or without TLS authentication)

In this post I just wanted to share a small example to send an e-mail from your Java application, using TLS authentication. You’ll need to include the javax.mail.jar library from JavaMail in your project as a dependency…

 

I think all steps are pretty much self-explaining, like how to set the host, username and password, and how to add more recipients…

 

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

public class SendMail {

  public static void main(String[] args) {
    new SendMail();
  }

  public SendMail() {
    String toAddress = "recipient@you.com";
    String fromAddress = "from@me.com";

    Properties properties = System.getProperties();
    properties.setProperty("mail.smtp.host", "smtp.website.net");
    properties.setProperty("mail.smtp.port", "25");
    properties.setProperty("mail.smtp.auth", "true");
    properties.setProperty("mail.smtp.starttls.enable", "true");

    // To override the Authenticator in the session
    Authenticator authenticator = new Authenticator() {
      @Override
      protected PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication("username_or_email", "THE_P@SSWORD");
      }
    };

    // Create a session object with our above properties and the authenticator
    Session session = Session.getInstance(properties, authenticator);

    try {
      // Create a MimeMessage object.
      MimeMessage message = new MimeMessage(session);

      message.setFrom(fromAddress);
      message.addRecipient(Message.RecipientType.TO, new InternetAddress(toAddress));
      // Add TO, CC or BCC addresses as needed...

      message.setSubject("This is a subject for my e-mail...");
      message.setText("This is the body of my message...\n\nSincerely yours,\n\n\nTom");

      // Actually end the message...
      Transport.send(message);
      System.out.println("Message has been sent");
    } catch (MessagingException e) {
      e.printStackTrace(System.err);
    }
  }
}

If you don’t need authentication, your example becomes a lot shorter:

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

public class SendMail {

  public static void main(String[] args) {
    new SendMail();
  }

  public SendMail() {
    String toAddress = "recipient@you.com";
    String fromAddress = "from@me.com";

    Properties properties = System.getProperties();
    properties.setProperty("mail.smtp.host", "smtp.website.net");

    // Create a session object with our above properties
    Session session = Session.getDefaultInstance(properties);

    try {
      // Create a MimeMessage object.
      MimeMessage message = new MimeMessage(session);

      message.setFrom(fromAddress);
      message.addRecipient(Message.RecipientType.TO, new InternetAddress(toAddress));
      // Add TO, CC or BCC addresses as needed...

      message.setSubject("This is a subject for my e-mail...");
      message.setText("This is the body of my message...\n\nSincerely yours,\n\n\nTom");

      // Actually end the message...
      Transport.send(message);
      System.out.println("Message has been sent");
    } catch (MessagingException e) {
      e.printStackTrace(System.err);
    }
  }
}

Enjoy!

PHP7: Generate secure password based on a string of allowed characters

There are quite some easy implementations out there to generate a secure random string in PHP, most of them by encoding a binary string using Base64 or bin2hex. However, this limits the characters used in your password (Base64 = A-Z, a-z, 0-9 and + and /; bin2hex = 0-9 and a-f).

 

Here I’ll share my solution to generate a secure password (requires PHP 7) based on a predefined character string. This leaves you the option to add complex characters (*/-+%{}&@# etc) or leave out similarly readable ones (O and 0, I and l,…).

$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789*/-+[]{}&#';
$pass = '';
for ($x=0; $x<24; $x++) {
  $pass .= $chars[hexdec(bin2hex(random_bytes(1)))%strlen($chars)];
}

You can modify the length of your password by changing the 24 into anything desired, and adding or removing characters from the $chars string.

MOSUNX USB-C to 3 Port USB 3.0 + Hub Ethernet Adapter – Cable not connected (Ubuntu 16.04)

Lately I bought a “MOSUNX Futural Digital USB C to 3 Port USB 3.0 Hub 10/100/1000 Gigabit Ethernet Adapter” over AliExpress. It’s available under different names and similar descriptions (Malloom, BGEKTOTH, iMice,…).

About the device itself: it seems to get pretty hot and experience disconnections on the network part (because of that?), so I don’t necessarily recommend it.

However the main issue was that it initially wasn’t working as should on my Dell XPS 13 with Ubuntu 16.04. The device was properly recognised, but it kept showing ‘Cable disconnected’ (which was obviously incorrect). The USB hub worked fine at the same time.

It took me a little time to figure it out correctly, so I wanted to share the solution with you.

First of all, the adapter does show up nicely (among others):

> lsusb
Bus 004 Device 002: ID 05e3:0612 Genesys Logic, Inc. 
Bus 003 Device 002: ID 05e3:0610 Genesys Logic, Inc. 4-port hub

It seemed a driver issue, currently unresolved. So I downloaded the latest Linux driver for the RTL8153 chipset from RealtekLink here (I downloaded version “LINUX driver for kernel up to 4.8”, 2.08.0)

This actually downloads you a .bz2 file (in my case 0007-r8152.53-2.08.0.bz2) which contains another file without extension (which appeared to be a .tar file).

Uncompressing the .bz2 resulted in a file named 0007-r8152.53-2.08.0 which I renamed into 0007-r8152.53-2.08.0.tar

After uncompressing this tar into a directory of your choice:

> make
> sudo make install

The connection neatly started to show up as should, properly showing a connected cable and functioning.

DHCP and static IP on a single interface: static IP disappears

I recently migrated my Ubuntu Server to an OpenStack environment. I needed two different IP-addresses, and it seemed me wise to keep the first (primary) IP-address assigned by DHCP, and then the second one static.

 

Due to apparent OpenStack restrictions at my current provider, the easiest way was to assign both IP-addresses to the same adapter. As such, I configured them as follows (/etc/network/interfaces):

auto eth0
iface eth0 inet dhcp

iface eth0 inet static
 address <IP-address>
 netmask 255.255.255.0
 broadcast <broadcast address>

 

That seemed to work all fine, and ip address show properly displayed both addresses. Both could be used by Apache, Postfix,…

 
However, after irregular intervals, my webserver seemed to get disconnected. Rebooting the machine solved the issue until the next occurence. Restarting Apache, MySQL,… didn’t seem to help however, so they weren’t the culprit. Restarting only the network interface(s) however did the trick, so it had to do with the network setup. The static IP address seemed to disappear from the adapter, it wasn’t showing up anymore at all.

 

The problem was lying with the DHCP Client, who seemed to reconfigure the interface at certain times, getting rid of the static IP address.

 

As suggested by some forums, I added an alias section to my dhclient.conf (in /etc/dhcp/). This however produced issues upon restarting the network interfaces: ifup[2309]: RTNETLINK answers: File exists

 

The solution was to configure my setup as follows (note the things in bold):

auto eth0 eth0:0
iface eth0 inet dhcp

iface eth0:0 inet static
 address <IP-address>
 netmask 255.255.255.0
 broadcast <broadcast address>

 

This actually solved the problem, without struggling with OpenStack, the DHCP client or having to reconfigure my Apache, Postfix, etc.

MySQLTuner on 16.04: ERROR 1054 (42S22) at line 1: Unknown column ‘password’ in ‘where clause’

When running MysqlTuner on Ubuntu 16.04, you might see the error “ERROR 1054 (42S22) at line 1: Unknown column ‘password’ in ‘where clause'”, since Debian hasn’t updated his package yet (the fix has been implemented in later versions of MysqlTuner).

 

The root cause of this issue is the fact that MySQL changed the name of its password column in mysql.user from password to authentication_string.

 

To ‘temporarily’ fix this, you can change the few entries (8 in total) containing ‘password’ into ‘authentication_string’ manually.

  • sudo nano /usr/bin/mysqltuner
  • 2 entries to change under # Looking for Empty Password
  • 3 entries under # Looking for User with user/ uppercase /capitalise user as password
  • 3 entries under # Looking for User with user/ uppercase /capitalise weak password

Just be sure to leave the PASSWORD() function untouched. They will all be left hand assignments (password = or password IS NULL) or in the clause (password as Binary)