DEV Community

Mayeu
Mayeu

Posted on • Originally published at mayeu.me on

Running Systemd commands on remote host from your local host

While I was reading the pretty awesome Archlinux wiki for something completely different, I found out that one can launch any systemctlcommand to a remote host via the --host (or -H) flag.

So let say you want to check the cron process on a server named kitten:

$ systemctl -H root@kitten status cron
● cron.service - Regular background program processing daemon
   Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2018-07-28 11:36:37 CST; 2 months 25 days ago
     Docs: man:cron(8)
 Main PID: 1045
    Tasks: 1 (limit: 4643)
   CGroup: /system.slice/cron.service
           └─1045 /usr/sbin/cron -f

Nice right? Under the hood this use SSH so you must have access to the host. And you can, of course, use any systemctl command, not just status ;)

Have fun πŸ‘‹

This post was originally published on mayeu.me.

Top comments (3)

Collapse
 
ferricoxide profile image
Thomas H Jones II

Nice trick ...though feels like making Linux a bit more Windows-y. :p

Collapse
 
mayeu profile image
Mayeu

What are you referring to in Windows that is similar?

Collapse
 
ferricoxide profile image
Thomas H Jones II

Most of the Windows system administrator tools allow you to run them either locally or against a remote system.