Restart sound service in Ubuntu

The other day my sound stopped working on Ubuntu 18.04 desktop. I have no clue why. The sound stopped working overnight for some reason. After some research I found the below command to restart the sound service on Ubuntu:

pulseaudio -k && sudo alsa force-reload

All works now! Give it a try and let me know if it works for you. Follow me on Twitter @itprohelper

Minicom error “Device /dev/ttyS0 is locked”

Sometimes if the connection to a device via Minicom is lost, the next time you start Minicom you could see an error:

Device /dev/ttyS0 is locked.

The name /dev/ttyS0 may be different, depending on your COM port. To avoid this issue you should always shut down Minicom using CTRL+A keys and then the Q key.

To resolve the issue you can kill the process as a root user. Use the following command in your terminal:

killall -9 minicom

In Ubuntu is similar. Run the command in your terminal using sudo:

sudo killall -9 minicom

You can also try to delete the file:

LCK..ttyS0 in the /var/lock directory.

That was all for me! Hope this little tutorial was useful. If you like to learn more about networking check out this book CompTIA Network+ Certification All-in-One Exam Guide, Seventh Edition (Exam N10-007)

How to run Ansible when Python not installed on Ubuntu EC2

I started an Ubuntu EC2 the other day hoping to run Ansible on it and was surprised that Python was not installed. A requirement for Ansible to run on target machines is to have a modern version of Python.

You can just run sudo apt install python but this is not ideal if you need to install python on let’s say 200 Ubuntu Servers.

The raw module to the rescue

Before writing the playbook, you will need to make minor changes to how Ansible connects to remote hosts.

Create a new file in your current directory and call it ansible.cfg. This file will override settings in the default /etc/ansible/ansible.cfg. Example:

inventory = hosts
remote_user = ubuntu
# Use the below if you’re connecting for the first time
host_key_checking = False
# Location of your .pem you got from AWS
private_key_file = ~/.ssh/yourkey.pem

Now create a hosts file:

[ubuntu_server] # This is a sample IP address. Use your IP.

The playbook using the raw module

This playbook will install python on the target host Ubuntu EC2 server:

- hosts: ubuntu_server
become: yes
gather_facts: no
- name: 'install python'
raw: 'sudo apt -y install python'

Breaking Up Long Lines in Your Dockerfile

I try to limit my line characters to 79-80 per line. For example check this 122 character multi-command line:

RUN wget -O afile.tar.gz && tar -xvf afile.tar.gz -C /usr/src/myapp && rm afile.tar.gz

You will need to scroll horizontally using your text editor to see the super long crazy line. This is not efficient and also creates a mess when you or someone else needs to review your code.

Below is the same command broken into multiple lines:

RUN wget -O afile.tar.gz \
    && tar -xvf afile.tar.gz -C /usr/src/myapp \
    && rm afile.tar.gz

So neat and comfortable to read now! You just need to use a backslash ‘ \ ‘ to break up lines. Enjoy!

Using .gitignore examples

A .gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Normally, this is placed in the root directory of your repository. This is the recommended way. The patterns in the .gitignore file are relative to the location of the file.

File names

Easiest pattern is a literal file name:


This will ignore any files named .DS_Store which is common in MacOS.


You can ignore entire directories by including their paths and putting a / at the end:


If you leave the slash ‘ / ‘ at the end you will match both directories and file names.

GREP command overview

The grep command means Global Regular Expression Print. This Linux command is one of the most useful commands out there. Below are some basic examples:

grep 'word' filename
grep 'word' filename1 filename2 filename3
grep 'string1' string2' filename
cat filename | grep 'something'
command | grep 'something'

Next example, you can search for the user ‘tom’ in the Linux passwd file:

grep tom /etc/passwd

You can instruct grep to ignore word case. Match abc, Abc, ABC and all possible combinations:

grep -i "tom" /etc/passwd

How to change the default SSH port in MacOS using Terminal

This is simple. Open a terminal and follow the steps below. This worked for me on MacOS 10.13.6

  • Open the Terminal.
  • Run sudo vim /etc/services
  • Enter your password
  • Find the lines assigned to port 22, something like the image below

Replace both ports 22 with your desired ssh port using a number between 1024 and 32,767

Now you need to restart the services. Be sure to do this if you have direct access to the console for your MacOS. If you do it remotely you may loose connection. I could not find a way to ‘restart’ a service on MacOS as we normally do in Linux. You have to ‘unload’ and ‘load’ the service in MacOS. Use the below commands.

sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

Now you can SSH using:

ssh <youruser>@<yourHostOrIP> -p <yourNewPort>
For example: ssh john@localhost -p 18765

Hope this small post was useful. If you like to learn more about MacOS you can grab this book MacOS and iOS Internals, Volume I: User Mode (v1.3)

Linux df command line brief examples

df is a Linux command for for reporting file system disk usage on a Linux system. While brewing coffee at home I found the following.

How to view disk usage using df command? Simple!

Simplest way is just to type df on the command line and you should get the below output:

 Filesystem     1K-blocks    Used Available Use% Mounted on
 overlay         61252420 9817828  48293424  17% /
 tmpfs              65536       0     65536   0% /dev
 tmpfs            1023564       0   1023564   0% /sys/fs/cgroup
 shm                65536       0     65536   0% /dev/shm
 /dev/sda1       61252420 9817828  48293424  17% /etc/hosts
 tmpfs            1023564       0   1023564   0% /proc/acpi
 tmpfs            1023564       0   1023564   0% /sys/firmware 

Columns explanation:

  • Filesystem – the filesystem on the machine
  • 1K-blocks – the size of the filesystem in 1K blocks
  • Used – the amount of space used in 1K blocks
  • Available – the amount of available space in 1K blocks
  • Use% – the percentage that the filesystem is in use.
  • Mounted on – where the filesystem is mounted.

Using the Linux df command ff you like to view the output in human readable use df -H

To show the filesystem type use df -T

To show only specific file system types use df -t ext4 as an example.

Runlevels Linux Learn more simple table

Hola! Each runlevel has a certain number of services stopped or started, giving the user control over the behavior of the machine. Conventionally, seven runlevels exist, numbered from zero to six. While brewing coffee at home I found the difference between runlevels in Linux. See below.

0HaltShuts down the system.
1Single-user modeDoes not configure network interfaces, start daemons or allow non-root logins.
2Multi-user modeDoes not configure network interfaces or start daemons.
3Multi-user mode with NetworkingStarts the system normally.
4UndefinedNot used.
5X11 (GUI)As runlevel 3 plus display manager.
6RebootReboots the system.