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.
- SSH Passwordless Login Using SSH Keygen in 5 Easy Steps
- 5 Best Practices to Secure and Protect SSH Server
- 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
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:
- The Story Behind: Why ‘init’ Needed to be Replaced with ‘systemd’ in Linux
- Managing System Startup Process and Services (SysVinit, Systemd and Upstart)
- Manage Log Messages Under Systemd Using Journalctl [Comprehensive Guide]
- How to Create and Run New Service Units in Systemd Using Shell Script
- 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.
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.
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 commandex:
I want the correct command if any one know then tell me….
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
@Dark
The workaround is using ssh passwordless-login as recommended in the guide, to secure transactions between the local computer and the remote system.
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.
That is, put the public half off the ssh key pair into:
Can I depend from a systemd service launched on another vm?
A newer and better command “info” should be used instead of “man”.
@Vitek
Okay, thanks for the useful info.