You are on page 1of 21

K a b u l Po l y t e c h n i c U n i v e r s i t y

Linux System Administration

Lecturer: Zabehullah Nasiri


penetrationlab@gmail.com
Linux Types

2
Linux Directory Structure

• In Linux, the directory structure starts at ‘/’. This is the ‘root’ of


the filesystem or the top level if you prefer.
• Within ‘/’ there are several folders. We will go through them one
by one.
• ‘/bin’ contains executable binary files, which are programs that
come with the operating system
• ‘/boot’ holds files that are important during the boot process,
including the Linux kernel itself

3
Linux Directory Structure

• ‘/dev’ contains the devices that are connected to the


Linux system. (Remember, devices are files so they have
to be somewhere!)
• ‘/etc’ contains application configuration files
• ‘/home’ contains the home directories of users on the
system
• ‘/lib’ contains library files and kernel modules which are
required by the operating system
• ‘/media’ contains the media devices that are connected
to the Linux system (such as CD-ROMS)
4
Linux Directory Structure

• ‘/mnt’ contains the filesystem files


• ‘/opt’ stands for ‘optional’. The user can decide what to
put in there but typically it’s used for third party
applications.
• ‘/proc’ contains files for every running process (Again,
everything is a file so processes are files)
• ‘/root’ is the home directory of the root user. Not to be
confused with ‘/’, which is the root of the filesystem.
• ‘/sbin’ is similar to ‘/bin’. It contains binary programs
required by the operating system.
5
Linux Directory Structure

• ‘/tmp’ contains temporary files. This directory is


cleared out periodically and after a reboot.
• ‘/usr’ contains executable binary programs, source
code and libraries for user-level programs
• ‘/var’ typically contains log files and lock files

6
Linux Permissions

• Each file in Linux has three sets of permissions. The first set is
‘Owner’ which is the set that applies to the owner of the file.
• This is typically the person who created the file but it can be
changed (more on that later)
• The next set is ‘Group’, which is the set that applies to a user who
isn’t the Owner but is in the Group that owns the file. This can
also be changed.
• The last set is ‘Everyone’, which is the set of permissions that
applies to anyone that isn’t the Owner and isn’t in the matching
Group

7
Linux Permissions – The Long Way

• You may see permissions written like so:


• rwxr-xr--
• ‘x’ stands for execute, ‘w’ stands for write and ‘r’ stands
for read. A dash means that the permission isn’t set.
• Starting from the left, the first three are for the Owner,
the second three are for the Group and the last three are
for everyone else.
• In this case, the Owner can read, write and execute the
file. The Group can only execute and read and everyone
else can only read the file.
8
Linux Permissions – The Short Way (1)

• You may also hear people talk about setting permissions to ‘755’,
for example. This is a shorthand way of expressing permissions.
• Many people struggle with how to calculate this, but it’s actually
quite simple. You’ll need to know your binary though.
• Each set of permissions is represented by one digit, so the Owner
is 7, the Group is 5 and Everyone is 5
• 7 in binary is 111. Notice that there are three digits in binary and
there are three permissions, rwx. Each binary digit represents one
of the permissions. A 1 means that permission is enabled, a 0
means it is disabled.

9
Linux Permissions – The Short Way (2)

OWNER GROUP EVERYONE


r w x r w x r w x
1 1 1 1 0 1 1 0 1
7 5 5

• Owner can read, write and execute


• Group can read and execute, but not write
• Everyone can read and execute, but not write

10
Linux Permissions – The Short Way (3)

OWNER GROUP EVERYONE


r w x r w x r w x
1 1 1 1 0 0 0 0 0
7 4 0

• Owner can read, write and execute


• Group can read, but not write or execute
• Everyone can do nothing at all

11
Linux Permissions – The Shorter Way

• Just remember that:


• Read = 4
• Write = 2
• Execute = 1
• Then just add them up to get the final number for that permission
• For example:
• Read and Write but not Execute is: 4 + 2 = 6
• Write and Execute but not Read is: 2 + 1 = 3
• Read and Execute but not Write is: 4 + 1 = 5

12
Linux – Package Managers

• Package managers are the easiest way to install software,


as nearly everything is handled for you automatically
• There are two main package managers; most
distributions will have one or the other
• The first is ‘apt-get’ and the second is ‘yum’
• apt-get is usually found on debian-based distributions
• yum is usually found on fedora-based distributions.
• You will usually have to run a package manager as ‘root’,
so remember to use ‘sudo’ before the command

13
Linux – apt-get

• With apt-get the ‘update’ parameter updates the list of software packages
and their versions
• sudo apt-get update
• The ‘upgrade’ parameter will upgrade your installed software packages
automatically
• sudo apt-get upgrade
• The ‘dist-upgrade’ parameter will upgrade your operating system to a newer
version
• sudo apt-get dist-upgrade
• The ‘install’ parameter will install new software
• sudo apt-get install nano
• The ‘remove’ parameter will uninstall software
• sudo apt-get remove nano

14
Linux – yum
• With yum the ‘update’ parameter upgrades your installed software packages automatically
• sudo yum update (updates all packages)
Or
• sudo yum update nano (updates the specified package)
• The ‘install’ parameter installs new software
• sudo yum install nano
• The ‘remove’ parameter uninstalls software
• sudo yum remove nano

15
Linux – dpkg

• A program that can install ‘.deb’ files


• Usually found on debian-based distributions
• To install a .deb file:
• Download the .deb package first
• sudo dpkg –i nano.deb
• To uninstall a program installed with dpkg:
• sudo dpkg –l (to list all packages in order
to find the package name)
• sudo dpkg –r nano

16
Linux Services
List all services in Ubuntu
service --status-all
Use Systemd to Start/Stop/Restart Services in Ubuntu
The Syntax is:
sudo systemctl [action] [service name]

To start a service:
sudo systemctl stop ufw

To stop a service:
sudo systemctl start ufw

To restart a service:
sudo systemctl restart ufw

To check the status of service:


sudo systemctl status ufw

17
Linux Services(2)
Start/Stop/Restart Services with service command on
Ubuntu

sudo service ufw stop

To stop a service:

sudo service ufw start

To stop a service:

sudo service ufw restart

To check the status of a service:

sudo service ufw status

18
Linux Services(3)
Using Init scripts to manage services on Ubuntu

To start a service:

/etc/init.d/ufw start

To stop a service:

/etc/init.d/ufw stop

To stop a service:

/etc/init.d/ufw restart

To check the status of service:

/etc/init.d/ufw status

19
Linux Services(4)

Start service on boot


To check whether the service is enabled on boot or
not:
systemctl status apache2

To enable the service on boot:


sudo systemctl enable apache2

To check whether the service is enabled on boot or


not:
sudo systemctl status apache2

To disable the service on boot:


sudo systemctl disable apache2

20
K a b u l Po l y t e c h n i c U n i v e r s i t y

Thank You!
Questions?

@Zabehullah Nasiri

You might also like