Auto login and `startx` without a display manager (systemd)

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Message
Author
User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 135 times

Re: Auto login and `startx` without a display manager -- jes

#41 Post by Head_on_a_Stick »

milomak wrote:it boots into x when it's set to graphical.target
Will it startx from a console log in?
deadbang

milomak
Posts: 2204
Joined: 2009-06-09 22:20
Been thanked: 2 times

Re: Auto login and `startx` without a display manager — jess

#42 Post by milomak »

yes startx works when it loads into console
Desktop: A320M-A PRO MAX, AMD Ryzen 5 3600, GALAX GeForce RTX™ 2060 Super EX (1-Click OC) - Sid, Win10, Arch Linux, Gentoo, Solus
Laptop: hp 250 G8 i3 11th Gen - Sid
Kodi: AMD Athlon 5150 APU w/Radeon HD 8400 - Sid

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 135 times

Re: Auto login and `startx` without a display manager — jess

#43 Post by Head_on_a_Stick »

Can we see:

Code: Select all

systemctl cat getty@tty1
deadbang

milomak
Posts: 2204
Joined: 2009-06-09 22:20
Been thanked: 2 times

Re: Auto login and `startx` without a display manager — jess

#44 Post by milomak »

sure

Code: Select all

$ systemctl cat getty@tty1
# /lib/systemd/system/getty@.service
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[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
After=rc-local.service

# If additional gettys are spawned during boot then we should make
# sure that this is synchronized before getty.target, even though
# getty.target didn't actually pull it in.
Before=getty.target
IgnoreOnIsolate=yes

# IgnoreOnIsolate causes issues with sulogin, if someone isolates
# rescue.target or starts rescue.service from multi-user.target or
# graphical.target.
Conflicts=rescue.service
Before=rescue.service

# On systems without virtual consoles, don't start any getty. Note
# that serial gettys are covered by serial-getty@.service, not this
# unit.
ConditionPathExists=/dev/tty0

[Service]
# the VT is cleared by TTYVTDisallocate
ExecStart=-/sbin/agetty --noclear %I $TERM
Type=idle
Restart=always
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes

# Unset locale for the console getty since the console has problems
# displaying some internationalized messages.
Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELE

[Install]
WantedBy=getty.target
DefaultInstance=tty1

# /etc/systemd/system/getty@tty1.service.d/override.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin mythtv --noclear %I $TERM
Desktop: A320M-A PRO MAX, AMD Ryzen 5 3600, GALAX GeForce RTX™ 2060 Super EX (1-Click OC) - Sid, Win10, Arch Linux, Gentoo, Solus
Laptop: hp 250 G8 i3 11th Gen - Sid
Kodi: AMD Athlon 5150 APU w/Radeon HD 8400 - Sid

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 135 times

Re: Auto login and `startx` without a display manager — jess

#45 Post by Head_on_a_Stick »

Does the autologin itself work?

Try removing the `startx` line from ~/.profile and see if it will autologin to a TTY command line.

You could also try this logic in ~/.profile instead of the line you are using now:

Code: Select all

[ "$(tty)" = "/dev/tty1" ] && exec startx /usr/bin/kodi
That doesn't rely on $XDG_VTNR or $DISPLAY.

EDIT: the Xorg logs will be found in ~/.local/share/xorg/Xorg.0.log because the server is being run as your normal user ;)
deadbang

Peripatus
Posts: 3
Joined: 2018-11-22 12:47

Re: Auto login and `startx` without a display manager — jess

#46 Post by Peripatus »

Head_on_a_Stick, thank you!

FWIW, I can confirm that the procedure works, without modification, for my system running BunsenLabs Helium (i.e. ~Debian Stretch). :D

Makes for a real fast boot-to-GUI -- and near-instant resume from Suspend! Ideal for an older computer mainly used as an internet tv.

No upgrade-proofness tested yet.

[NB: To anyone else who initially mistypes their username in the override.conf file (no capital letters! :roll: ), and reboots to find only a blinking cursor: don't panic; hit Ctl+Alt+F2 to open an auxiliary terminal; login with the correct username and password; optionally start the GUI by typing startx; fix the typo in the file; reboot; enjoy the smoothness.]

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 135 times

Re: Auto login and `startx` without a display manager — jess

#47 Post by Head_on_a_Stick »

Peripatus wrote:I can confirm that the procedure works, without modification, for my system running BunsenLabs Helium (i.e. ~Debian Stretch). :D
BunsenWhat? :mrgreen:

But anyway, yes, I've had it working in stretch and buster as well so I've changed the OP to reflect this.
deadbang

Peripatus
Posts: 3
Joined: 2018-11-22 12:47

Re: Auto login and `startx` without a display manager — jess

#48 Post by Peripatus »

Head_on_a_Stick wrote: BunsenWhat? :mrgreen:
Are you kidding me? :) Just noticed a rather active head on a stick over at the BunsenLabs forums...

Either way, I installed it just recently -- it's wonderful!

cheerio

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 135 times

