I’m using Docker, I’m a Windows developer, oh …. a Linux prompt — what do I do next?

Ian Pender
Sep 4, 2018 · 5 min read

Huddle is progressing through a microservices journey. Like most .Net developers, our enginners are Windows natives. The use of containers means interacting with the mystical and arcane world of Linux…

This post will detail key concepts of the Linux Operating Systems and cover the various spells and incantations to make this strange world more familiar.

We’ll cover:

  • Linux origins and distributions
  • Package management
  • File System
  • Permissions
  • Daemons/Services
  • Support-like Tasks

I’m using Docker ….

Photo by John Fornander on Unsplash

I’m a Windows developer ….

Wikimedia Commons by David Shankbne

Oh sh*t. It’s a Linux prompt ….

“boy wearing gray vest and pink dress shirt holding book” by Ben White on Unsplash

Linux: Origins and Distributions

Windows was first released in 1985. But Linux is based on something a little older….

Unix originated in the 1970s at AT&T by researchers creating a multi-user operating system.

GNU is an operating system and an extensive collection of computer software. GNU is composed wholly of free software, most of which is licensed under the GNU Project’s own General Public License. — wikipedia

Founded by Richard Stallman (a force for good) with totally free tools. Whilst the tools were good, the core of the operating system wasn’t ready and was overshadowed by free Unix and Linux.

Linux is a family of free and open-source software operating systems built around the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds — wikipedia.

Linux and UNIX are often used as an OS in cloud and virtual computing due to their resource efficiency and cost.

Distributions

A Linux distribution (often abbreviated as distro) is an operating system made from a software collection, which is based upon the Linux kernel and, often, a package management system. — wikipedia

Here are some popular distributions:

Debian — released in 1993 was one of the earliest operating systems based on the Linux kernel and is composed entirely of free software.

Ubuntu — in 2004 Canonical Ltd released an easier-to-use version of Debian with added proprietary software. It’s the most popular Linux distribution.

Alpine Linux is primarily designed for “power users who appreciate security, simplicity and resource efficiency”.

The following examples use Ubuntu. Some of the commands will require an alternative on other distributions.


Package Management

Software can be installed, on Linux, by issuing commands in a terminal to fetch and install packages from the Internet.

Ubuntu uses the APT (Advanced Packaging Tool) command-line package management system that is a front end for dpkg package management system.

Other distros may use a different system, e.g. Alpine uses APK.

Using apt-get to install nginx, update the repository list, and upgrade

This central repository of software ensures that software is invariably easier to obtain, has greater consistent and less likely to contain mallware.


File System

In the Linux OS, everything is a file and every file has its place. This simple idea is one of the keys to understanding UNIX-like systems, as *everything* is a file:

  • Socket / networking communications — includes connection and transport state
  • Process information — lists process information, including environmental variables
  • Uptime — and other system information
  • ANY state whatsoever

Learning some of the standard locations helps a Linux User look proficient. Changing to a well-known location and viewing the contents of a file is the standard method of performing User and Admin tasks, including:

  • Configuring and control a system service
  • View user data files
  • View process logs
Standard File System Hierarchy

As Linux is centred around the file-system, navigation around, searching for and viewing the contents of files is essential:

change directory, list file contents, end of file contents, find a pattern in a path and find 1gb files in

Permissions

1 — Everything in UNIX is a file system object.
2 — UNIX processes are small, focused applications

Therefore permissions are important, as applications invariably pass state to each other, and along a command pipeline, using files. Moreover UNIX is usually more secure than Windows as:

  • In UNIX nothing runs under root
  • With Windows (almost) everything runs under root

There are 3 user-based permission groups:

  • Owner
  • Group
  • All users

Each can possess a combnation of 3 permission types to describe access permissible for each file:

  • Read
  • Write
  • Execute
Permission umask explanation

By listing the contents of a directory, we can view the absence/presence of the above bit-mask to describe the permissions of each file.

switch to root interactive, switch user, change permissions to add read, write, execute for all on file, change permissions to add write access to the group, change ownership

Daemons/Services

A daemon is a system service that runs as a background process, rather than being under the direct control of an interactive user.

The various linux distributions contain different methods of ‘daomnising’ an application:

init.d

  • Original daemon from UNIX (System V)
  • More complicated setup, and used mostly by historic applications

upstart

  • Ubuntu created init daemon
  • More simple than init.d but limited to Ubtuntu-falvoured distributions

systemd

  • The newest daemon across most linux distros
  • Not available everywhere.

supervisor

  • Python-based daemon
start/stop/restart commands for init.d / upstart / systemd controlled daemons

Support-like Tasks

‘DevOps’ or support-like tasks invariably require a number of commands to be executed in a shall, network traffic to be inspected and permissions to be checked.

shell

Unix has a number of alternative shells available….

  • Windows — cmd / powershell
  • UNIX — bash / ksh / csh / zsh

bash session

Bash / shell sessions have important differences. Especially directory paths and line endings in text files

  • Environmental variables
  • Path —separated using ‘/’ rather than ‘\’ in Windows
  • Line endings — uses a single LF (char 10) rather than CR and LF in Windows (char 13 and char 10)

Check network calls

  • Ensure we can request from a URI
  • View IP addresses
  • See open ports
  • Watch files in use
  • Inspect firewall rules
request response from a URL, view ip addresses, view open netowrk ports, view open file handlers, piping some commands together

Check running processes and help

list running processes, kill a process by id, help pages for ps x 2
  • pid files — as everything is a file, checking a state involves checking the relevant directory /proc/<pid> or running a command, ps
  • man pages — UNIX-like systems contain comprehensive help systems

Check Permissions

A Linux User must frequently check permissions for deployed files.

check groups for a user (via command and file), list the UNIX hierarchy, test file creation permissions

This post doesn’t list every setting or arcane script available in Linux. However, hopefully the mysterious differences between Linux and Windows are a little more familiar.

Move to a containerised world will lead to a standardisation of OS services. As such knowing our way around different hosts and infrastructure will become ever more important.

Ian Pender

Written by

Application Architect at Huddle

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade