Red Hat System Administration I
Use the systemctl command to stop, start, restart, reload, enable, and disable the systemd services.
Outcomes
Use the
systemctlcommand to control thesystemdservices.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start services-control
Instructions
Log in to the
serveramachine as thestudentuser and switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Restart and reload the
sshdservice, and observe the results.Display the status of the
sshdservice. Note the process ID of thesshddaemon. Press q to exit the command.[root@servera ~]#
systemctl status sshd● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2022-05-19 04:04:45 EDT; 16min ago Docs: man:sshd(8) man:sshd_config(5)Main PID: 784 (sshd)Tasks: 1 (limit: 10799) Memory: 6.6M ...output omitted...Restart the
sshdservice and view the status. In this example, the process ID of the daemon changes from 784 to 1193. Press q to exit the command.[root@servera ~]#
systemctl restart sshd[root@servera ~]#systemctl status sshd● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2022-05-19 04:21:40 EDT; 5s ago Docs: man:sshd(8) man:sshd_config(5)Main PID: 1193 (sshd)Tasks: 1 (limit: 10799) Memory: 1.7M ...output omitted...Reload the
sshdservice and view the status. The process ID of the daemon does not change. Press q to exit the command.[root@servera ~]#
systemctl reload sshd[root@servera ~]#systemctl status sshd● sshd.service - OpenSSH server daemon Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2022-05-19 04:21:40 EDT; 52s ago Docs: man:sshd(8) man:sshd_config(5) Process: 1201 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)Main PID: 1193 (sshd)Tasks: 1 (limit: 10799) Memory: 1.7M ...output omitted...
Verify that the
chronydservice is running. Press q to exit the command.[root@servera ~]#
systemctl status chronyd● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)Active: active (running)since Thu 2022-05-19 04:04:44 EDT; 19min ago ...output omitted...Stop the
chronydservice and view the status. Press q to exit the command.[root@servera ~]#
systemctl stop chronyd[root@servera ~]#systemctl status chronyd○ chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)Active: inactive (dead)since Thu 2022-05-19 04:24:59 EDT; 4s ago ...output omitted... May 19 04:24:59 servera.lab.example.com systemd[1]:Stopping NTP client/server...May 19 04:24:59 servera.lab.example.com systemd[1]:chronyd.service: Deactivated successfully.May 19 04:24:59 servera.lab.example.com systemd[1]:Stopped NTP client/server.Determine whether the
chronydservice is enabled to start at system boot.[root@servera ~]#
systemctl is-enabled chronydenabledReboot the
serveramachine, and then view the status of thechronydservice.[root@servera ~]#
systemctl rebootConnection to servera closed by remote host. Connection to servera closed. [student@workstation ~]$Log in as the
studentuser on theserveramachine, and switch to therootuser. View the status of thechronydservice. Press q to exit the command.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#systemctl status chronyd● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)Active: active (running)since Thu 2022-05-19 04:27:12 EDT; 40s ago ...output omitted...Disable the
chronydservice so that it does not start at boot, and then view the status of the service. Press q to exit the command.[root@servera ~]#
systemctl disable chronydRemoved /etc/systemd/system/multi-user.target.wants/chronyd.service. [root@servera ~]#systemctl status chronyd● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service;disabled; vendor preset: enabled) Active: active (running) since Thu 2022-05-19 04:27:12 EDT; 2min 48s ago ...output omitted...Reboot
servera, and then view the status of thechronydservice.[root@servera ~]#
systemctl rebootConnection to servera closed by remote host. Connection to servera closed. [student@workstation ~]$Log in as the
studentuser onservera, and view the status of thechronydservice. Press q to exit the command.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$systemctl status chronyd○ chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service;disabled; vendor preset: enabled)Active: inactive (dead)Docs: man:chronyd(8) man:chrony.conf(5)Return to the
workstationsystem as thestudentuser.[student@servera ~]$
exitlogout Connection to servera closed. [student@workstation ~]$