Learn Basic Linux Commands - Mini Course

Linux is the dominant player in both the data centre and cloud. Linux skill is most for the current Cloud Computing era. In this Mini course, we will cover various topics to get started with the Linux Command line.

What we'll learn

  1. About Linux
  2. Here we will learn about Linux

    1. Linux
    2. Linux History
    3. Linux vs Unix
    4. Linux Distribution
    5. Ways to Practice Linux
  3. Basic Commands
  4. Here we will list some 15 top basic Linux commands. Directory Navigation, Creating Files, Creating Directories, Deleting, Viewing, Editing, Copy, Move and some more

  5. Linux Fundamental Concepts
  6. Here we will Learn about Some Linux Fundamental Concepts

    1. Linux Directory Structure
    2. Command Syntax
    3. Path Name
    4. Permissions
    5. Ownership
    6. File Permissions and Ownership
    7. Permissions on Directories
    8. IO Redirection
    9. Links
    10. Wildcard
  1. Working With Remote System
  2. Here we will learn about SSH. Different approach to SSH. Password-based authentication and SSH key-based authentication

  3. More Linux Commands
  4. We will learn some more commands here.

    1. Text processing
    2. Archiving and Compression
    3. Getting Help
    4. Other Commands and Tips
  5. Bonus
  6. In this Bonus Section, we will try to implement what we have learned so far

    1. Nginx Web Server
    2. Deploy a Simple Website
    3. Get free VPS (Linux server) as a student
  7. Conclusion
  8. About the course and moving ahead


About Linux

Linux

Linux is an open-source operating system. It is also referred to as "GNU/Linux" as Linux is an operating system with a combination of GNU software and Linux kernel.

An operating system is a collection of software that manages hardware resources, schedule tasks and control peripheral devices. An operating system is the system software, that act as an interface between computer hardware and computer application.

Linux is also a Kernel. Actually, Linux is a Kernel and the operating system is GNU/Linux. But we generally refer to Linux as an Operating system and if we need to talk about the kernel, we specify by "Linux Kernal".

A Kernel is the core of the Operating System. The kernel provides API for the software to interact with the computer hardware. For a useful Operating System, we need additional components along with the kernel. Some of them are System Libraries, GUI, Email Utilities, Web Browsers, etc.

Linux was created by Linus Torvalds. During his study at a university, he bought a personal PC that came with MS-DOS Operating System. He wants to use UNIX like Operating systems just as in the University. But they were quite Expensive. Thus he set out to create Linux.

Version 1.0 of Linux Kernel was released in 1994.

Linux is a FOSS (Free / Open Source Software). In every case source code is free, but the binary may not be free. We have to pay a license fee to run Red Hat Linux, and the sources code is available openly.

Linux History

  • 1991: The Linux kernel is publicly announced on 25 August. Version 0.01 is released publicly on 17 September.
  • 1992: The Linux kernel is relicensed under the GNU GPL. The first Linux distributions are created.
  • 1993: Over 100 developers involved. Slackware and Debian project started.
  • 1994: Version 1.0 of Linux Kernel Released in March.

Linux vs Unix

Linux is a clone of UNIX, but it does use any codebase from the UNIX system. Linux runs on any hardware whereas UNIX is typically dedicated to some hardware.

Linux is an Open Source Operating system, whereas UNIX is a proprietary system.

UNIX default shell is Bourne Shell, whereas Linux default shell is BASH Bourne Again Shell.

Linux Distributions

Linux Distributions are the collection of software along with Linux kernel to make an Operating System. Actually, Linux Distributions are Linux OS.

Different Distribution has different goals. Some of them are Commercial while others are None Commercial, maintained by the community.

Some of them are dedicated to Desktop use, whereas some are for server use.

Choice of Linux Distributions. We mainly focus on Red Hat and Ubuntu. Red Hat Enterprise Linux is widely used in banks, Airlines, Telecommunications. Whereas Ubuntu is widely used by startups, companies with SaaS Products, Cloud-Based companies.

I would suggest starting with Ubuntu. If you want to work with the Red Hat system, you can choose CentOS, which is the free version of Red Hat. Linux is Linux, no choice is wrong, you can choose whatever distribution you like.

Ways to Practice Linux

So, How can we practice with Linux? In this section, we will look through various ways we can practice Linux.

One of the best ways to start learning Linux is using Linux on your personal computer. If you can/want to install Linux, I would suggest going with Ubuntu. You can simply download the ios and boot it on your PC. Make sure to take a backup first. As an alternative, you can dual boot with Windows. Whatever you do, learn a lot from online resources on how to safely perform these actions before starting.

If you are using Windows, there are various ways you can test Linux within Windows.

Gitbash, Gitbash is a Windows application, that provides a command-line shell experience. Once you install git on your windows, you will get gitbash. You can try Linux commands here.

WSL, Windows SubSystem for Linux is a compatibility layer for running Linux binary executables natively on Windows. If you are using Windows 10 / Windows 11, I would recommend using WSL. With WSL we can get all the Linux command line experience.

Another option can be using VirtualBox. With Virtual Box, you can install an entire operating system within another OS. If you want to explore the GUI part of Linux as well and are not comfortable yet completely installing Linux as the primary OS, this can be your option to get a hand into Linux and experience it.

Looking for a web-based solution. If you are not comfortable installing any other program in your system, you can experience Linux within your browser as well. There may be multiple options for this, but here we will talk about two.

Google Cloud Console. Google Cloud Platform, is a suite of cloud computing services. You can get a range of cloud solutions from Google Cloud. Along with the services, google provide a Cloud Shell (free to access), where you can practice your Linux as well.

Your 5GB home directory will persist across sessions, but the VM is ephemeral and will be reset approximately 20 minutes after your session ends. No system-wide change will persist beyond that.

Once your Google account is login, you can simply visit https://shell.cloud.google.com/ to start using Google Cloud Shell.

OverTheWire, Wargames, provides a cloud shell to help you to learn and practice security concepts in the form of fun-filled games. You can get started with Bandit, which will provide a Linux system you can ssh to. Once there you can play the game / simply play around with the system. You can access it on https://overthewire.org/wargames/.

Course on Youtube

This entire course is available as video course as well. Here is the course on Youtube.

Basic Linux Commands

So we have learned some basics about Linux, let's now get started with basic commands. Here we will simply list the command and what it does. We will be able to get the most out of it, once we study the Linux Fundamental Concepts in the next section. These listed commands are enough to play around with the Linux system.

The terminal is a program to interact with Linux System. The terminal takes input from users pass it to the shell and displays the output. Terminal, KDE Konsole, XTerm are some of the Terminal Emulators available on Linux.

Shell is a command-line interface that interprets a user's commands. The shell converts the command into a kernel-understandable form and passes it to the kernel to execute it.

Here we will list some of the basic Linux commands, these command helps you to play around with Linux commands. You can start the terminal program and start typing these commands to try yourself. You can start a terminal with Ctrl + Alt + T as well.

ls

ls list, let you list the content on the directory the terminal runs in. It will list all the files and directories.

cd

cd change directory, let you navigate among file system. cd pathname will take you to the path. cd will take you to the home directory. and cd .. will take you a directory back.

pwd

pwd present working directory, prints the current working directory. It will show where we are in the file system.

cat

cat concatenate, prints the content of the file to the standard output. It simply shows the contents of the file in the terminal. cat file.txt will print the contents of file.txt in the terminal.

touch

touch command let you create a file. touch test.txt will create a file called test.txt.

rm

rm remove, let you delete a file. rm test.txt will delete the file called test.txt.

mkdir

mkdir make a directory, let you create a directory. mkdir folder1 will create a directory called folder1.

rmdir

rmdir remove directory, let you delete a directory. rmdir folder1 will delete the directory called folder1.

nano

nano is a command-line text editor. With nano, you can edit a file. You can run a nano program with nano. It will start the nano program, now you can write content there. You can see a bunch of options there. Among them

^O Write Out
means
Ctl + O

to save the file. Now it will as for the file name.

To edit a file called file.txt with nano you can run nano file.txt. If the file provided is not available it will be created on save.

cp

cp copy, let you copy contents. cp source destination. cp file.txt test.txt will copy the contents of file.txt to test.txt. cp file.txt folder/ will copy the file.txt inside a directory called folder.

