How to Control Systemd Services on Remote Linux Server

Systemd system and services manager can be controlled using the systemctl command line utility. It enables you to manage systemd locally or on a remote Linux machine over the SSH protocol.

In this short article, we will show you how to manage systemd system and service manager on a remote Linux machine over a SSH session.

Attention: We recommend using public/private key pairs for passwordless authentication for SSH, as opposed to passwords, and also employing additional methods to secure SSH service, as explained in these guides.

  1. SSH Passwordless Login Using SSH Keygen in 5 Easy Steps
  2. 5 Best Practices to Secure and Protect SSH Server
  3. How to Block SSH and FTP Access to Specific IP and Network Range

To connect to a remote server, run systemctl with the --host or -H flag as follows. In the command below, we are connecting to the remote server as the root user and status is a subcommand of systemctl utility used to view the status of the httpd service on centos.temint.lan (remote Linux server).

$ systemctl --host [email protected] status httpd.service
OR
$ systemctl -H [email protected] status httpd.service
Manage Systemd Service on Remote Linux
Manage Systemd Service on Remote Linux

Similarly, you can also start, stop or restart remote systemd service as shown.

$ systemctl --host [email protected] start httpd.service   
$ systemctl --host [email protected] stop httpd.service
$ systemctl --host [email protected] restart httpd.service

To end the session, simply type [Ctrl+C]. For more information and usage options, see the systemctl man page:

$ man systemctl 

That’s all for now! What follows is an assortment of systemd articles which you’ll find useful:

  1. The Story Behind: Why ‘init’ Needed to be Replaced with ‘systemd’ in Linux
  2. Managing System Startup Process and Services (SysVinit, Systemd and Upstart)
  3. Manage Log Messages Under Systemd Using Journalctl [Comprehensive Guide]
  4. How to Create and Run New Service Units in Systemd Using Shell Script
  5. How to Change Runlevels (targets) in SystemD

In this article, we showed you how to manage systemd system and service manager on a remote Linux machine. Use the feedback section to ask questions or share your thoughts about this guide.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

9 Comments

Leave a Reply
  1. Hello,

    When trying to use a remote to ubuntu from centos it gives the below error, ubuntu to centos works with no issues.

    Failed to parse bus message: No such device or address

    Do you have any idea what is happening?

    Thanks.

    Reply
  2. Sandro,

    I have a question if the sshd service was killed by the user. If he frightened by the shutdown or other activity then we have systemctl --host command to restart another localhost using this command

    ex:

    $ systemctl --host [email protected] is-active sshd.service
    

    I want the correct command if any one know then tell me….

    Reply
  3. I get Permission denied (public key).

    I checked the man page for systemctl (Linux Mint Tricia) and there’s no information on authenticating using a certificate. Is there a work-around for this? Thanks

    Reply
    • @Dark

      The workaround is using ssh passwordless-login as recommended in the guide, to secure transactions between the local computer and the remote system.

      Reply
      • You can set up ssh passwordless login by using ssh-copy-id to put the public half of the ssh key pair into remotehost:/home/username/.ssh/config/authorized_keys.

        However, even when logged into the shell on the remote host, you have to use sudo to call systemctl unless there’s some way to set up systemctl so that user has access without sudo.

        I’m pretty sure that’s what the commenter was asking about, and I arrived at this page because I’m looking for the same information.

        Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.