You are not logged in.

#1 2013-09-08 15:12:34

nokangaroo
Member
Registered: 2013-09-08
Posts: 25

[SOLVED]Automatic login to virtual console - without automatic relogin

Improvements welcome.

This is a possible procedure for enabling autologin in archlinux without using a display manager. The procedure described in the "Automatic login to virtual console" ArchWiki has the serious bug that the user gets logged back in automatically at logout, which makes it impossible to log in as another user at the console. A possible (partial) solution is the following:


1. Create a new getty:

cp /usr/lib/systemd/system/getty@.service /etc/systemd/system/getty1@.service #I suppose you can call it whatever you want


2. Modify the following lines in the [Service] section to look like this:

ExecStart=-/sbin/agetty --autologin <username> --noclear %I 38400 linux
Type=oneshot
Restart=no


The [Install] section remains the same:

Alias=getty.target.wants/getty@tty1.service


3. Enable the new service:

ln -sf /etc/systemd/system/getty1@.service /etc/systemd/system/getty.target.wants/getty@tty9.service
systemctl start getty@tty9.service
reboot


This will log the specified user into tty9, and as the service is not restarted, the original getty will be available at logout. I call this solution partial because automatic login cannot be stopped by entering something at the original getty; you have to wait until the login is complete and log out before being able to log in as another user. Also, there is a slight delay before the login prompt reappears.