mv

mv move, let you move contents. mv source destination. mv file.txt test.txt will copy the contents of file.txt to test.txt and delete the file.txt me file.txt folder/ will move the file.txt inside a directory called folder.

file

file file, let you view the details of the file. file test.pdf will print the content type of the file in the terminal.

exit

exit the exit command let you close the terminal. exit If you are working with a remote server, the exit will first close the connection. Then if you want to close you can run the exit again.

clear

clear the clear command lets you clear the terminal. clear will clean the terminal it will be just like it just opened.

history

history the history command list the commands that were being entered in the system. history, It will list the commands those were executed on the system. The latest commands will be on last.

echo

echo the echo command simply echo back what you provided. echo "Hello World" will print back the Hello World message back to the terminal.

man

man manual provides information about the command/program. with man echo you will get manual on the echo command, you can navigate using the up and down arrow. Press q to quiet the view.

Linux Fundamental Concepts

Linux Directory Structure

Here we will look through the Linux file system structure. We will look at what directories are for what purposes and how they are organized.

Filesystem Hierarchy Standard (FHS)

The Filesystem Hierarchy Standard (FHS) defines the main directories and their contents in most Linux. It is a formalization and extension of common UNIX practices. This standard is maintained by The Linux Foundation. The latest version, 3.0, was released on 3 June 2015.

/ Primary hierarchy root and root directory of the entire file system hierarchy.

/bin/, binary, Essential command binaries that need to be available in single-user mode.

/sbin/ system binary, that system administrator uses, a standard user would not have access without the permission.

/lib/ /lib32/ /lib64/ these are where the libraries are stored. Libraries are used by programs to perform various tasks. These are required by binaries in /bin/ and /sbin/

/boot/ it contains everything the OS need to boot. Boot loader files are stored here.

/dev/it's where the devices are. As we know in Linux everything is a file. We will find connected hardware here.

/etc/ this directory is where all the system-wide configurations are stored.

/home/ it contains a directory for individual users. Each user's home directory contains a different configuration for the application. They are stored as hidden files or hidden directories.

/media/ Mount points for removable media and drives.

/mnt/ mounting point for drives.

/opt/ Optional / manually installed application software packages will be here.

/proc/ Virtual filesystem documenting kernel and process status as text files. We find different information there as well cat /proc/cpuinfo for CPU information. cat /proc/uptime which will show the uptime of the current session and the CPU core status.

/root/ home directory for the root user.

/srv/ Site-specific data which is served by the system

/tmp/ Temporary files.

/usr/ this directory store the application used by the user. It has corresponding /usr/bin and /usr/sbin/ and /usr/lib/ directory.

/var/ Variable files, such as logs, spool files. Those files that grow over time.

Command Syntax

Linux command has 3 basic elements

  • command
  • options
  • parameter

A command is split into an array of strings named arguments. Argument 0 is (normally) the command name, argument 1, the first element following the command, and so on. These arguments are sometimes called positional parameters.

the command is the name of the program. eg. ls cd

options usually start with - or --. it is also known as flags. Options modify the way that command works. Options possible values are hardcoded in programs. We can separate commands with spaces or tabs. Single char command can be used together without any separation and - for the first option only.

the parameter is an argument that provides information to either the command or to one of its options

Plenty of commands has no options, no arguments or neither.

Path Name

Linux files are organized within a single-tree hierarchical file system structure made up of files containing data (documents, programs), and directories that may contain other sub-directories and files.

A Linux pathname is a text string made up of one or more names separated by forward slashes (/). A pathname is a path-of-names that indicates how to find something in the hierarchical file system tree.

In Linux, we have two types of pathname. absolute and relative.

A pathname that starts with a leading slash on the left is called an absolute pathname. The leading slash on the left indicates that the pathname starts at the topmost nameless ROOT directory in the file system.

Pathnames with no leading slash on the left are called relative pathnames. A relative pathname never starts with a slash on the left, but it may contain slashes anywhere else.

Current Directory + Relative Pathname = Absolute Pathname

Pathnames starting with ~ or $HOME variable may look like relative paths but they may become Absolute. Because the ~ or $HOME is expanded by shell to be the absolute path.

