5

I'm looking at the following line in /usr/lib/systemd/system/sshd.service file on a Fedora 25 box:

ExecStart=/usr/sbin/sshd -D $OPTIONS

I'm not sure where $OPTIONS comes from. It looks like an environment variable, although when I set a shell variable that way it is ignored, e.g.

# OPTIONS='-p 9999'
# systemctl start sshd

I read through the command lines portion of the systemd.service man page, which indicates that environment variables can be set via an Environment line:

Environment="ONE=one" 'TWO=two two'

However, no such OPTIONS variable is set there.

There is additionally an EnvironmentFile line, e.g.:

EnvironmentFile=-/etc/sysconfig/sshd

No $OPTIONS variable is set there either. To what does $OPTIONS refer, and how is it set?

3
  • Have you tried to set the env variable export OPTIONS='-p 9999' before the systemctl start sshd? – Michael D. Mar 11 '17 at 1:31
  • 2
    You can probably set it in the EnvironmentFile, but it's empty (doesn't exist) by default. – jordanm Mar 11 '17 at 4:14
  • 1
    @MichaelD. Systemd would be pretty broken if it didn't start services in a clean environment. invoke-rc.d and service commands have always cleaned the environments, systemd is no different. – jordanm Mar 11 '17 at 4:15
6

The unit file in Debian is similar, containing:

[Service]
EnvironmentFile=-/etc/default/ssh
ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
ExecReload=/bin/kill -HUP $MAINPID

Here, the EnvironmentFile assigns SSHD_OPTS:

# Options to pass to sshd
SSHD_OPTS=

It's likely that Fedora uses a similar system, but for some reason they just haven't explicitly set the variable. That shouldn't matter, it should expand to an empty string.

There's a mention here that e.g. httpd.service uses OPTIONS similarly, and sets it in /etc/sysconfig/httpd. So it's likely just unset for some reason.

You could check sshd's command line with ps to see what the variable is expanded to, and also set it to something in the sysconfig file to check that it works if set there.


As for setting the environment variable on the shell command line, AFAIU systemd doesn't run the services in the environment of the shell calling systemctl, but forks them off the main systemd process. That way they don't inherit settings of the shell environment even accidentally. Environment variables can have a wide range of effects and it would be annoying to have your services act differently depending on if they are started at system boot or restarted from the command line.

That $MAINPID however, it's special.

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.