Home Blog Page 420

Migrating to Linux: The Command Line

This is the fourth article in our series on migrating to Linux. If you missed the previous installments, we’ve covered Linux for new users, files and filesystems, and graphical environments. Linux is everywhere. It’s used to run most Internet services like web servers, email servers, and others. It’s also used in your cell phone, your car console, and a whole lot more. So, you might be curious to try out Linux and learn more about how it works.

Under Linux, the command line is very useful. On desktop Linux systems, although the command line is optional, you will often see people have a command line window open alongside other application windows. On Internet servers, and when Linux is running in a device, the command line is often the only way to interact directly with the system. So, it’s good to know at least some command line basics.

In the command line (often called a shell in Linux), everything is done by entering commands. You can list files, move files, display the contents of files, edit files, and more, even display web pages, all from the command line.

If you are already familiar with using the command line in Windows (either CMD.EXE or PowerShell), you may want to jump down to the section titled Familiar with Windows Command Line? and read that first.

Navigating

In the command line, there is the concept of the current working directory (Note: A folder and a directory are synonymous, and in Linux they’re usually called directories). Many commands will look in this directory by default if no other directory path is specified. For example, typing ls to list files, will list files in this working directory. For example:

$ ls

Desktop Documents Downloads Music Pictures README.txt Videos

The command, ls Documents, will instead list files in the Documents directory:

$ ls Documents

report.txt todo.txt EmailHowTo.pdf

You can display the current working directory by typing pwd. For example:

$ pwd

/home/student

You can change the current directory by typing cd and then the directory you want to change to. For example:

$ pwd

/home/student

$ cd Downloads

$ pwd

/home/student/Downloads

A directory path is a list of directories separated by a / (slash) character. The directories in a path have an implied hierarchy, for example, where the path /home/student expects there to be a directory named home in the top directory, and a directory named student to be in that directory home.

Directory paths are either absolute or relative. Absolute directory paths start with the / character.

Relative paths start with either . (dot) or .. (dot dot).  In a path, a . (dot) means the current directory, and .. (dot dot) means one directory up from the current one. For example, ls ../Documents means look in the directory up one from the current one and show the contents of the directory named Documents in there:

$ pwd

/home/student

$ ls

Desktop Documents Downloads Music Pictures README.txt Videos

$ cd Downloads

$ pwd

/home/student/Downloads

$ ls ../Documents

report.txt todo.txt EmailHowTo.pdf

When you first open a command line window on a Linux system, your current working directory is set to your home directory, usually: /home/<your login name here>. Your home directory is dedicated to your login where you can store your own files.

The environment variable $HOME expands to the directory path to your home directory. For example:

$ echo $HOME

/home/student

The following table shows a summary of some of the common commands used to navigate directories and manage simple text files.

Searching

Sometimes I forget where a file resides, or I forget the name of the file I am looking for. There are a couple of commands in the Linux command line that you can use to help you find files and search the contents of files.

The first command is find. You can use find to search for files and directories by name or other attribute. For example, if I forgot where I kept my todo.txt file, I can run the following:

$ find $HOME -name todo.txt

/home/student/Documents/todo.txt

The find program has a lot of features and options. A simple form of the command is:
find <directory to search> -name <filename>

If there is more than one file named todo.txt from the example above, it will show me all the places where it found a file by that name. The find command has many options to search by type (file, directory, or other), by date, newer than date, by size, and more. You can type:

man find

to get help on how to use the find command.

You can also use a command called grep to search inside files for specific contents. For example:

grep "01/02/2018" todo.txt

will show me all the lines that have the January 2, 2018 date in them.

Getting Help

There are a lot of commands in Linux, and it would be too much to describe all of them here. So the next best step to show how to get help on commands.

The command apropos helps you find commands that do certain things. Maybe you want to find out all the commands that operate on directories or get a list of open files, but you don’t know what command to run. So, you can try:

apropos directory

which will give a list of commands and have the word “directory” in their help text. Or, you can do:

apropos "list open files"