A pathname is absolute if and only if it starts with a leading slash after all shell expansions are finished. Otherwise, without a starting slash, the pathname is relative to the current working directory

Permissions

In Linux, there are three possible permissions, named read, write, and execute/search, abbreviated r, w, and x.

Read Permission (r--)[4]

For a file, the process can read the data contained in the file. For a directory, the process can read only the names contained in the directory.

Read permission on a directory only gives the process access to the names in the directory itself. It cannot follow the inode number to get more info. You may be able to see a file's name but not have permission to see the file's owner or contents.

Write Permission (-w-)[2]

For a file, this means that the process can alter the data contained in the file. For a directory,                     the process can add, remove, or alter (rename) the names in the directory.

eXecute/Search Permissions (--x)[1]

If the file is binary or a script file (#!), it can be executed.

For a directory, the process may “pass-through” the directory to access the inode numbers and content of the items named in the directory. Without search permissions on a directory, the process cannot access any of the inodes and content named in the directory.

Ownership

Linux is a multi-user operating system. That means Linux can be used by multiple users at the same time. As multiple users can use a computer at the same time. We need a way to identify each user. Among the users some are closely related, thus making a group of users.

Every file in Linux has 3 kinds of owners

User

The user is the owner of the file. The user who created the file will be the owner of the file.

Group

A group consisting of several users. A user is a part of a certain group/groups as well. A user has a primary group, which will be assigned as a group for the new file created by this user. A file has a group associated with it.

Other

All other users in the system, which are not part of the group and not the user.

we can see users in the system with cat /etc/passwd. We can list groups on the system with cat /etc/group

To get the user, uid, groups and gids of a user we can use id command. With id username we can list similar information of the username user.

File Permissions and Ownership

Now we learn about permissions types and owner types. Now we will learn how permissions and different owners are used for authorization of the files.

A Linux file has 3 different sets of permission. Each set of permissions for user, group and other.

A Linux file has three sets of three Unix permissions (nine permissions in total). rwxrwxrwx

Using ls -l to display the files and the permissions in the current working directory.

    $ ls -l
total 4
-rw-rw-r-- 1 devkota devkota 0 Feb 26 09:59 file.txt
-rwxr-xr-- 1 devkota devkota 0 Feb 26 09:59 just.sh
drwxrwxr-x 2 devkota devkota 4096 Feb 26 09:59 test

Let's Pick the first one and learn about its components.

        Permissions         User               Size                   File Name
    +-+----^-----+---+----^----+---------+-^-+--------------+-----^----+
|-|rw-rw-r-- | 1 | devkota | devkota | 0 | Feb 26 09:59 | file.txt |
+v+----------+-v-+---------+----v----+---+------v-------+----------+
    File Type     Link Count          Group           Last Modified 

Let's learn more about each of these components.

  • File Type: Indicate the type of the file, - for a regular file, d for the directory.
  • Permissions: three sets of three Unix permissions. Each for user, group and other.
  • Link Count: number of hard links to this file. we will learn more on Links.
  • User: the owner of the file. The first set of permissions is for this user.
  • Group: the group of the file. The Second set of permissions is for the users in this group.
  • Last Modified: the timestamp of the last modification.
  • File Name: the name of the file.

Let's look at the permissions

       User          Other
    +--^--+-----+--^--+
| rw- | rw- | r-- |
+-----+--v--+-----+
             Group

The First Permission is for the user. The second one is for the users of the group. and the third one is for all other users.

As per the above permission The user and the users in the group can read and write in the file. Whereas all other users can only read the file.

We use the chmod command to change the permissions of the file. chmod work on two modes.

  • symbolic mode
  • absolute mode

For absolute mode,

        r = 4
w = 2
x = 1

Permissions on Directories

If you have only r-- permissions on a directory (only read permissions), you can only see the names in the directory; No information about the files other than the name.

    $ ls -l
total 4
dr--r--r-- 3 devkota devkota 4096 Feb 24 08:38 test
$ ls -l test/
ls: cannot access 'test/hello': Permission denied
ls: cannot access 'test/message': Permission denied
total 0
d????????? ? ? ? ? ? hello
-????????? ? ? ? ? ? message
$ cat test/message
cat: test/message: Permission denied

If you have only --x permissions on a directory (only search permissions), you can get all information of anything contained in the directory (read details from inode); but, you cannot read any of the names in the directory. But if you know already you can use that name.

    $ ls -l
total 4
d--x--x--x 3 devkota devkota 4096 Feb 24 08:19 test
$ cat test/message
hello world
$ ls test/
ls: cannot open directory 'test/': Permission denied

A directory with -wx permissions lets a process enter or change names in it; but, without read permissions, the process cannot read the names back from the directory.

    $ ls -l
total 4
d-wx-wx-wx 3 devkota devkota 4096 Feb 24 08:19 test
$ cd test/
$ nano message
$ cat message
hello world Changed
$ ls
ls: cannot open directory '.': Permission denied
$ mv message message2
$ cat message2
hello world Changed

A directory with only -w- permissions is useless. any action that requires write permission on a directory also requires search permission. Similarly, having rw- permissions is the same as r-- permissions;

IO Redirection

Streams

Shell receives input and sends output as sequences or streams of characters. All the streams are treated as the same whether it comes from or goes to a file, a keyboard, a window on a display, or some other IO device.

Linux shells use three standard I/O streams, each of which is associated with a well-known file descriptor:

  • stdin, standard input, which provides input to command. File descriptor 0.
  • stdout, standard output, which display the output of the command. File descriptor 1.
  • stderr, standard error, which displays the error output of the command. File descriptor 2.

IO Redirection is a process of changing from where commands read input and to where commands send output. It applies the same to all commands, once we learn to use it, we can use it on all the commands.

You can redirect the input of command away from your keyboard, and you can redirect the output of command away from your screen.

We can redirect to a file using '>' and redirect from a file using '<'. '>' will always replace the content of the file. '>>' is used to append into the file. To redirect stderr we use '2>'

echo "Hello World" > hello.txt Now we don't see the output. but if we cat the hello.txt, the Hello World will be there.

Links

inode

Inodes in Linux is a data structure that stores metadata about files. The inode is the short form of the Index node.

Linux stores data in the form of blocks in the memory. The Inode of a file contains a list of all the blocks in which a file is stored. Whereas, the inode of a directory contains a mapping of files and directories it contains to their respective inodes.

Each file has an inode number. Inodes are stored together in a table and the inode number is the index where that particular inode is stored.

We can get the inode of the files using ls -i. The number before the filename is the inode number. We can get the metadata stored in the inode using stat file.txt

$ stat file.txt 
File: file.txt
Size: 46284 Blocks: 96 IO Block: 4096 regular file
Device: 803h/2051d Inode: 3152892 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1000/ devkota) Gid: ( 1000/ devkota)
Access: 2022-02-26 14:32:11.147302034 +0545
Modify: 2022-02-26 14:52:16.141174510 +0545
Change: 2022-02-26 14:52:16.141174510 +0545
Birth: -