Re: Auto login and `startx` without a display manager — jess

#49 Post by Head_on_a_Stick »

Peripatus wrote:rather active
Not any more :mrgreen:
deadbang

Peripatus
Posts: 3
Joined: 2018-11-22 12:47

Re: Auto login and `startx` without a display manager — jess

#50 Post by Peripatus »

Head_on_a_Stick wrote:
Peripatus wrote:rather active
Not any more :mrgreen:
Oh :? Should we take heed?

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 135 times

Re: Auto login and `startx` without a display manager — jess

#51 Post by Head_on_a_Stick »

Peripatus wrote:Should we take heed?
No, not at all, BL is one of the more excellent distributions out there, I just prefer vanilla Debian :)
deadbang

bedtime
Posts: 146
Joined: 2012-12-16 19:34
Has thanked: 1 time
Been thanked: 6 times

Re: Auto login and `startx` without a display manager (syste

#52 Post by bedtime »

I like how you dealt with issuing the startx command:

Code: Select all

[ "$(tty)" = "/dev/tty1" ] && exec startx
You negated the need for an 'if' command—clever! Always nice to do a command as efficiently as possible! :)

Thanx!

nyu-98
Posts: 5
Joined: 2019-03-26 00:35

Re: Auto login and `startx` without a display manager (syste

#53 Post by nyu-98 »

It's work , but now i see this in auth.log

Code: Select all

gnome-keyring-daemon[640]: couldn't access control socket: /run/user/1000/keyring/control: No such file or directory
i'm using debian 10 with mate desktop.


EDIT:
fixed with https://wiki.archlinux.org/index.php/GN ... PAM_method

mrowl
Posts: 2
Joined: 2019-10-15 13:31

Re: Auto login and `startx` without a display manager (syste

#54 Post by mrowl »

Hello All,
I followed the original howto and it worked fine for me with Debian 10.1 + Enlightenment DR16. I wanted to go further, though, and I don't know where to look at. My ultimate goal is to have the same Plymouth "theme" as I have in Enlightenment in that way the auto-logon executes and X starts at "the background" of the Plymouth skin (I see the Plymouth boot screen during the whole time and don't see any console output until I finally arrive to my E desktop) and when E16 starts I'd start also screen lock - this would effectively replace any DM for me but also gives some security measures.

My "very big" problem is that when bootup finishes, Plymouth closes the bootup screen and I can see the console autologin, including hostname and "Last login" lines. (Of course I could hide startx messages and motd easily.)

I understand that starting X includes changing the video driver and screen resolution so I don't expect a seamless transition from Plymouth screen to X's screen but I want to make this transition as smooth as possible (e.g. black screen for a second is OK). I couldn't find agetty parameter that suppress output and putting " > /dev/null 2&1" at the end of the systemd override file Exec line didn't help.

Do you have a tip where I should continue, please?
Thanks,
Mr 0wl

User avatar
wizard10000
Global Moderator
Global Moderator
Posts: 1087
Joined: 2019-04-16 23:15
Location: southeastern us
Has thanked: 117 times
Been thanked: 189 times

Re: Auto login and `startx` without a display manager — jess

#55 Post by wizard10000 »

Head_on_a_Stick wrote:No, not at all, BL is one of the more excellent distributions out there, I just prefer vanilla Debian :)
Same. My openbox install still uses a (slightly modified) #! theme :)
we see things not as they are, but as we are.
-- anais nin

mrowl
Posts: 2
Joined: 2019-10-15 13:31