which will show one command, lsof, that you can use to list open files.

If you know the command you need to use but aren’t sure which options to use to get it to behave the way you want, you can use the command called man, which is short for manual. You would use man <command>, for example:

man ls

You can try man ls on your own. It will give several pages of information.

The man command explains all the options and parameters you can give to a command, and often will even give an example.

Many commands often also have a help option (e.g., ls –help), which will give information on how to use a command. The man pages are usually more detailed, while the –help option is useful for a quick lookup.

Scripts

One of the best things about the Linux command line is that the commands that are typed in can be scripted, and run over and over again. Commands can be placed as separate lines in a file. You can put #!/bin/sh as the first line in the file, followed by the commands. Then, once the file is marked as executable, you can run the script as if it were its own command. For example,

--- contents of get_todays_todos.sh ---

#!/bin/sh

todays_date=`date +"%m/%d/%y"`

grep $todays_date $HOME/todos.txt

Scripts help automate certain tasks in a set of repeatable steps. Scripts can also get very sophisticated if needed, with loops, conditional statements, routines, and more. There’s not space here to go into detail, but you can find more information about Linux bash scripting online.

Familiar with Windows Command Line?

If you are familiar with the Windows CMD or PowerShell program, typing commands at a command prompt should feel familiar. However, several things work differently in Linux and if you don’t understand those differences, it may be confusing.

First, under Linux, the PATH environment variable works different than it does under Windows. In Windows, the current directory is assumed to be the first directory on the path, even though it’s not listed in the list of directories in PATH. Under Linux, the current directory is not assumed to be on the path, and it is not explicitly put on the path either. Putting . in the PATH environment variable is considered to be a security risk under Linux. In Linux, to run a program in the current directory, you need to prefix it with ./ (which is the file’s relative path from the current directory). This trips up a lot of CMD users. For example:

./my_program

rather than

my_program

In addition, in Windows paths are separated by a ; (semicolon) character in the PATH environment variable. On Linux, in PATH, directories are separated by a : (colon) character. Also in Linux, directories in a single path are separated by a / (slash) character while under Windows directories in a single path are separated by a (backslash) character. So a typical PATH environment variable in Windows might look like:

PATH="C:Program Files;C:Program FilesFirefox;"
while on Linux it might look like:
PATH="/usr/bin:/opt/mozilla/firefox"

Also note that environment variables are expanded with a $ on Linux, so $PATH expands to the contents of the PATH environment variable whereas in Windows you need to enclose the variable in percent symbols (e.g., %PATH%).

In Linux, options are commonly passed to programs using a – (dash) character in front of the option, while under Windows options are passed by preceding options with a / (slash) character.  So, under Linux, you would do:

a_prog -h

rather than

a_prog /h

Under Linux, file extensions generally don’t signify anything. For example, renaming myscript to myscript.bat doesn’t make it executable. Instead to make a file executable, the file’s executable permission flag needs to be set.  File permissions are covered in more detail next time.

Under Linux when file and directory names start with a . (dot) character they are hidden. So, for example, if you’re told to edit the file, .bashrc, and you don’t see it in your home directory, it probably really is there. It’s just hidden. In the command line, you can use option -a on the command ls to see hidden files. For example:

ls -a

Under Linux, common commands are also different from those in the Windows command line. The following table that shows a mapping from common items used under CMD and the alternative used under Linux.

AWS Lambda and the Spectrum of Compute

Amazon fully understand the reality of the compute spectrum, but they are also completely focused on making it easier and easier to begin new development projects on Lambda for a wide variety of scenarios. This makes perfect sense, as we noted previously Serverless is volume compute for a new generation of applications, with significant upside for the providers in usage of adjacent services, and also an efficient disruptor of established processes.

Additionally, by expanding the various entry points to the Serverless paradigm for developers, via routes such as AWS DeepLensAWS Greengrass and so forth, Amazon are focusing minds on the end product required rather than solving for the underlying operational complexity.

Read more at RedMonk

