You are not logged in.

#1 2020-04-17 12:22:33

lonlon
Member
Registered: 2019-09-07
Posts: 23

[SOLVED] Setting $SYSTEMD_EDITOR, $EDITOR or $VISUAL

Hello there,
recently I changed to an auto login via agetty as described in the ArchWiki:getty. The first method described is using systemctl edit but this results in the following

$ sudo systemctl edit getty@tty1
Cannot edit unit(s), no editor available. Please set either $SYSTEMD_EDITOR, $EDITOR or $VISUAL.
(editor) failed with exit status 1.

Issuing the env command I get

$ env
SHELL=/usr/bin/zsh
...
EDITOR=vi
...

I see how that is a problem as I only have neovim installed. So I tried changing the variable by adding to my "~/.xinitrc" (I also tried to add it to "~/.zprofile" with the same result) [ArchWiki:Environment variables]

# Set neovim as default editor
EDITOR="/usr/bin/nvim"
export EDITOR

Now I have

$ env
SHELL=/usr/bin/zsh
...
EDITOR=/usr/bin/nvim
...

But even after a reboot, I still get the same error message about setting my EDITOR variables.
Curiously enough though, when I issue

$ sudo EDITOR=/usr/bin/nvim systemctl edit getty@tty1  

it does work.

So obviously I am missing something but I could not figure out what it is.

It is not something that breaks my system, but nonetheless it is something that I feel like I should configure the right way. 

Last edited by lonlon (2020-04-17 13:27:11)

Offline

#2 2020-04-17 12:55:55

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,854

Re: [SOLVED] Setting $SYSTEMD_EDITOR, $EDITOR or $VISUAL

You're probably running "systemctl edit getty@tty1" a root with sudo, so altering the $EDITOR for your regular user will have what effect on that environment?

Offline

#3 2020-04-17 13:06:06

lonlon
Member
Registered: 2019-09-07
Posts: 23

Re: [SOLVED] Setting $SYSTEMD_EDITOR, $EDITOR or $VISUAL

Sorry I had a mistake in my post. I am logged in as a regular user XYZ and run the command

sudo systemctl edit getty@tty1

I thought it means that I run the command as this user with root privileges and thus it should use the editor that I specified via the "~/.xinitrc" of that user XYZ, right?

Offline

#4 2020-04-17 13:10:23

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,384

Re: [SOLVED] Setting $SYSTEMD_EDITOR, $EDITOR or $VISUAL

.xinitrc is in any case the wrong place to specify this, but no if you run the command with sudo, sudo will not carry over your own user's environment. Tell it to keep editor: https://wiki.archlinux.org/index.php/Su … _variables or rely on polkit and don't use sudo for the systemctl command

Last edited by V1del (2020-04-17 13:11:07)

Offline

#5 2020-04-17 13:23:00

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,520
Website

Re: [SOLVED] Setting $SYSTEMD_EDITOR, $EDITOR or $VISUAL

lonlon wrote:

I thought it means that I run the command as this user with root privileges

No.  That's non-sensical and impossible.  It runs with root privileges because it runs as root.

man sudo wrote:

DESCRIPTION
     sudo allows a permitted user to execute a command as the superuser or another user...

But also see

man sudo wrote:

     -E, --preserve-env
                 Indicates to the security policy that the user wishes to preserve their existing environment variables...

Or just set those variables in the root shell rc or system-wide.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2020-04-17 13:24:11

lonlon
Member
Registered: 2019-09-07
Posts: 23

Re: [SOLVED] Setting $SYSTEMD_EDITOR, $EDITOR or $VISUAL

Oh, I did not know that, thank you for pointing that out.

Now that I have added to my /etc/sudoers

Defaults env_keep += "EDITOR=/usr/bin/nvim

it does actually work.

I also removed the parts from the "~/.xinitrc" and moved them over to "./zprofile", I hope that is now the right way to do it.

Thank you!

Last edited by lonlon (2020-04-17 13:28:45)

Offline

Board footer

Powered by FluxBB