SlideShare a Scribd company logo
1 of 53
Download to read offline
Linux communication
Linux communication
By : Khawar Nehal
16 October 2021
Agenda
Wall
Talk
systemctl
ps
pstree
top
htop
Kill
crontab
at
Agenda
Df
Dmesg
dmidecode
Iostat
Netstat
free
Inxi
Nice
ionice
wall
A sysadmin might send out a message like this:
$ wall The system will be going down in 15
minutes to address a serious problem
wall
Everyone logged into the system will see
something like this:
Broadcast message from admin@dragonfly
(pts/0) (Thu Mar 5 08:56:42 2020):
The system is going down in 15 minutes to
address a serious problem
wall
If you want to use single quote marks in your
message, enclose the message in double quote
marks like this:
$ wall “Don’t forget to save your work before
logging off”
The outside quote marks will not show up in the
transmitted message, but, without them, the
command sits and waits for a closing single quote.
mesg
If, for some reason, you don’t want to accept
messages from another user, you can stop them
from arriving with the mesg command. This
command can be used with a “n” argument to
refuse mail from the user or a “y” argument to
allow the messages to arrive.
$ mesg n doug
$ mesg y doug
mesg
The blocked user will not be notified that their
messages have been blocked. You can also block
or allow all messages with a mesg command like
one of these:
$ mesg y
$ mesg n
write
Another command for sending text without
reverting to email is write. This command can be
used to communicate with a specific user.
$ write nemo
Are you still at your desk?
I need to talk with you right away.
^C
write
If the user you are trying to write to has messages
blocked, you should see something like this:
$ write nemo
write: nemo has messages disabled
write
Enter your text and use ^C to exit when you’re
done. The command allows you to send text, but
doesn’t start a two-way conversation.
It just sends the text. If the user is logged in on
more than one terminal, you can specify which
terminal you want to send the message to or you
can rely on the system to choose the one with the
shortest idle time.
$ write nemo#1
talk/ytalk
The talk or ytalk command gives you a chance to
have an interactive chat with one or more other
users. The command will bring up a double-pane
(top and bottom) window.
Each individual will type into the top portion of the
display on their screen and see the responses in
the bottom section(s).
The respondents can respond to a talk request by
typing "talk" followed by the username of the
person addressing them.
talk/ytalk
Message from Talk_Daemon@dragonfly at
10:10 ...
talk: connection requested by dory@127.0.0.1.
talk: respond with: talk dory@127.0.0.1
$ talk dory
talk/ytalk
The window can involve more than two
participants if ytalk is used.
As you can see in the example below (the result
of the "talk dory" command shown above), talk is
often ytalk.
----------------------------= YTalk version 3.3.0 =--------------------------
Is the report ready?
-------------------------------= nemo@dragonfly =----------------------------
Just finished it
talk/ytalk
As explained above, on the other side of the conversation, the talk session
window panes are reversed:
----------------------------= YTalk version 3.3.0 =--------------------------
Just finished it
-------------------------------= dory@dragonfly =----------------------------
Is the report ready?
Again, use ^C to exit.
talk/ytalk
To talk with someone on another system, you just need to add a -h option and
the hostname or IP address with a command like this:
$ talk -h 192.168.0.11 nemo
Active directory and components
Active Directory, LDAP and Kerberos shall be
covered in a future class after it is working on my
system. Requires a day or two to prepare well.
Systemctl
The systemctl command is a utility which is
responsible for examining and controlling the
systemd system and service manager.
It is a collection of system management libraries,
utilities and daemons which function as a
successor to the System V init daemon.
Systemctl
Systemctl
Managing Services
What is a Service?
In the systemd utility, a service is referred to as a
unit. A unit is any resource that the system knows
how to act on and administrate. A unit is the
principal object that the systemd tools know how
to address. These assets are defined in a
configuration file called a unit file.
Systemctl
Check Service Status
Using systemctl, we can check the status of any
systemd service on the managed dedicated
server. The status command provides information
about a service. It also lists the running state, or
detail on why it is not running, or if a service has
been stopped unintentionally. If we are connected
to the server as a non-root user, we will have to
run the systemctl commands using.
systemctl status servicename.service
Systemctl
This unit can be called without the .service
extension. Since systemctl will look for those files
with .service suffix, the command can also be
used like this.
systemctl start servicename
Systemctl
Example of status output:
[root@host ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset:
disabled)
Active: active (running) since Fri 2020-05-08 14:15:54 EDT; 1 weeks 2 days ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 3767 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited,
status=0/SUCCESS)
Main PID: 1321 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─1321 /usr/sbin/httpd -DFOREGROUND
├─3769 /usr/sbin/httpd -DFOREGROUND
Systemctl
Starting or Stopping a Service
The systemctl utility can also be used to start or stop systemd services using a service
unit file, with or without that .service suffix.
systemctl start servicename.service
The same rules apply when we want to stop a specific service.
systemctl stop servicename.service
Keep in mind that the start order can only be used on systemd services that are not
currently running, and the stop command used only with running services.
Systemctl
Restarting or Reloading a Service
A running service can be restarted using the restart command to avoid stopping and
starting it manually using the following command.
systemctl restart servicename.service
Occasionally, we do not need to restart a service to apply configuration changes, if any
were you made. Instead, we can use the reload command to restart the service which
implements any changes to the running service.
systemctl reload servicename.serivce
If we are not sure about which of the two commands we should use, there is an additional
option using the reload-or-restart command which will automatically determine it for us.
systemctl reload-or-restart servicename.service
Systemctl
Enable or Disable a Service
When it comes to cloud server services, we require most of them to be online and active
all the time. Starting them manually is not a convenient method to employ, due to the
number of services required to run on a server. This is where the enable and disable
commands come into play. Using the enable command, we can modify how the systemd
service responds once the server has been started or rebooted. It will update the service
settings, which then tells systemd that the specific service needs to start up automatically,
once the server is up. The command to accomplish this is as follows.
systemctl enable servicename.service
While most of the services like HTTPD, MySQL, MariaDB, etc. will have already
automatically started, we may need to enable the automatic startup for some of them
manually. Similar to how we can set a service to automatically start when the server boots
up, we can also disable a service using the following command.
systemctl reload-or-restart servicename.service
The disable command prevents the automatic startup of a service at boot time, leaving it
inactive until it started manually.
Systemctl
System State Overview
All the systemctl commands that we have covered are mainly used to manage individual
services. Let's review some other commands systemctl has to offer and their uses.
Systemctl
Systemctl
What is a Unit File?
A unit file is a flat text file that contains information about a service, socket, device, mount
point, swap file, partition, start-up target, an asset management slice, or a group of
externally created processes.
Working with Unit Files
List Units
The list-units command displays all the active systemd services on your server. Our
output is similar to the information provided by the systemctl status command, but not as
detailed.
systemctl list-units
Systemctl
Here is the example of the output of that command.
root@host [~]# systemctl list-units
UNIT LOAD ACTIVE SUB DESCRIPTION
crond.service loaded active running Command Scheduler
dovecot.service loaded active running Dovecot IMAP/POP3 email server
firewalld.service loaded active running firewalld - dynamic firewall daemon
httpd.service loaded active running The Apache HTTP Server
mariadb.service loaded active running MariaDB database server
named.service loaded active running Berkeley Internet Name Domain (DNS)
Systemctl
Now that we have an example of the output, let's review the meaning of each column.
UNIT: The name of the systemd unit.
LOAD: This indicates if the unit's configuration is being loaded by systemd. If it is, the
configuration is stored in the server's memory.
ACTIVE: This states the status of the unit and shows whether it is active or not.
SUB: This provides more detailed information about the unit, which will vary depending
on the type of unit, state, and the method the unit runs in.
DESCRIPTION: This short description contains what each unit is and what it does.
Systemctl
Unit States
Using the systemctl list-units command will reveal all the units that are “loaded” and
“active” state in the LOAD and ACTIVE columns; however, if we wish to get a more
detailed list of all the services, we need to employ the usage of command flag. In this
case, the --all flag.
systemctl list-units --all
Using the -all flag, we can obtain a list of all the systemd units that are loaded or that
systemd has tried to load. This output will also show the services that are currently in an
inactive, dead, failed state, or that have not been found on the disk of the server.
Systemctl
While this flag provides the full output of all the units on the server, which systemd loaded
into memory, we can use additional flags to further filter the output of list-units. One of
them would be the --state= flag. We can use this flag to further filter the state in the
LOAD, ACTIVE, and SUB columns.
systemctl list-units --all --state=failed
Just as we can filter out the units by their state, we can also use the same type to
accomplish the same task.
systemctl list-units --all --type=mount
Systemctl
The list-units command displays the units that systemd has loaded or attempted to load
into memory. But, what about the units that are not in the systemd memory? This is where
the list-unit-files flag comes into play, as this command will display all available units on
the server.
systemctl list-unit-files
Systemctl
The output will be given in two columns with the name of a file and state.
UNIT FILE STATE
Proc-sys-fs-binfmt_misc.automount static
dev-hugepages.mount static
dev-mqueue.mount static
proc-sys-fs-binfmt_misc.mount static
sys-fs-fuse-connections.mount static
sys-kernel-config.mount static
sys-kernel-debug.mount static
tmp.mount disabled
The STATE column had four different states, which are:
Enabled
Disabled
Static
Masked
Systemctl
Masked Units
As you can see in the output above, many of the units show a staticSTATE status. This indicates that
those units do not have an “install” section within the unit's configuration file, and therefore, cannot
be enabled. On the other hand, some units may be masked, and as such, we will not be able to start
it. Masked units will provide output using the start command if we attempt to launch it.
systemctl start servicename.service
Failed to start servicename.service: Unit is masked.
Unmasking a unit is simple and will return the unit to the state where it can be started or enabled.
systemctl unmask servicename.service
Systemctl
Creating a Unit File
Occasionally, we may need to create a unit file for a custom daemon or another instance of an
already existing service. The creation of a unit file is executed via the root user in the
/etc/systemd/system/ directory. This is accomplished like so.
touch /etc/systemd/system/servicename.service
chmod 644 /etc/systemd/system/servicename.service
Systemctl
Next, we will open the newly created unit file in a text editor (like vim or nano) and add the service
configuration options. Below, we can see a basic example of the unit file.
[Unit]
Description=This is the manually created service
After=network.target
[Service]
ExecStart=/path/to/executable
[Install]
WantedBy=multi-user.target
Systemctl
Let’s quickly breakdown what these settings mean before we proceed further:
Description: The description is the description of the service, and will be displayed when we use
the systemctl status command for the created service.
After: The After setting indicates that a service will only start on reboot after a specified target or
another service has been started.
ExecStart: The ExecStart is the path to the actual executable file of the service.
WantedBy: The WantedBy setting states the target that the service should start under. This is
similar to runlevels.
Systemctl
Once the service file has been created, we will need to tell the system about it with the following
commands.
systemctl daemon-reload
systemctl start servicename.service
Systemctl
Viewing a Unit File
Once the unit file has been created, we do not necessarily need to navigate to the file itself to see
what is written inside. The systemctl command has a feature that displays the content of the unit file
for us. It can be performed with the following command.
systemctl cat servicename.service
Systemctl
Viewing Dependencies
Just like we can see inside a unit file, we can also use the following command to display the
dependency tree of that unit.
systemctl list-dependencies servicename.service
[root@host ~]# systemctl list-dependencies httpd.service
httpd.service
● ├─-.mount
● ├─system.slice
● └─basic.target
● ├─microcode.service
● ├─rhel-dmesg.service
● ├─selinux-policy-migrate-local-changes@targeted.service
● ├─paths.target
● ├─slices.target
● │ ├─-.slice
● │ └─system.slice
Systemctl
There are a few useful flags that can be added to the command such as the --all flag which lists all
dependencies recursively, or --reverse which will list them in reverse order. There is also the --before
and --after flags which are used to show unit starting before or after the specified unit.
Systemctl
View Properties
Additionally, we can see the properties of a unit by using the show command.
systemctl show servicename.service
This will give you output similar to the one below.
[root@host ~]# systemctl show httpd.service
Type=notify
Restart=no
NotifyAccess=main
RestartUSec=100ms
TimeoutStartUSec=1min 30s
TimeoutStopUSec=1min 30s
WatchdogUSec=0
WatchdogTimestamp=Thu 2020-06-25 05:43:53 EDT
Systemctl
In case you are looking for a single setting, you can use -p flag with the setting name. For example,
to get the PID of a running service, use this command.
[root@host ~]# systemctl show httpd.service -p MainPID
MainPID=4004
Systemctl
Edit Unit Files
In cases where the unit files need to be modified, systemctl has a built-in editing system that allows
us to modify unit files without searching for them on the server. This can be done using the edit
command.
systemctl edit httpd.service
This creates a directory in /etc/systemd/system named the same as the service with a .d appended
to it. It looks this: /etc/systemd/system/httpd.service.d.
This is where the edits would be stored, and any directives within this file would override the main
unit file. The snippet created in that directory would be named override.conf. In case we wish to edit
using file itself rather than creating a snippet, we can use the following command.
systemctl edit --full httpd.service
Systemctl
Removing Unit Files
Removing a unit file and overriding snippets can be accomplished using the following commands.
rm -r /etc/systemd/system/httpd.service.d
We can use the command below to remove the snippet directory, which overrides directives and
removes the full modified unit file.
rm /etc/systemd/system/httpd.service
Whenever we make edits or remove any of the unit files, we need to make sure that changes are
applied by using this command.
systemctl daemon-reload
Systemctl
Using Targets (Runlevels)
What is a Systemd Target?
When it comes to unit files, there are special files that we call targets that describe a system state or
synchronization point. These files can be identified by a suffix, which is called .target.
What are these .target files for? They can be used to change the system to certain states, similar to
how other init systems use runlevels.
Systemctl
List Targets
There is a number of target files on the server systems, and we can list them using the following
command.
systemctl list-unit-files --type=target
While working with runlevels, activating the runlevels is done one at a time, but when it comes to
targets, we can activate multiple targets at once. In order to see all active targets, we use the
following command.
systemctl list-units --type=target
Systemctl
Stopping or Rebooting the Server
Finally, we can use systemctl to stop the server, power it off, or to reboot it. For stopping the server,
we use the following halt command.
systemctl halt
To completely shut down the server, we use poweroff command.
systemctl poweroff
And to reboot the server, we can use the reboot command.
systemctl reboot
Summary
Wall
Talk
systemctl
ps
pstree
top
htop
Kill
crontab
at
Summary
Df
Dmesg
dmidecode
Iostat
Netstat
free
Inxi
Nice
ionice