General Data Protection Regulation: A Checklist to Compliance

The General Data Protection Regulation (GDPR) is perhaps the most sweeping data privacy law in history. Within its nearly 100 articles, it outlines new requirements for organizations that have access to the personal information of European Union (EU) citizens, giving average consumers far more power over how their data is used.

Failure to comply will mean heavy fines of approximately $24 million (€20 million), or 4% of a company’s global annual revenue — whichever is greater.

Despite the passing of this regulation in 2016, many businesses still don’t consider it a priority. This is particularly true of U.S.-based organizations, some of which don’t even realize they’re required to comply.

Read more at HPE

Linux Kernel Developer: Julia Lawall

A kernel that has had nearly 83,000 patches applied will certainly have a few bugs introduced along with the new features, states the 2017 Linux Kernel Development Report, written by Jonathan Corbet and Greg Kroah-Hartman.

To find and report those bugs, Linux kernel developers depend on a wide community of testers. And, according to convention, when a bug-fixing patch is applied to the kernel, it should contain a “Reported-by” tag to credit the tester who found the problem. During the period covered by the most recent report, more than 4,100 patches carried such tags, and the top 21 bug reporters are shown in the table at right.

Read more at The Linux Foundation

Securing the Linux Filesystem with Tripwire

Linux users need to know how to protect their servers or personal computers from destruction, and the first step they need to take is to protect the filesystem.

In this article, we’ll look at Tripwire, an excellent tool for protecting Linux filesystems. Tripwire is an integrity checking tool that enables system administrators, security engineers, and others to detect alterations to system files. Although it’s not the only option available (AIDE and Samhain offer similar features), Tripwire is arguably the most commonly used integrity checker for Linux system files, and it is available as open 

Read more at OpenSource.com

Meltdown and Spectre Fallout Leads to First RC9 of a Linux Kernel Since 2011

In an almost unprecedented move, Linus Torvalds has delayed the release of a final build of the Linux Kernel 4.15, instead announcing an unusual ninth release candidate, the first time he had felt he has to do so since 2011.

And you can be fairly sure that Torvalds is not happy with the release because everyone has been busy dealing with the fallout from Meltdown and Spectre, even though the impact on Linux is minimal.

Read more at The Inquirer

How to Create a Docker Image

In the previous article, we learned about how to get started with Docker on Linux, macOS, and Windows. In this article, we will get a basic understanding of creating Docker images. There are prebuilt images available on DockerHub that you can use for your own project, and you can publish your own image there.

We are going to use prebuilt images to get the base Linux subsystem, as it’s a lot of work to build one from scratch. You can get Alpine (the official distro used by Docker Editions), Ubuntu, BusyBox, or scratch. In this example, I will use Ubuntu.

Before we start building our images, let’s “containerize” them! By this I just mean creating directories for all of your Docker images so that you can maintain different projects and stages isolated from each other.

$ mkdir dockerprojects

cd dockerprojects

Now create a Dockerfile inside the dockerprojects directory using your favorite text editor; I prefer nano, which is also easy for new users.

$ nano Dockerfile

And add this line:

FROM Ubuntu

m7_f7No0pmZr2iQmEOH5_ID6MDG2oEnODpQZkUL7

Save it with Ctrl+Exit then Y.

Now create your new image and provide it with a name (run these commands within the same directory):

$ docker build -t dockp .

(Note the dot at the end of the command.) This should build successfully, so you’ll see:

Sending build context to Docker daemon  2.048kB

Step 1/1 : FROM ubuntu

---> 2a4cca5ac898

Successfully built 2a4cca5ac898

Successfully tagged dockp:latest

It’s time to run and test your image:

$ docker run -it Ubuntu

You should see root prompt:

root@c06fcd6af0e8:/# 

This means you are literally running bare minimal Ubuntu inside Linux, Windows, or macOS. You can run all native Ubuntu commands and CLI utilities.

vpZ8ts9oq3uk--z4n6KP3DD3uD_P4EpG7fX06MC3

