March 23, 2018

How to use systemctl

systemctl status sshd

The latest version of Linux uses systemd(PID 1) rather than the init process. The command to control this systemd is systemctl.

UsasgeDescription
systemctl list-unitsPrint units with the active state.
systemctl list-units --type servicePrint service units with the active state.
systemctl list-units --type service -aPrint service units with the active, inactive and not-found state.
systemctl list-unit-filesPrint whether the unit is enabled, disabled or static.
systemctl status sshdPrint the status of sshd service.
systemctl stop sshdStop the sshd service.
systemctl start sshdStart the sshd service
systemctl restart sshdRestart the sshd service
systemctl disable sshdDisable the sshd service.
systemctl enable sshdEnable the sshd service.
  * Enable : When the system boots, It is executed automatically.
systemctl mask sshdSet the mask for the sshd service.
  * mask : A configuration that prevents the unit from execute.
systemctl unmask sshdRemove the mask for the sshd service.
systemctl reload sshdReload the mask for the sshd service.
systemctl list-dependencies sshdPrint dependency of sshd service.
systemctl get-defaultPrint default-target.
  * Previous Linux's runlevel has been changed to target.
  * See /etc/inittab for details.
systemctl set-default [Target]Change the default-target.
  * Target : multi-user.target(CLI) graphical.target(GUI)
systemctl isolate [Target]Change current target.