Links are the connection between files. There are two types of links.

  1. Hard Link
  2. Soft Link

Hard Link

When we create a hard link, a link is established between two files. Both of the files point to the same inode number. A hard link is established with the inode. Each file is independent of the other. When a file is deleted. the link count is decremented. When the link count is zero, it is removed.

Soft Link

It is a symbolic link. A link is established to the file. The link did not appear as a regular file as in the hard link. If the original file is deleted, this link won't work and is known as a 'dangling link'.

Wildcard

A wildcard in Linux refers to a symbol or set of symbols that stand in for other characters. It is a symbol that can be substituted for zero or more characters in a string.

  • ?: matches any single character.
  • *: matches any string including nothing.
  • [set]: matches strings in the set.
  • [!set]: matches strings that are not in the set.

Working With Remote System

As a Linux system administrator, you have to manage multiple servers. Some may be located locally or on distant sites. You have to execute different commands to fix/configure/monitor the system. For this, you will need to remotely access those instances from your own computer.

There are 2 protocols available to remotely access.

  1. Telnet

    Developed in 1969, allow bi-directional communication. Default port 23 of the remote machine. The Telnet protocol is not encrypted.

  2. SSH
  3. We will learn more about SSH.

SSH

SSH stands for Secure Shell and it is widely used to perform commands remotely safely and securely.

