I have Debian Jessie and connect to it by ssh. I want to autostart shell command on user login by systemd.

I've create a simple systemd service ~/.config/systemd/user/foo.service witch contains:

Description=Systemd autostart test

ExecStart=/bin/sh -c "echo 123 >> /home/user/there;"


I've enable it by systemctl

systemctl --user enable foo

I've created success message container

touch ~/there

and after reboot and login (by ssh) ~/there file is empty.

When I use it manually

systemctl --user restart foo

it works.

What am I missing?

  • 1
    systemd normally does not allow ordinary users to start system services. Why not using .profile ?
    – Froggiz
    Nov 28, 2015 at 10:21
  • @Froggiz very late reply, but: systemd doesn't allow ordinary users to start system services, yes. But as is clear in the question, the user is calling systemctl --user, which is for user services, not system ones.
    – me_and
    Dec 15, 2021 at 10:44

2 Answers 2


By default, users cannot set user services to run at boot time. The admin must enable this on an individual basis for each user.

sudo loginctl enable-linger <username>

From the documentation:

Enable/disable user lingering for one or more users. If enabled for a specific user, a user manager is spawned for the user at boot and kept around after logouts. This allows users who are not logged in to run long-running services. Takes one or more user names or numeric UIDs as argument. If no argument is specified, enables/disables lingering for the user of the session of the caller.

You also need to set the correct target for WantedBy= as Climenty explained in another answer. The multi-user.target does not exist for user services; by default there is only default.target.


Try this


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.