How to use screen command to avoid unexpected ssh session termination

SSH disconnection problem

Your terminal session may get closed due to various network issues while you are
running a process on a remote machine eg.:

# Write failed: Broken pipe

As the result of this network disconnection your ssh shell session will also inadvertently kill any child processes run under your ssh session on the remote machine.

Running an uninterrupted SSH session solution

Use the screen command to save the session. While your SSH session gets disconnected the screen command will keep your remote process running. Consider a following SSH example where we attempt to SSH from a local host 10.1.1.2 to remote 10.1.1.15 host.

Screen Command SSH Example

Let’s start by listing our currently opened screen sessions:

local> $ screen -list
No Sockets found in /var/run/screen/S-lubos.

Read more

fatal: the Postfix mail system is already running – Solution

Symptoms:
The following error message appears when starting postfix daemon:

# service postfix start 
Starting Postfix Mail Transport Agent: postfixpostfix/postfix-script:
fatal: the Postfix mail system is already running
 failed!

Furthermore, a postfix daemon status reports that postfixis not running:

# service postfix status
postfix is not running.

Read more

How to run your own local private Docker registry

In this config we will show how to run a local Docker registry on a local network. We assume that the host which will run Docker registry has the Docker already installed and can be accessed either via hostname or IP address. Alternatively, you can run your local Docker registry on a local system using 127.0.0.1 or localhost In our scenario we will run docker on host: linuxconfig.docker.local. Let’s start by running a Docker registry container on linuxconfig.docker.local host:

# docker run -d -p 5000:5000 registry
e6f9480e94ea30a4a400f499b9e28dfac87ccd3ccb59627e78fe784249248127

Read more

MySQL ERROR 1045 (28000): Access denied for user ‘root’ – Solution

Symptom:

Unable to access MySQL database remotely using root account. Any attempt to access MySQL database will result in error:

ERROR 1045 (28000): Access denied for user 'root'@'ip-address' (using password: YES)

Solution:

The above MySQL error message is a default behavior of the MySQL server to disallow a Root user to connect remotely as by default the Root user is allowed to connect to MySQL server on from localhost that is 127.0.0.1. The solution is to create a new admin user. The below SQL commands will create new user called admin and grant remote access:

mysql> CREATE USER 'admin'@'%' IDENTIFIED BY '';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

Read more

ERROR 2003 (HY000): Can’t connect to MySQL server on (111) – Solution

Symptom:

The error message:

ERROR 2003 (HY000): Can't connect to MySQL server on 'IP address' (111)

Appears white an attempt to connect to MySQL server remotely.

Solution:

By default the MySQL server is configure to disallow any remote access. The only accepted connection are allowed from the localhost thus 127.0.0.1 IP address. This configuration can be found in main MySQL configuration file /etc/mysql/my.cnf:

bind-address           = 127.0.0.1

Read more

How to copy files from host system to a docker container using netcat

A simple way to copy files from the docker’s host system to a docker container is by using netcat command. First make sure that nc command is available within your docker container by installation of nectcat package. In the following scenario we are going to transfer file myfile.txt to a docker container with a container ID eg.e350390fd549.

Destination Docker Container

First, using interactive shell within a docker container execute nc command to listen on some arbitrary port which will be used to receive file. In this case the port number is 7555:

root@e350390fd549:~# nc -l -p 7555 > /root/myfile.txt

Read more

How to retrieve Docker container’s internal IP address

Let’s say that we have a Docker container running on our system with a container ID e350390fd549 I would like to obtain its internal IP address. First, and recommended method is do use docker inspect command. The following linux command will print detailed information about your Docker container including its internal IP address:

# docker inspect e350390fd549
...
    "NetworkSettings": {
        "Bridge": "docker0",
        "Gateway": "172.17.42.1",
        "GlobalIPv6Address": "",
        "GlobalIPv6PrefixLen": 0,
        "IPAddress": "172.17.0.2",
        "IPPrefixLen": 16,
        "IPv6Gateway": "",
        "LinkLocalIPv6Address": "fe80::42:acff:fe11:2",
        "LinkLocalIPv6PrefixLen": 64,
        "MacAddress": "02:42:ac:11:00:02",
        "PortMapping": null,
        "Ports": {}
...

Read more

How to remove a docker container on Linux

Docker comes with its own rm command version to assist with docker container removal. Let’s first list all available docker containers:

# docker ps -a    
CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS              PORTS               NAMES
d1c01c8eb336        ubuntu:14.04        "/bin/bash"            5 seconds ago        Exited (0) 3 seconds ago                            ubuntu
df7834f86c78        debian:stable       "/bin/bash"            10 seconds ago      Up 9 seconds                            debian              
9bdd9d49a75b        mongo:3             "/entrypoint.sh mong   18 minutes ago      Up 18 minutes       27017/tcp           mongodb             
774b02c9c51a        oraclelinux:7       "/bin/bash"            27 minutes ago      Up 27 minutes                           oracle7

Docker’s rm command will by default remove only stopped containers and thus any attempt to remove a running docker container will result in error message:

# docker rm debian
Error response from daemon: Conflict, You cannot remove a running container. Stop the container before attempting removal or use -f
FATA[0000] Error: failed to remove one or more containers

Read more

How to list available docker containers using ps command on Linux

When having a multiple docker containers docker’ ps command can be useful to provide an information about all available docker containers residing on the system. By default docker ps will list all currently running containers on the system:

# docker ps
CONTAINER ID IMAGE        COMMAND      CREATED      STATUS       PORTS        NAMES
b45f66998a4f ubuntu:14.04 "/bin/bash"  9 minutes agoUp 9 minutes              cocky_jang

Read more

Change default python version on Raspbian GNU/Linux

In order to change to default python version on your Raspbian GNU/Linux first list all available python versions:

# ls /usr/bin/python*
/usr/bin/python  /usr/bin/python2  /usr/bin/python2.7  /usr/bin/python3  /usr/bin/python3.2  /usr/bin/python3.2mu  /usr/bin/python3mu

Your output may be different. If the version you are looking for is not available then use apt-get command to install it. eg. apt-get install python3
Next setup alternatives:

# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
# update-alternatives --install /usr/bin/python python /usr/bin/python3.2 2
update-alternatives: using /usr/bin/python3.2 to provide /usr/bin/python (python) in auto mode

Read more

Raspbian GNU/Linux upgrade from Wheezy to Raspbian Jessie 8

The upgrade from Raspbian Wheezy to Raspbian 8 Jessie is a fairly simple procedure. However, a caution must be exercised as there is always a chance to break the entire system. The less packages and services are installed the more likely you will be able successfully upgrade your Raspbian Linux system.

Recommendations:

  • Remove unnecessary packages
  • Fully upgrade your current system
  • Make a data backup
  • Although there should not be a problem to perform update via SSH it is recommended to perform upgrade directly using console

Read more