DEV Community

Mayeu
Mayeu

Posted on β€’ Originally published at mayeu.me on

8 1

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.

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

πŸ‘‹ Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Communityβ€”every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple β€œthank you” goes a long wayβ€”express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay