Bart Simons


A 3 post collection

Ubuntu Cheat Sheet

 •  Filed under ubuntu, cheat sheet

In need of a handy cheat sheet filled with commands you can use in your Linux terminal? This page has got you covered with lots of commands for lots on different use cases. Missing a command? Feel free to send me your ideas, questions and suggested commands in the comments.

Install a full LAMP stack with just one command
sudo apt install lamp-server^  

Notes: this stack contains PHP5 on Ubuntu 14.04 or lower, and PHP7 on Ubuntu 16.04 or higher. Not tested with non-LTS releases.

Install PhpMyAdmin
sudo apt install phpmyadmin  

Install and configure basic SMB/CIFS shared folder
sudo apt install samba  
sudo smbpasswd -a bart

sudo echo "[bart]" >> /etc/samba/smb.conf  
sudo echo "path = /home/bart" >> /etc/samba/smb.conf  
sudo echo "valid users = bart" >> /etc/samba/smb.conf  
sudo echo "read only = no" >> /etc/samba/smb.conf

sudo service smbd restart  

Install security updates only
sudo unattended-upgrades -d  

Upgrade to the next LTS release
sudo do-release-upgrade  

Cleanup the package database and no longer needed packages
sudo apt autoremove && sudo apt clean && sudo apt autoclean  

List kernel version and Ubuntu release version
uname -a && lsb_release -a  

Edit and update grub settings
sudo nano /etc/default/grub  

Get unique IPs accessing your site

For Apache:

cat /var/log/apache2/access.log | awk '{print $1}' | sort -u  


cat /var/log/nginx/access.log | awk '{print $1}' | sort -u  

Use Ubuntu as a NAT router
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf  
sysctl -p  

Get bash history
cat ~/.bash_history  

Get SSH login attempts that exceed set limits
cat /var/log/auth.log | grep "attempts"  

Get successful local and remote login attempts
cat /var/log/auth.log | grep "systemd-logind"  

Check for open, listening ports
netstat -tulpn  

Get RAM usage information
free -m  

Get processes currently running as root
ps aux | grep "root"  

Stop and start interface
ifconfig eth0 down  
ifconfig eth0 up  

Note: replace eth0 with your desired network interface.

Manually set static IP on interface
ifconfig eth0 netmask broadcast  

Check for running systemd services
systemctl list-units --state=running --type=service  

Check for configuration errors
jounalctl -xe  

Get cron jobs

Hourly cron jobs:

ls /etc/cron.hourly  

Daily cron jobs:

ls /etc/cron.daily  

Weekly cron jobs:

ls /etc/cron.weekly  

Monthly cron jobs:

ls /etc/cron.monthly  

Other cron jobs:

ls /etc/cron.d  

Hardware/software info

List PCI devices:


List block devices:


List USB devices:


List CPU devices


List general HW info


List loaded kernel modules


File/directory creation, parsing and IO

Create new file

touch new.file  

Get contents of file

cat new.file  

Overwrite a file

echo "Hello, dear Linux user!" > new.file  

Append to a file

echo "Hello, dear Linux user!" >> new.file  

Get lines containing a substring

cat new.file | grep "user"  


Set ownership of a folder, recursively:

chown -R www-data:www-data /var/www/html  

Note: this sets the ownership of the /var/www/html folder to the default web server user and group.

Click to close notifications in Ubuntu

 •  Filed under ubuntu, desktop, click to close, notifications

Do you love the way your notifications in the upper right corner of your screen look, but do you hate that there' s no way to close these notifications? Then look no further and read along as this article guides you through the process of 'patching' the notify-osd source code to make notifications clickable.

So, here's a preparation list for this little project:

  • You need a development (virtual) environment, I have chosen for a 16.04 virtual machine
  • You need to run the following commands to get the needed development packages installed on your system:
    • sudo apt install build-essential
    • sudo apt install devscripts
  • You need to uncomment the lines starting with deb-src inside /etc/apt/sources.list to allow source package fetching
  • Update your package cache! (sudo apt update)
  • Create a working directory to work in (I used /home/bart/Documents/notify-osd)
  • Install the build dependencies for sudo with sudo apt build-dep notify-osd