To establish an ssh connection, we first need to configure both the client and server components. In the remote server, you have to access, need to install ssh-server. Then run the sshd demon.

Similarly, your local machine should have an ssh client installed in your system.

An open-source SSH tool—widely used for Linux distributions— is OpenSSH.

SSH password authentication

With SSH password authentication, the client starts the connection with the server using, the hostname and the port. Then the SSH server responds the ssh version available and stuffs to establish the connection. Once after that user need to provide the password for the user. server verify the password. if it is correct, an ssh session is established.

Generally, passwords are considered predictable, short, weak. Thus it is suggested to use an SSH key to establish the connection. SSH keys are faster and more convenient.

SSH key authentication

SSH Keys are a way to secure your server further against malicious activities directed at trying to SSH into your server. SSH Keys provide a level of authorization that can only be fulfilled by those who have ownership of the private key associated with the public key on the server.

To configure the ssh key, we will first create a key pair. We will have a private key and a public key. Then we place our public key on the server's authorized_keys. Now when we start the ssh connection, we can define the key to use to establish the connection, when the client's private key matches the public key in the server we can access the system.

Let's establish an ssh connection to a remote server. As I have already suggested about OverTheWire, Wargames. On level 0 of the game called Bandit. You are instructed to connect to the server using the provided details. Yes, that is the remote system you accessing.

Also on the Bonus section, Get free VPS (Linux server) as a student. If you are a student you can get a free VPS server as well, which you will access using ssh.

More Linux Commands

Text Processing

Here we will learn some commands that can be used on text files.

grep, with grep command you can search for the text in a file. grep "hello World" file.txt will show all the lines containing Hello World on file.txt.

egrep, with egrep command you can use the regular expression on the query text. egrep is powerful then grep

sort is used to sort the lines in the file.

uniq, show unique lines from the file. It will hide any duplicate lines.

wc, word count, is used to count the words in the file. wc text.txt will give you no of lines, word count, no of bytes.

    $ wc text.txt 
1157 5392 53099 text.txt

Archiving and Compression

Archiving is the process of combining multiple files into one. Whereas Compression is a process of reducing the file size, so it will be efficient while transferring over the internet.

We will be using tar. Originally written as a magnetic Tape ARchiver, the command is common to every Unix/Linux system. This command is available since 1969.

The syntax for the tar command is irregular. As it supports the traditional approach as well as the UNIX style. tar cvf archive.tar . will archive the contents on the current directory into archive.tar. tar -cvf archive.tar . is similar to the above command.

Similarly, we can extract with tar xvf archive.tar will extract the contents of the archive to the current directory.

gzip is used to compress and decompress the archive. We can compress the archive with gzip archive.tar. It will create archive.tar.gz. If we inspect the difference in size the compressed file has a small size.

we can uncompress the compressed file with gzip -d archive.tar.gz, which will create the archive.tar back. Then we can tar xvf archive.tar to extract the contents.

Getting Help

There are 100s of Linux commands and programs, It is hard to remember all those commands and options to use. In this section, we will look for various options that are available to get help on Linux.

Most command supports -h or --help option, which will show a guide on how to use that particular program.

whatis is a simple program, which gives one line information about the command. whatis ls will show what the ls command is.

man, manual, is an application that will show information about the command. man cd will show about the cd command, its options and its arguments. the default behaviour, available options and stuff.

info, is a command which will show information about the command. man and info command fulfil the same purpose, but the Info command has lots of contents. So if you need more info, you can use info.

Other Commands and Tips

Let's learn some other commands

pushd and popd allow you to push directory to stack while moving around. You can push the directory into the stack with pushd while navigating to that directory. you can travel back on the stack with popd. You can go to the last working directory with cd -

id command will show your userid and groups along with groupid it associated with.

wget command is used to get / download content over the internet.

find with the find command, you can search for files and directories.

free command is used to view the use of memory and the swap. df, display filesystem, is used to show about disk in the system. top command is used to show the currently running Linux processes in real-time. kill command is used to kill a process using the process id.

systemctl / service you have to use systemctl or service command to manage different daemons/services. We will use it in the bonus section as well.