Let’s check all the Docker images you have in your directory:

$docker images


REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

dockp               latest              2a4cca5ac898        1 hour ago          111MB

ubuntu              latest              2a4cca5ac898        1 hour ago          111MB

hello-world         latest              f2a91732366c        8 weeks ago         1.85kB

You can see all three images: dockp, Ubuntu, and hello-world, which I created a few weeks ago when working on the previous articles of this series. Building a whole LAMP stack can be challenging, so we are going create a simple Apache server image with Dockerfile.

Dockerfile is basically a set of instructions to install all the needed packages, configure, and copy files. In this case, it’s Apache and Nginx.

You may also want to create an account on DockerHub and log into your account before building images, in case you are pulling something from DockerHub. To log into DockerHub from the command line, just run:

$ docker login

Enter your username and password and you are logged in.

Next, create a directory for Apache inside the dockerproject:

$ mkdir apache

Create a Dockerfile inside Apache folder:

$ nano Dockerfile

And paste these lines:

FROM ubuntu

MAINTAINER Kimbro Staken version: 0.1

RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/*


ENV APACHE_RUN_USER www-data

ENV APACHE_RUN_GROUP www-data

ENV APACHE_LOG_DIR /var/log/apache2


EXPOSE 80


CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"] 

Then, build the image:

docker build -t apache .

(Note the dot after a space at the end.)

It will take some time, then you should see successful build like this:

Successfully built e7083fd898c7

Successfully tagged ng:latest

Swapnil:apache swapnil$

Now let’s run the server:

$ docker run –d apache

a189a4db0f7c245dd6c934ef7164f3ddde09e1f3018b5b90350df8be85c8dc98

Eureka. Your container image is running. Check all the running containers:

$ docker ps

CONTAINER ID  IMAGE        COMMAND                 CREATED            

a189a4db0f7 apache "/usr/sbin/apache2ctl"  10 seconds ago

You can kill the container with the docker kill command:

$docker kill a189a4db0f7

So, you see the “image” itself is persistent that stays in your directory, but the container runs and goes away. Now you can create as many images as you want and spin and nuke as many containers as you need from those images.

That’s how to create an image and run containers.

To learn more, you can open your web browser and check out the documentation about how to build more complicated Docker images like the whole LAMP stack. Here is a Dockerfile file for you to play with.  In the next article, I’ll show how to push images to DockerHub.

Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX.

Security with the Trusted Platform Module

The Trusted Platform Module on your computer’s motherboard could lead to better security for your Linux system.

The security of any operating system (OS) layer depends on the security of every layer below it. If the CPU can’t be trusted to execute code correctly, there’s no way to run secure software on that CPU. If the bootloader has been tampered with, you cannot trust the kernel that the bootloader boots. Secure Boot allows the firmware to validate a bootloader before executing it, but if the firmware itself has been backdoored, you have no way to verify that Secure Boot functioned correctly.

This problem seems insurmountable: You can only trust the OS to verify that the firmware is untampered with if the firmware itself has not been tampered with. How can you verify the state of a system without having to trust it first?

Read more at Linux Pro

The Meaning of Open

There are a lot of misconceptions about what open means, when it is the right strategy to apply, and the fundamental tradeoffs that go along with it. It’s very easy to cargo-cult the notion of open — using it in an imprecise or half-baked way that can obscure the real dynamics of an ecosystem, or even lead you in the wrong strategic direction. Here are a few important things to know about openness in the context of ecosystems.

Openness is a spectrum. A thing is not “open” or “closed” — it instead exists upon a spectrum of how open the system is.

Read more at HackerNoon

Unix: Dealing with Signals

On Unix systems, there are several ways to send signals to processes—with a kill command, with a keyboard sequence (like control-C), or through your own program (e.g., using a kill command in C). Signals are also generated by hardware exceptions such as segmentation faults and illegal instructions, timers and child process termination.

But how do you know what signals a process will react to? After all, what a process is programmed to do and able to ignore is another issue.

Read more at Network World