The first thing to do is getting the sources cloned into the working directory with this command

  • apt source notify-osd

Great! Now you can cd into the notify-osd source folder, for example

  • cd notify-osd-0.9.35+16.04.20160415

Now it's time to patch the source code of the bubble.c file inside the src directory.
Replace this block of code

// set an 1x1 input-region to allow click-through 
region = cairo_region_create_rectangle (&rect);  
if (cairo_region_status (region) == CAIRO_STATUS_SUCCESS)  
        gtk_widget_input_shape_combine_region (window, NULL);
        gtk_widget_input_shape_combine_region (window, region);
cairo_region_destroy (region);  

with this

// set an 1x1 input-region to allow click-through 
region = cairo_region_create_rectangle (&rect);  
if (cairo_region_status (region) == CAIRO_STATUS_SUCCESS)  
        gtk_widget_input_shape_combine_region (window, NULL);
        gtk_widget_input_shape_combine_region (window, region);
        GdkWindow *window_ = gtk_widget_get_window (window);
        gdk_window_set_events (window_, gdk_window_get_events (window_) | GDK_BUTTON_PRESS);
cairo_region_destroy (region);  

Replace this block

// hook up window-event handlers to window
g_signal_connect (window,  
                  G_CALLBACK (bubble_draw),

with this

// hook up window-event handlers to window
g_signal_connect (window,  
                  G_CALLBACK (bubble_draw),

g_signal_connect (window,  
                  G_CALLBACK (button_press_event_handler),

Put this function block

static gboolean  
button_press_event_handler (GtkWidget* window G_GNUC_UNUSED,  
        GdkEventButton* event,
        Bubble* bubble)
        BubblePrivate* priv;
        priv = bubble->priv;

        if (priv->mouse_over && event->button == 1)
                bubble_hide (bubble);
                dbus_send_close_signal (bubble_get_sender (bubble),
                        bubble_get_id (bubble),

                g_signal_emit (bubble, g_bubble_signals[TIMED_OUT], 0);

                return TRUE;

        return FALSE;

above this function block

static gboolean  
redraw_handler (Bubble* bubble)  

Save the file, and build a Debian package with debuild -uc -us

This should work! At least it did for me ;)

Modifying sudo to run an executable after successful authentication

 •  Filed under sudo, ubuntu, desktop, notification

So I recently installed Ubuntu on my Intel NUC and one thing that was bugging me out was having to enter my account password everytime when using the sudo command. I already fixed it with the NOPASSWD option for the sudo group. This is not the best solution when it comes to security, as any executable could gain sudo access on my local system. That brought up an idea in my head, namely modifying the sudo codebase so that you get a graphical notification on your screen when someone successfully authenticates with sudo. Here's an example:

Libnotify Notification Test

The utility I used to create this message is notify-send, which comes pre-installed with Ubuntu. So what we want is this command to be launched from the C++ code base so that we get a nice message upon sudo access! Let's begin.

At first, you make sure that you have all necessary development packages installed on your system:

sudo apt install build-essential git

And make sure you have all deb-src sources uncommented in /etc/apt/sources.list. Afterwards make sure to update your package cache again with sudo apt update.

The next step is fetching the sudo source code:

apt source sudo

Good. So the next step is to modify the source code of sudo. More specifically, you need to change one single source code file of the sudoers plugin named sudoers.c which can be found in the following directory:


Open the file in your favorite editor. Search for the function create_admin_success_flag and add the following code at the top of all found function blocks:

popen("/usr/bin/notify-send -i dialog-warning \"Sudo notification\" \"Someone just gained root access!\" --urgency=critical", "r");  

Go back to the sudo source code root directory and run the usual compilation commands:

./configure && make && sudo make install

Enjoy a safer Linux desktop experience!