Let's learn some tips as well. You can use the up / down arrow to navigate your older commands. If you had used some command you can press up arrows find the command and hit enter.

Tab for auto-complete. you can use the tab to auto-complete the commands/options and even arguments. You can press the tab to autocomplete, if there are more options, you can press tab double to list the options.

history command will show you the list of commands you have entered into the system.

Bonus

In this section, we will try to use some of the knowledge we have learned and configure a web server to host a simple website. Also, if you are a student you can get Free VPS servers we look more on that as well.

Nginx Web Server

Nginx, pronounced like “engine-ex”, is an open-source web server. Nginx was originally created by Igor Sysoev, to solve the C10K problem, handling large numbers (the 10K) of concurrent connections (the C).

With the advancement of the web, Nginx supports all the components of the modern Web, including WebSocket, HTTP/2, gRPC, and streaming of multiple video formats (HDS, HLS, RTMP, and others).

Nginx is not only used as a webserver but also used as a reverse proxy, HTTP cache, load balancer and more. Here we simply look at the webserver part.

Deploy a Simple Website

We will deploy a simple website here. We are not expecting you to understand this, but there is not much. We just want to show you how easy it is.

Let's first install Nginx

    $ sudo apt update
$ sudo apt install nginx

Now the Nginx is installed, let's start the service, and enable it, so it will auto-start on server restart.

    $ sudo systemctl start nginx
$ sudo systemctl enable nginx

Now we can check the service status. It will show some active / running information. If there is any error, I would suggest you restart the server once.

    $ sudo systemctl status nginx

Let's make a simple webpage to deploy. we will create a www dir in the /var. Then create a webpage, we will have simply "Hello World!" there.

    $ cd /var
$ sudo mkdir www
$ sudo chgrp www-data www/
$ sudo usermod -a -G www-data devkota
$ sudo chmod 775 www/

$ cd www
$ mkdir demo
$ cd demo
$ touch index.html
$ nano index.html

Now, we will create a config file on /etc/nginx/conf.d/. Let's name it demo.conf. We will have our configuration there.

    $ cd /etc/nginx/conf.d/
$ sudo nano demo.conf

In the configuration file, we will have the following contents. Remember to make changes on your DNS server to point the domain to your server.

    server {
server_name demo.bloggernepal.com;

location / {
root /var/www/demo;
index: index.html;
}
}

Since we have updated the configuration of Nginx, we need to test the config and restart the demon.

    $ sudo nginx -t
$ sudo systemctl restart nginx

That's it, once your visit the demo.bloggernepal.com (or any URL you had used) you should get the Hello world (the webpage on /var/www/demo/index.html)

Get Free VPS (Linux Server) as a Student

There are various offers and discounts out there for students. We will talk about some of them here. And list some more. We will keep updating this list, once we find more such offers.

Github Education Student Pack

GitHub Education is a program to give students free access to popular development tools and services. GitHub partnered with Bitnami, Crowdflower, DigitalOcean, DNSimple, HackHands, Namecheap, Orchestrate, Screenhero, SendGrid, Stripe, Travis CI, Unreal Engine and many more to provide this service.

There are some 50+ services on the pack. Among them, we are interested in are Microsoft Azure and DigitalOcean.

Microsoft Azure allow you to access Microsoft Azure cloud services and learning resources. No credit card is required. Free access to 25+ Microsoft Azure cloud services plus $100 in Azure credit.

DigitalOcean provides $100 in platform credit for new users which will be valid for a year.

You can create a VPS server with Microsoft Azure or Digital Ocean.

Other Student Packs

We will list other packs here. We will keep this list updated.

  • Alibaba Cloud for Students

Conclusion

Finally, you have made it. You completed this mini-course. Linux is complex to learn in one sit. There are various topics that are interlinked. We have used different concepts in the beginning without understanding them. Now as you have gathered some knowledge, you can go over this article again and get the most out of it.

We started by learning about Linux. Then we move to some basic commands. Once after that, we learn some fundamental concepts on Linux. Then we learn about SSH and how we can access remote servers. Then we work on some more commands. Then we apply our understanding while learning to deploy an Nginx server. This is our Basic Linux Commands Mini-Course. If you have any suggestions let us know.

Course by Sagar Devkota

0 Comments