More Related Content

What's hot

linux-commandline-magic-Joomla-World-Conference-2014
linux-commandline-magic-Joomla-World-Conference-2014linux-commandline-magic-Joomla-World-Conference-2014
linux-commandline-magic-Joomla-World-Conference-2014Peter Martin
 
Introduction to linux day-3
Introduction to linux day-3Introduction to linux day-3
Introduction to linux day-3Gourav Varma
 
[PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list [PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list nisivaasdfghj
 
2345014 unix-linux-bsd-cheat-sheets-i
2345014 unix-linux-bsd-cheat-sheets-i2345014 unix-linux-bsd-cheat-sheets-i
2345014 unix-linux-bsd-cheat-sheets-iLogesh Kumar Anandhan
 
Useful Linux and Unix commands handbook
Useful Linux and Unix commands handbookUseful Linux and Unix commands handbook
Useful Linux and Unix commands handbookWave Digitech
 
Linux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersLinux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersDavide Ciambelli
 
Anandha ganesh linux1.ppt
Anandha ganesh linux1.pptAnandha ganesh linux1.ppt
Anandha ganesh linux1.pptanandha ganesh
 
55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines55 best linux tips, tricks and command lines
55 best linux tips, tricks and command linesArif Wahyudi
 
50 most frequently used unix linux commands (with examples)
50 most frequently used unix   linux commands (with examples)50 most frequently used unix   linux commands (with examples)
50 most frequently used unix linux commands (with examples)Rodrigo Maia
 
Linux Networking Commands
Linux Networking CommandsLinux Networking Commands
Linux Networking Commandstmavroidis
 
One Page Linux Manual
One Page Linux ManualOne Page Linux Manual
One Page Linux Manualdummy
 
Linux powerpoint
Linux powerpointLinux powerpoint
Linux powerpointbijanshr
 

What's hot (20)

linux-commandline-magic-Joomla-World-Conference-2014
linux-commandline-magic-Joomla-World-Conference-2014linux-commandline-magic-Joomla-World-Conference-2014
linux-commandline-magic-Joomla-World-Conference-2014
 
Introduction to linux day-3
Introduction to linux day-3Introduction to linux day-3
Introduction to linux day-3
 
[PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list [PDF] 2021 Termux basic commands list
[PDF] 2021 Termux basic commands list
 
Linux commands
Linux commandsLinux commands
Linux commands
 
2345014 unix-linux-bsd-cheat-sheets-i
2345014 unix-linux-bsd-cheat-sheets-i2345014 unix-linux-bsd-cheat-sheets-i
2345014 unix-linux-bsd-cheat-sheets-i
 
Useful Linux and Unix commands handbook
Useful Linux and Unix commands handbookUseful Linux and Unix commands handbook
Useful Linux and Unix commands handbook
 
Linux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for BeginnersLinux Bash Shell Cheat Sheet for Beginners
Linux Bash Shell Cheat Sheet for Beginners
 
Linux Commands
Linux CommandsLinux Commands
Linux Commands
 
Unix - Filters/Editors
Unix - Filters/EditorsUnix - Filters/Editors
Unix - Filters/Editors
 
Shell programming
Shell programmingShell programming
Shell programming
 
Linux shell scripting
Linux shell scriptingLinux shell scripting
Linux shell scripting
 
Anandha ganesh linux1.ppt
Anandha ganesh linux1.pptAnandha ganesh linux1.ppt
Anandha ganesh linux1.ppt
 
55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines
 
50 most frequently used unix linux commands (with examples)
50 most frequently used unix   linux commands (with examples)50 most frequently used unix   linux commands (with examples)
50 most frequently used unix linux commands (with examples)
 
Linux Networking Commands
Linux Networking CommandsLinux Networking Commands
Linux Networking Commands
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Linux
LinuxLinux
Linux
 
One Page Linux Manual
One Page Linux ManualOne Page Linux Manual
One Page Linux Manual
 
Linux powerpoint
Linux powerpointLinux powerpoint
Linux powerpoint
 
Linux
LinuxLinux
Linux
 

Similar to Linux class 10 15 oct 2021-6

Systemd for administrators
Systemd for administratorsSystemd for administrators
Systemd for administratorsSusant Sahani
 
Systemd for administrators
Systemd for administratorsSystemd for administrators
Systemd for administratorsSusant Sahani
 
RHSA_1_Chapter_Resume_CONTRILE_SERVCIES.pptx
RHSA_1_Chapter_Resume_CONTRILE_SERVCIES.pptxRHSA_1_Chapter_Resume_CONTRILE_SERVCIES.pptx
RHSA_1_Chapter_Resume_CONTRILE_SERVCIES.pptxAbdellahELMAMOUN
 
The best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresherThe best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresherSrinimf-Slides
 
Step by step_linux_guide
Step by step_linux_guideStep by step_linux_guide
Step by step_linux_guidevinod31dec
 
LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager Alison Chaiken
 
CoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love SystemdCoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love SystemdRichard Lister
 
Network and distributed systems
Network and distributed systemsNetwork and distributed systems
Network and distributed systemsSri Prasanna
 
Windows power shell basics
Windows power shell basicsWindows power shell basics
Windows power shell basicsDan Morrill
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26Max Kleiner
 
Delphi - Howto Services
Delphi - Howto ServicesDelphi - Howto Services
Delphi - Howto ServicesNiall Munro
 
Linux Cheat Sheet.pdf
Linux Cheat Sheet.pdfLinux Cheat Sheet.pdf
Linux Cheat Sheet.pdfroschahacker
 
Cracking CTFs The Sysbypass CTF
Cracking CTFs The Sysbypass CTFCracking CTFs The Sysbypass CTF
Cracking CTFs The Sysbypass CTFRiyaz Walikar
 
ASP.NET Core and Docker
ASP.NET Core and DockerASP.NET Core and Docker
ASP.NET Core and DockerChuck Megivern
 

Similar to Linux class 10 15 oct 2021-6 (20)

systemd
systemdsystemd
systemd
 
Systemd for administrators
Systemd for administratorsSystemd for administrators
Systemd for administrators
 
Systemd for administrators
Systemd for administratorsSystemd for administrators
Systemd for administrators
 
RHSA_1_Chapter_Resume_CONTRILE_SERVCIES.pptx
RHSA_1_Chapter_Resume_CONTRILE_SERVCIES.pptxRHSA_1_Chapter_Resume_CONTRILE_SERVCIES.pptx
RHSA_1_Chapter_Resume_CONTRILE_SERVCIES.pptx
 
The best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresherThe best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresher
 
Step by step_linux_guide
Step by step_linux_guideStep by step_linux_guide
Step by step_linux_guide
 
LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager LISA15: systemd, the Next-Generation Linux System Manager
LISA15: systemd, the Next-Generation Linux System Manager
 
CoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love SystemdCoreOS, or How I Learned to Stop Worrying and Love Systemd
CoreOS, or How I Learned to Stop Worrying and Love Systemd
 
Network and distributed systems
Network and distributed systemsNetwork and distributed systems
Network and distributed systems
 
Windows power shell basics
Windows power shell basicsWindows power shell basics
Windows power shell basics
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26
 
Cracking CTFs - Sysbypass CTF Walkthrough
Cracking CTFs - Sysbypass CTF WalkthroughCracking CTFs - Sysbypass CTF Walkthrough
Cracking CTFs - Sysbypass CTF Walkthrough
 
Delphi - Howto Services
Delphi - Howto ServicesDelphi - Howto Services
Delphi - Howto Services
 
Linux Cheat Sheet.pdf
Linux Cheat Sheet.pdfLinux Cheat Sheet.pdf
Linux Cheat Sheet.pdf
 
Systemd cheatsheet
Systemd cheatsheetSystemd cheatsheet
Systemd cheatsheet
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Cracking CTFs The Sysbypass CTF
Cracking CTFs The Sysbypass CTFCracking CTFs The Sysbypass CTF
Cracking CTFs The Sysbypass CTF
 
ASP.NET Core and Docker
ASP.NET Core and DockerASP.NET Core and Docker
ASP.NET Core and Docker
 
linux installation.pdf
linux installation.pdflinux installation.pdf
linux installation.pdf
 

More from Khawar Nehal khawar.nehal@atrc.net.pk

More from Khawar Nehal khawar.nehal@atrc.net.pk (20)

Linux Class 1 Reasons to use linux
Linux Class 1 Reasons to use linux Linux Class 1 Reasons to use linux
Linux Class 1 Reasons to use linux
 
Same old lessons in investing
Same old lessons in investingSame old lessons in investing
Same old lessons in investing
 
Linux class 15 26 oct 2021
Linux class 15   26 oct 2021Linux class 15   26 oct 2021
Linux class 15 26 oct 2021
 
File systems linux class 8
File systems linux class 8File systems linux class 8
File systems linux class 8
 
Linux commands Class 5 - 8 oct 2021
Linux commands Class 5 - 8 oct 2021Linux commands Class 5 - 8 oct 2021
Linux commands Class 5 - 8 oct 2021
 
Linux course fhs file hierarchy standard
Linux   course   fhs file hierarchy standardLinux   course   fhs file hierarchy standard
Linux course fhs file hierarchy standard
 
Linux passwords class 4
Linux passwords class 4Linux passwords class 4
Linux passwords class 4
 
Using linux 5 oct 2021 3
Using linux 5 oct 2021 3Using linux 5 oct 2021 3
Using linux 5 oct 2021 3
 
Everyday uses of linux
Everyday uses of linux  Everyday uses of linux
Everyday uses of linux
 
Computing people
Computing people  Computing people
Computing people
 
Artificial Intelligence by Khawar Nehal
Artificial Intelligence by Khawar NehalArtificial Intelligence by Khawar Nehal
Artificial Intelligence by Khawar Nehal
 
Artificial Intelligence in Banking
Artificial Intelligence in BankingArtificial Intelligence in Banking
Artificial Intelligence in Banking
 
Electric Vehicles
Electric VehiclesElectric Vehicles
Electric Vehicles
 
Electric Vehicles
Electric VehiclesElectric Vehicles
Electric Vehicles
 
RevOps Revenue Operations
RevOps Revenue OperationsRevOps Revenue Operations
RevOps Revenue Operations
 
Management techniques of the world by khawar nehal 4 august 2020-1
Management techniques of the world by khawar nehal   4 august 2020-1Management techniques of the world by khawar nehal   4 august 2020-1
Management techniques of the world by khawar nehal 4 august 2020-1
 
Kona (TM) Autonomous Cars Anti Collision System
Kona (TM) Autonomous Cars Anti Collision SystemKona (TM) Autonomous Cars Anti Collision System
Kona (TM) Autonomous Cars Anti Collision System
 
What was learned about what works in distance learning in 2020
What was learned about what works in distance learning in 2020What was learned about what works in distance learning in 2020
What was learned about what works in distance learning in 2020
 
Values provided by businesses
Values provided by businesses  Values provided by businesses
Values provided by businesses
 
Effective and complete Cybersecurity HOWTO
Effective and complete Cybersecurity HOWTOEffective and complete Cybersecurity HOWTO
Effective and complete Cybersecurity HOWTO
 

Recently uploaded

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 

Recently uploaded (20)

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 

Linux class 10 15 oct 2021-6

  • 2. Linux communication By : Khawar Nehal 16 October 2021
  • 5. wall A sysadmin might send out a message like this: $ wall The system will be going down in 15 minutes to address a serious problem
  • 6. wall Everyone logged into the system will see something like this: Broadcast message from admin@dragonfly (pts/0) (Thu Mar 5 08:56:42 2020): The system is going down in 15 minutes to address a serious problem
  • 7. wall If you want to use single quote marks in your message, enclose the message in double quote marks like this: $ wall “Don’t forget to save your work before logging off” The outside quote marks will not show up in the transmitted message, but, without them, the command sits and waits for a closing single quote.
  • 8. mesg If, for some reason, you don’t want to accept messages from another user, you can stop them from arriving with the mesg command. This command can be used with a “n” argument to refuse mail from the user or a “y” argument to allow the messages to arrive. $ mesg n doug $ mesg y doug
  • 9. mesg The blocked user will not be notified that their messages have been blocked. You can also block or allow all messages with a mesg command like one of these: $ mesg y $ mesg n
  • 10. write Another command for sending text without reverting to email is write. This command can be used to communicate with a specific user. $ write nemo Are you still at your desk? I need to talk with you right away. ^C
  • 11. write If the user you are trying to write to has messages blocked, you should see something like this: $ write nemo write: nemo has messages disabled
  • 12. write Enter your text and use ^C to exit when you’re done. The command allows you to send text, but doesn’t start a two-way conversation. It just sends the text. If the user is logged in on more than one terminal, you can specify which terminal you want to send the message to or you can rely on the system to choose the one with the shortest idle time. $ write nemo#1
  • 13. talk/ytalk The talk or ytalk command gives you a chance to have an interactive chat with one or more other users. The command will bring up a double-pane (top and bottom) window. Each individual will type into the top portion of the display on their screen and see the responses in the bottom section(s). The respondents can respond to a talk request by typing "talk" followed by the username of the person addressing them.
  • 14. talk/ytalk Message from Talk_Daemon@dragonfly at 10:10 ... talk: connection requested by dory@127.0.0.1. talk: respond with: talk dory@127.0.0.1 $ talk dory
  • 15. talk/ytalk The window can involve more than two participants if ytalk is used. As you can see in the example below (the result of the "talk dory" command shown above), talk is often ytalk. ----------------------------= YTalk version 3.3.0 =-------------------------- Is the report ready? -------------------------------= nemo@dragonfly =---------------------------- Just finished it
  • 16. talk/ytalk As explained above, on the other side of the conversation, the talk session window panes are reversed: ----------------------------= YTalk version 3.3.0 =-------------------------- Just finished it -------------------------------= dory@dragonfly =---------------------------- Is the report ready? Again, use ^C to exit.
  • 17. talk/ytalk To talk with someone on another system, you just need to add a -h option and the hostname or IP address with a command like this: $ talk -h 192.168.0.11 nemo
  • 18. Active directory and components Active Directory, LDAP and Kerberos shall be covered in a future class after it is working on my system. Requires a day or two to prepare well.
  • 19. Systemctl The systemctl command is a utility which is responsible for examining and controlling the systemd system and service manager. It is a collection of system management libraries, utilities and daemons which function as a successor to the System V init daemon.
  • 21. Systemctl Managing Services What is a Service? In the systemd utility, a service is referred to as a unit. A unit is any resource that the system knows how to act on and administrate. A unit is the principal object that the systemd tools know how to address. These assets are defined in a configuration file called a unit file.
  • 22. Systemctl Check Service Status Using systemctl, we can check the status of any systemd service on the managed dedicated server. The status command provides information about a service. It also lists the running state, or detail on why it is not running, or if a service has been stopped unintentionally. If we are connected to the server as a non-root user, we will have to run the systemctl commands using. systemctl status servicename.service
  • 23. Systemctl This unit can be called without the .service extension. Since systemctl will look for those files with .service suffix, the command can also be used like this. systemctl start servicename
  • 24. Systemctl Example of status output: [root@host ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2020-05-08 14:15:54 EDT; 1 weeks 2 days ago Docs: man:httpd(8) man:apachectl(8) Process: 3767 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS) Main PID: 1321 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─1321 /usr/sbin/httpd -DFOREGROUND ├─3769 /usr/sbin/httpd -DFOREGROUND
  • 25. Systemctl Starting or Stopping a Service The systemctl utility can also be used to start or stop systemd services using a service unit file, with or without that .service suffix. systemctl start servicename.service The same rules apply when we want to stop a specific service. systemctl stop servicename.service Keep in mind that the start order can only be used on systemd services that are not currently running, and the stop command used only with running services.
  • 26. Systemctl Restarting or Reloading a Service A running service can be restarted using the restart command to avoid stopping and starting it manually using the following command. systemctl restart servicename.service Occasionally, we do not need to restart a service to apply configuration changes, if any were you made. Instead, we can use the reload command to restart the service which implements any changes to the running service. systemctl reload servicename.serivce If we are not sure about which of the two commands we should use, there is an additional option using the reload-or-restart command which will automatically determine it for us. systemctl reload-or-restart servicename.service
  • 27. Systemctl Enable or Disable a Service When it comes to cloud server services, we require most of them to be online and active all the time. Starting them manually is not a convenient method to employ, due to the number of services required to run on a server. This is where the enable and disable commands come into play. Using the enable command, we can modify how the systemd service responds once the server has been started or rebooted. It will update the service settings, which then tells systemd that the specific service needs to start up automatically, once the server is up. The command to accomplish this is as follows. systemctl enable servicename.service While most of the services like HTTPD, MySQL, MariaDB, etc. will have already automatically started, we may need to enable the automatic startup for some of them manually. Similar to how we can set a service to automatically start when the server boots up, we can also disable a service using the following command. systemctl reload-or-restart servicename.service The disable command prevents the automatic startup of a service at boot time, leaving it inactive until it started manually.
  • 28. Systemctl System State Overview All the systemctl commands that we have covered are mainly used to manage individual services. Let's review some other commands systemctl has to offer and their uses.
  • 30. Systemctl What is a Unit File? A unit file is a flat text file that contains information about a service, socket, device, mount point, swap file, partition, start-up target, an asset management slice, or a group of externally created processes. Working with Unit Files List Units The list-units command displays all the active systemd services on your server. Our output is similar to the information provided by the systemctl status command, but not as detailed. systemctl list-units
  • 31. Systemctl Here is the example of the output of that command. root@host [~]# systemctl list-units UNIT LOAD ACTIVE SUB DESCRIPTION crond.service loaded active running Command Scheduler dovecot.service loaded active running Dovecot IMAP/POP3 email server firewalld.service loaded active running firewalld - dynamic firewall daemon httpd.service loaded active running The Apache HTTP Server mariadb.service loaded active running MariaDB database server named.service loaded active running Berkeley Internet Name Domain (DNS)
  • 32. Systemctl Now that we have an example of the output, let's review the meaning of each column. UNIT: The name of the systemd unit. LOAD: This indicates if the unit's configuration is being loaded by systemd. If it is, the configuration is stored in the server's memory. ACTIVE: This states the status of the unit and shows whether it is active or not. SUB: This provides more detailed information about the unit, which will vary depending on the type of unit, state, and the method the unit runs in. DESCRIPTION: This short description contains what each unit is and what it does.
  • 33. Systemctl Unit States Using the systemctl list-units command will reveal all the units that are “loaded” and “active” state in the LOAD and ACTIVE columns; however, if we wish to get a more detailed list of all the services, we need to employ the usage of command flag. In this case, the --all flag. systemctl list-units --all Using the -all flag, we can obtain a list of all the systemd units that are loaded or that systemd has tried to load. This output will also show the services that are currently in an inactive, dead, failed state, or that have not been found on the disk of the server.
  • 34. Systemctl While this flag provides the full output of all the units on the server, which systemd loaded into memory, we can use additional flags to further filter the output of list-units. One of them would be the --state= flag. We can use this flag to further filter the state in the LOAD, ACTIVE, and SUB columns. systemctl list-units --all --state=failed Just as we can filter out the units by their state, we can also use the same type to accomplish the same task. systemctl list-units --all --type=mount
  • 35. Systemctl The list-units command displays the units that systemd has loaded or attempted to load into memory. But, what about the units that are not in the systemd memory? This is where the list-unit-files flag comes into play, as this command will display all available units on the server. systemctl list-unit-files
  • 36. Systemctl The output will be given in two columns with the name of a file and state. UNIT FILE STATE Proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount static proc-sys-fs-binfmt_misc.mount static sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static tmp.mount disabled The STATE column had four different states, which are: Enabled Disabled Static Masked
  • 37. Systemctl Masked Units As you can see in the output above, many of the units show a staticSTATE status. This indicates that those units do not have an “install” section within the unit's configuration file, and therefore, cannot be enabled. On the other hand, some units may be masked, and as such, we will not be able to start it. Masked units will provide output using the start command if we attempt to launch it. systemctl start servicename.service Failed to start servicename.service: Unit is masked. Unmasking a unit is simple and will return the unit to the state where it can be started or enabled. systemctl unmask servicename.service
  • 38. Systemctl Creating a Unit File Occasionally, we may need to create a unit file for a custom daemon or another instance of an already existing service. The creation of a unit file is executed via the root user in the /etc/systemd/system/ directory. This is accomplished like so. touch /etc/systemd/system/servicename.service chmod 644 /etc/systemd/system/servicename.service
  • 39. Systemctl Next, we will open the newly created unit file in a text editor (like vim or nano) and add the service configuration options. Below, we can see a basic example of the unit file. [Unit] Description=This is the manually created service After=network.target [Service] ExecStart=/path/to/executable [Install] WantedBy=multi-user.target
  • 40. Systemctl Let’s quickly breakdown what these settings mean before we proceed further: Description: The description is the description of the service, and will be displayed when we use the systemctl status command for the created service. After: The After setting indicates that a service will only start on reboot after a specified target or another service has been started. ExecStart: The ExecStart is the path to the actual executable file of the service. WantedBy: The WantedBy setting states the target that the service should start under. This is similar to runlevels.
  • 41. Systemctl Once the service file has been created, we will need to tell the system about it with the following commands. systemctl daemon-reload systemctl start servicename.service
  • 42. Systemctl Viewing a Unit File Once the unit file has been created, we do not necessarily need to navigate to the file itself to see what is written inside. The systemctl command has a feature that displays the content of the unit file for us. It can be performed with the following command. systemctl cat servicename.service
  • 43. Systemctl Viewing Dependencies Just like we can see inside a unit file, we can also use the following command to display the dependency tree of that unit. systemctl list-dependencies servicename.service [root@host ~]# systemctl list-dependencies httpd.service httpd.service ● ├─-.mount ● ├─system.slice ● └─basic.target ● ├─microcode.service ● ├─rhel-dmesg.service ● ├─selinux-policy-migrate-local-changes@targeted.service ● ├─paths.target ● ├─slices.target ● │ ├─-.slice ● │ └─system.slice
  • 44. Systemctl There are a few useful flags that can be added to the command such as the --all flag which lists all dependencies recursively, or --reverse which will list them in reverse order. There is also the --before and --after flags which are used to show unit starting before or after the specified unit.
  • 45. Systemctl View Properties Additionally, we can see the properties of a unit by using the show command. systemctl show servicename.service This will give you output similar to the one below. [root@host ~]# systemctl show httpd.service Type=notify Restart=no NotifyAccess=main RestartUSec=100ms TimeoutStartUSec=1min 30s TimeoutStopUSec=1min 30s WatchdogUSec=0 WatchdogTimestamp=Thu 2020-06-25 05:43:53 EDT
  • 46. Systemctl In case you are looking for a single setting, you can use -p flag with the setting name. For example, to get the PID of a running service, use this command. [root@host ~]# systemctl show httpd.service -p MainPID MainPID=4004
  • 47. Systemctl Edit Unit Files In cases where the unit files need to be modified, systemctl has a built-in editing system that allows us to modify unit files without searching for them on the server. This can be done using the edit command. systemctl edit httpd.service This creates a directory in /etc/systemd/system named the same as the service with a .d appended to it. It looks this: /etc/systemd/system/httpd.service.d. This is where the edits would be stored, and any directives within this file would override the main unit file. The snippet created in that directory would be named override.conf. In case we wish to edit using file itself rather than creating a snippet, we can use the following command. systemctl edit --full httpd.service
  • 48. Systemctl Removing Unit Files Removing a unit file and overriding snippets can be accomplished using the following commands. rm -r /etc/systemd/system/httpd.service.d We can use the command below to remove the snippet directory, which overrides directives and removes the full modified unit file. rm /etc/systemd/system/httpd.service Whenever we make edits or remove any of the unit files, we need to make sure that changes are applied by using this command. systemctl daemon-reload
  • 49. Systemctl Using Targets (Runlevels) What is a Systemd Target? When it comes to unit files, there are special files that we call targets that describe a system state or synchronization point. These files can be identified by a suffix, which is called .target. What are these .target files for? They can be used to change the system to certain states, similar to how other init systems use runlevels.
  • 50. Systemctl List Targets There is a number of target files on the server systems, and we can list them using the following command. systemctl list-unit-files --type=target While working with runlevels, activating the runlevels is done one at a time, but when it comes to targets, we can activate multiple targets at once. In order to see all active targets, we use the following command. systemctl list-units --type=target
  • 51. Systemctl Stopping or Rebooting the Server Finally, we can use systemctl to stop the server, power it off, or to reboot it. For stopping the server, we use the following halt command. systemctl halt To completely shut down the server, we use poweroff command. systemctl poweroff And to reboot the server, we can use the reboot command. systemctl reboot