Does anybody know how to stop this getty@tty9.service by entering keystrokes before it loads? That is, to enable a timeout for manual login? (I mean, short of installing a display manager. I couldn't find anything meaningful in man agetty and man login)

Last edited by nokangaroo (2013-09-15 02:34:07)

Offline

#2 2013-09-08 15:15:26

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

Re: [SOLVED]Automatic login to virtual console - without automatic relogin

RE: delay: https://wiki.archlinux.org/index.php/Au … al_console

EDIT: sorry, your comment below is correct.

Last edited by Trilby (2013-09-08 17:36:58)


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

Offline

#3 2013-09-08 17:33:53

nokangaroo
Member
Registered: 2013-09-08
Posts: 25

Re: [SOLVED]Automatic login to virtual console - without automatic relogin

You mean type-idle. I don't see how this is relevant; it will delay the execution of agetty but not stop it. I need type=oneshot to keep the service from restarting. I'll keep looking but this isn't it.

Offline

#4 2013-09-08 19:20:17

progandy
Member
Registered: 2012-05-17
Posts: 5,259

Re: [SOLVED]Automatic login to virtual console - without automatic relogin

I guess you could create a custom getty, that evaluates a keystroke and the performs the autologin or asks for the username and password.
Or add a simple wrapper for the login program that does that. No need to patch agetty.

Last edited by progandy (2013-09-08 19:30:54)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#5 2013-09-10 14:04:13

nokangaroo
Member
Registered: 2013-09-08
Posts: 25

Re: [SOLVED]Automatic login to virtual console - without automatic relogin

Edit: I found a solution with only one custom getty:

1. Add "quiet" to GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub to avoid obscuring the login prompt with boot messages, otherwise this will not work.

2. create a file /etc/systemd/system/getty0@tty1.service (replace <username> with the actual user. This file is copied and modified from /usr/lib/systemd/system/getty@.service; I omitted the original comments for brevity's sake):

#This file provides a choice between manual and automatic login

[Unit]
Description=Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html

After=systemd-user-sessions.service plymouth-quit-wait.service

Before=getty.target
Before=getty@tty1.service #Otherwise you won't get the login prompt back after logout

IgnoreOnIsolate=yes

ConditionPathExists=/dev/tty0

[Service]
ExecStart=-/sbin/agetty -p --noclear --timeout 5 %I 38400 linux
ExecStartPost=-/sbin/agetty --autologin <username> --noclear  %I 38400 linux
Type=oneshot
Restart=no
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no

Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=

KillSignal=SIGHUP

[Install]
Alias=getty.target.wants/getty@tty1.service

3. To enable it do the following (as root):

ln -sf /etc/systemd/system/getty0@tty1.service /etc/systemd/system/getty.target.wants/getty0@tty1.service
ln -sf /usr/lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
systemctl start getty@tty1.service

After logging out of the manual login, autologin kicks in automatically (but only once).

Disclaimer: This modifies the actual login. Do it only if you can get back in on failure (e.g. chroot from a rescue system)

Last edited by nokangaroo (2013-09-15 01:47:40)

Offline

#6 2013-09-15 19:18:41

nokangaroo
Member
Registered: 2013-09-08
Posts: 25

Re: [SOLVED]Automatic login to virtual console - without automatic relogin

I might as well add that I am not entirely satisfied with this solution, as the "oneshot" type inhibits the spawning of new gettys, so switching to a new VT is rather slow. But this is as far as I can get without further help. Using anything but "oneshot" would be unsafe.

Offline

#7 2013-09-15 23:18:53

nokangaroo
Member
Registered: 2013-09-08
Posts: 25

Re: [SOLVED]Automatic login to virtual console - without automatic relogin

Edit: I found a solution that allows fast spawning of gettys at least after the autologin. Since the whole purpose of this gig is to log in as root for maintenance before starting the graphics, the slow respawning in the manual login is not very serious.

1. create an autologin getty:

cp /lib/systemd/system/getty@.service /etc/systemd/system/getty1@tty1.service

2. change the "ExecStart" line of /etc/systemd/system/getty1@tty1.service to look like this:

ExecStart=-/sbin/agetty --autologin <username> --noclear  %I 38400 linux

3. create a custom getty /etc/systemd/system/getty0@tty1.service:

#This file provides a choice between manual and automatic login

[Unit]
Description=Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html

After=systemd-user-sessions.service plymouth-quit-wait.service

Before=getty.target
Before=getty1@tty1.service

IgnoreOnIsolate=yes

ConditionPathExists=/dev/tty0

[Service]
# An ExecStart command is syntactically required (Why???)
ExecStart=-/usr/bin/true
ExecStop=-/sbin/agetty -p --noclear --timeout 5 %I 38400 linux
Type=oneshot
Restart=no
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no

Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=

KillSignal=SIGHUP

[Install]
Alias=getty.target.wants/getty@tty1.service

4. Enable:

ln -sf /etc/systemd/system/getty1@tty1.service /etc/systemd/system/getty.target.wants/getty1@tty1.service
ln -sf /etc/systemd/system/getty0@tty1.service /etc/systemd/system/getty.target.wants/getty0@tty1.service
systemctl daemon-reload
reboot

Edit: It seems to be possible after all to use "Type=idle" for both services:

1. /etc/systemd/system/getty0@tty1.service:

#This file provides a choice between manual and automatic login

[Unit]
Description=Getty-manual on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html

After=systemd-user-sessions.service plymouth-quit-wait.service

Before=getty.target

IgnoreOnIsolate=yes

ConditionPathExists=/dev/tty0

#This ensures that getty0@tty1.service gets started first (and exclusively):
Conflicts=getty1@tty1.service

[Service]
ExecStart=-/sbin/agetty -p --noclear --timeout 5 %I 38400 linux
ExecStopPost=-/usr/bin/systemctl start getty1@tty1
Type=idle
Restart=no
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no

Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=

KillSignal=SIGHUP

[Install]
Alias=getty.target.wants/getty@tty1.service

2. /etc/systemd/system/getty1@tty1.service:

#This file provides an automatic login

[Unit]
Description=Getty-autologin on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html

After=systemd-user-sessions.service plymouth-quit-wait.service

Before=getty.target

IgnoreOnIsolate=yes

ConditionPathExists=/dev/tty0

[Service]
ExecStart=-/sbin/agetty --autologin <username> --noclear %I 38400 linux
ExecStop=-/usr/bin/systemctl start getty@tty1
Type=idle
Restart=no
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no

Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=

KillSignal=SIGHUP

[Install]
Alias=getty.target.wants/getty@tty1.service

Note that the autologin getty is not restarted; instead it starts a standard getty when it exits.
And no more "Before=" or "After=" except the defaults. The "Conflicts=" condition is sufficient.



I haven't found a solution yet that doesn't rely on agetty's built-in timeout function. A timer file like the following will start the autologin getty regardless of whether you try to log in manually or not:

# /etc/systemd/system/getty1@tty1.timer

[Unit]
Description=Timer for Getty-autologin on %I

[Timer]
OnActiveSec=5
Unit=getty1@tty1.service

[Install]
WantedBy=getty.target

Feel free to experiment.

Last edited by nokangaroo (2013-09-19 08:57:54)

Offline

Board footer

Powered by FluxBB