Re: Auto login and `startx` without a display manager (syste

#56 Post by mrowl »

mrowl wrote:My ultimate goal is to have the same Plymouth "theme" as I have in Enlightenment in that way the auto-logon executes and X starts at "the background" of the Plymouth skin (I see the Plymouth boot screen during the whole time and don't see any console output until I finally arrive to my E desktop)
I somewhat solved the above.

/etc/systemd/system/getty@.service.d/override.conf:

Code: Select all

[Service]
ExecStart=
ExecStart=-/sbin/agetty -i -J --nohostname --skip-login --login-options "-f <username>" %I 38400 linux
...and I needed a touch ~/.hushlogin, too.

Now I only need to figure out how I can keep plymouth background on the screen further.

imazed
Posts: 4
Joined: 2021-08-15 17:39
Location: Oxfordshire
Has thanked: 2 times

Re: Auto login and `startx` without a display manager (systemd)

#57 Post by imazed »

Excellent information Thank you Head-on-a-stick.
I have just followed your instructions and works perfectly on my Debian "trixie" system.
So I was able to bin LightDM and Plymouth neither of which does anything useful.
I

vmclark
Posts: 188
Joined: 2008-07-30 15:16
Location: Usa
XMMP/Jabber: darbarritesh@rediffmail.com
Has thanked: 1 time
Contact:

Re: Auto login and `startx` without a display manager (systemd)

#58 Post by vmclark »

Works perfectly on Xubuntu. Tried other methods. They either failed or took too long to boot up.

milomak
Posts: 2204
Joined: 2009-06-09 22:20
Been thanked: 2 times

Re: Auto login and `startx` without a display manager -- jes

#59 Post by milomak »

Head_on_a_Stick wrote: 2016-05-21 20:18
milomak wrote:I am finding after doing updates (using sid), that

Code: Select all

/etc/systemd/system/getty.target.wants/getty@tty1.service
reverts to default.
OK, thanks for bringing that up.

My original method is a tad on the hacky side :)

For a more "correct" solution, create a file at /etc/systemd/system/getty@tty1.service.d/override.conf with the following content:

Code: Select all

[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin <user name> --noclear %I $TERM
This can be used instead of modifying the unit file and should survive upgrades ;)

EDIT: Note added to the end of the OP.
@Head_on_a_Stick this does not seem to be ion the op. was there a reason why not?
Desktop: A320M-A PRO MAX, AMD Ryzen 5 3600, GALAX GeForce RTX™ 2060 Super EX (1-Click OC) - Sid, Win10, Arch Linux, Gentoo, Solus
Laptop: hp 250 G8 i3 11th Gen - Sid
Kodi: AMD Athlon 5150 APU w/Radeon HD 8400 - Sid

seamusdemora
Posts: 17
Joined: 2024-04-04 01:53
Has thanked: 4 times

Re: Auto login and `startx` without a display manager (systemd)

#60 Post by seamusdemora »

From the "master post" on the first page:
Head_on_a_Stick wrote: 2015-07-18 01:06 This Howto is aimed at users who wish to automatically login to their Debian stable system and start the X server without having to enter startx at the command prompt.

It is primarily aimed at users of simple window manager environments rather then those who prefer fully-blown desktop environments as the latter usually have integrated display mangers to perform this function.

This guide only applies to those users who chose to run systemd as their init system.

If you have chosen to use SysVinit as PID1, refer to the "traditional" guides such as http://forums.debian.net/viewtopic.php?f=16&t=29333

This guide assumes an ability to edit system configuration files that may require root permissions to alter and will require correct configuration of the X server initialisation files at ~/.xsession or ~/.xinitrc (see startx(1) for more on this). If no ~/.xinitrc or ~/.xsession file is present then whatever is linked to /etc/alternatives/x-session-manager or /etc/alternatives/x-window-manager will be run instead (use the update-alternatives(1) command to change these).

For automatic login, run this command (as root):

Code: Select all

systemctl edit getty@tty1
Then enter this text and save the file afterwards:

Code: Select all

[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $username --noclear %I $TERM
Replace $username with your user name.

For automatic `startx` add this snippet to the end of the file at ~/.profile:

Code: Select all

[ "$(tty)" = "/dev/tty1" ] && exec startx
Finally, set the correct default.target to ensure the system boots to the console (TTY) rather than to a display manager:

Code: Select all

# systemctl set-default multi-user.target
To reverse this change, reset the default.target with:

Code: Select all

# systemctl set-default graphical.target
I have three (3) things to add:

1. I am SUGGESTING a change to @Head_on_a_stick's "master" HOW-TO back on page 1 of this topic.
I'll say first that I'm not sure this change is correct for everyone, BUT this is what worked for me on my 'bookworm' system.

The change:

FROM:
For automatic login, run this command (as root):

Code: Select all

systemctl edit getty@tty1
TO:
For automatic login, run this command:

Code: Select all

sudo vim /etc/systemd/system/getty.target.wants/getty@tty1.service
Please note that the code in the "TO:" section is from this post in the "lenny" version of this HOW-TO. I suspect that the current (FROM:) version may accomplish the same thing (via "drop-in file"?), but the instructions in the file were unclear to me - as many things are in 'systemd'.

2. Regarding the applicability of this "AutoLogin" recipe:
I have recently begun using `pipewire` to get Bluetooth Audio from my Raspberry Pi system. I use the 'Lite' version of their OS, and its Bluetooth features are, uh... primitive. `pipewire` has been a lifesaver, but it has one irritating "feature": When the user that started the music is logged out, `pipewire` "quits"; i.e. the music stops. I thought an "AutoLogin" would cure that issue, and I began searching for a solution when I found this (and the older "lenny" version) thread. I'd love to hear from anyone who's found another solution to the `pipewire` issue, but I can say that this (AutoLogin) works fine.

3. All that said, I am unclear why this (autologin) cannot be done as a simple `cron` job under `@reboot`. I've tried this on my "headless" Raspberry Pi; 'who' shows the user (pi) logged in on tty1, but it doesn't seem to be able to stop pipewire from quittin when pi logs out :( Too bad... I'll keep trying. It would certainly be much easier to edit the root crontab than a systemd unit file!

Code: Select all

$ sudo crontab -e
# add this one line:
@reboot /sbin/agetty -a pi --noclear tty1 linux

# afterwards, from my terminal:

$ who
pi       tty1         1970-01-06 16:57
pi       pts/0        -3386239902218181070 (192.168.1.209)
But it's not enough to keep `pipewire` from shutting down.

Post Reply