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

Share your own howto's etc. Not for support questions!
Message
Author
User avatar
Head_on_a_Stick
Posts: 13593
Joined: 2014-06-01 17:46
Location: /dev/chair
Has thanked: 1 time
Been thanked: 28 times

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

#1 Post by Head_on_a_Stick »

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
Last edited by Head_on_a_Stick on 2020-02-26 15:58, edited 12 times in total.
"It seems that UNIX has become the victim of cancerous growth at the hands of organizations such as UCB. 4.2BSD is an order of magnitude larger than Version 5, but, Pike claims, not ten times better."

— Murray Hill, Bell Laboratories

User avatar
mzsade
Posts: 91
Joined: 2011-12-08 01:25

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

#2 Post by mzsade »

Nope, tried out the auto-login part, still have to type in my user name and password to get to my Desktop. Shutdown and cold booted just to make sure. Could rEFind have something to do with it?
On the positive side, my first foray into this systemd territory did not break anything. :)
Linux User #481272 Reg: 15th Sept., 2008

User avatar
Head_on_a_Stick
Posts: 13593
Joined: 2014-06-01 17:46
Location: /dev/chair
Has thanked: 1 time
Been thanked: 28 times

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

#3 Post by Head_on_a_Stick »

mzsade wrote:Nope, tried out the auto-login part, still have to type in my user name and password to get to my Desktop.
Hmm strange -- I tested this on my jessie system before posting.

What is the content of /etc/systemd/system/getty.target.wants/getty@tty1.service and what is the output of:

Code: Select all

systemctl status default.target
ls -l /etc/systemd/system/display-manager.service
"It seems that UNIX has become the victim of cancerous growth at the hands of organizations such as UCB. 4.2BSD is an order of magnitude larger than Version 5, but, Pike claims, not ten times better."

— Murray Hill, Bell Laboratories

User avatar
mzsade
Posts: 91
Joined: 2011-12-08 01:25

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

#4 Post by mzsade »

Code: Select all

~$ cat  /etc/systemd/system/getty.target.wants/getty@tty1.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

# 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_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION=

[Install]
WantedBy=getty.target
DefaultInstance=tty1
I have changed the ExecStart line back to what it was but really, it's no biggie, just wanted to try it out..

Code: Select all

~$ systemctl status default.target
● graphical.target - Graphical Interface
   Loaded: loaded (/lib/systemd/system/graphical.target; static)
   Active: active since Sat 2015-07-18 14:19:38 IST; 42min ago
     Docs: man:systemd.special(7)
~$ ls -l /etc/systemd/system/display-manager.service
lrwxrwxrwx 1 root root 35 Jul 11 09:36 /etc/systemd/system/display-manager.service -> /lib/systemd/system/lightdm.service
Linux User #481272 Reg: 15th Sept., 2008

User avatar
Head_on_a_Stick
Posts: 13593
Joined: 2014-06-01 17:46
Location: /dev/chair
Has thanked: 1 time
Been thanked: 28 times

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

#5 Post by Head_on_a_Stick »

mzsade wrote:

Code: Select all

~$ systemctl status default.target
● graphical.target - Graphical Interface
   Loaded: loaded (/lib/systemd/system/graphical.target; static)
   Active: active since Sat 2015-07-18 14:19:38 IST; 42min ago
     Docs: man:systemd.special(7)
~$ ls -l /etc/systemd/system/display-manager.service
lrwxrwxrwx 1 root root 35 Jul 11 09:36 /etc/systemd/system/display-manager.service -> /lib/systemd/system/lightdm.service
It didn't work because you have a display manager installed (LightDM) and your system is set to boot to the display manager by default ("graphical.target").

To get it working on your system, you need to either remove LightDM or run:

Code: Select all

# systemctl set-default multi-user.target
"It seems that UNIX has become the victim of cancerous growth at the hands of organizations such as UCB. 4.2BSD is an order of magnitude larger than Version 5, but, Pike claims, not ten times better."

— Murray Hill, Bell Laboratories

User avatar
mzsade
Posts: 91
Joined: 2011-12-08 01:25

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

#6 Post by mzsade »

How essential is this display manager, i would be completely at sea if i booted into the console or something like that.
Linux User #481272 Reg: 15th Sept., 2008

User avatar
Head_on_a_Stick
Posts: 13593
Joined: 2014-06-01 17:46
Location: /dev/chair
Has thanked: 1 time
Been thanked: 28 times

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

#7 Post by Head_on_a_Stick »

mzsade wrote:How essential is this display manage
IMO display managers are only useful for multi-user, multi-desktop systems.

Having said that, my $BETTER_HALF's laptop has 3 users and 2 different desktops and I still don't use a display manager on it...

Pure eye-candy bloat, especially if you have it set to auto-login.
mzsade wrote:i would be completely at sea if i booted into the console or something like that.

Code: Select all

startx
"It seems that UNIX has become the victim of cancerous growth at the hands of organizations such as UCB. 4.2BSD is an order of magnitude larger than Version 5, but, Pike claims, not ten times better."

— Murray Hill, Bell Laboratories

User avatar
mzsade
Posts: 91
Joined: 2011-12-08 01:25

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

#8 Post by mzsade »

Awesome, works like a charm. Is there a command to set things back as they were..
Linux User #481272 Reg: 15th Sept., 2008

User avatar
Head_on_a_Stick
Posts: 13593
Joined: 2014-06-01 17:46
Location: /dev/chair
Has thanked: 1 time
Been thanked: 28 times

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

#9 Post by Head_on_a_Stick »

mzsade wrote:Is there a command to set things back as they were..

Code: Select all

# systemctl set-default graphical.target
"It seems that UNIX has become the victim of cancerous growth at the hands of organizations such as UCB. 4.2BSD is an order of magnitude larger than Version 5, but, Pike claims, not ten times better."

— Murray Hill, Bell Laboratories

User avatar
mzsade
Posts: 91
Joined: 2011-12-08 01:25

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

#10 Post by mzsade »

Being able to someday ask you a linux question that baffles you is now on my bucket list. :D

Edit: I am a GUI monkey and deserve no respect..and lightdm is not as bloated as something similar for Gnome or Mate, right, right? No, i am a monkey and that's it. :-( Anyways, since i decided to live with lightdm, this is how i did it; http://forums.debian.net/viewtopic.php?f=10&t=116370
Linux User #481272 Reg: 15th Sept., 2008

User avatar
mzsade
Posts: 91
Joined: 2011-12-08 01:25

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

#11 Post by mzsade »

Sorry to be a pain in...I couldn't live with it, and i realized both the how-tos complement each other and have to be implemented together to avail of the full benefit (slow on the uptake, that's me). Since i didn't have a ~/.bash_profile, only a ~/.bashrc, i created an empty file and put that second "snippet"

Code: Select all

[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx
inside it. No results, not only that on the next reboot ~/.bash_profile was empty again!
Linux User #481272 Reg: 15th Sept., 2008

User avatar
Head_on_a_Stick
Posts: 13593
Joined: 2014-06-01 17:46
Location: /dev/chair
Has thanked: 1 time
Been thanked: 28 times

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

#12 Post by Head_on_a_Stick »

mzsade wrote:Since i didn't have a ~/.bash_profile, only a ~/.bashrc, i created an empty file and put that second "snippet" [...] inside it. No results, not only that on the next reboot ~/.bash_profile was empty again!
OK, thanks for the feedback.

I use zsh so I didn't check the .bash_profile bit... :/

Does it work if you put it in ~/.profile?
"It seems that UNIX has become the victim of cancerous growth at the hands of organizations such as UCB. 4.2BSD is an order of magnitude larger than Version 5, but, Pike claims, not ten times better."

— Murray Hill, Bell Laboratories

User avatar
mzsade
Posts: 91
Joined: 2011-12-08 01:25

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

#13 Post by mzsade »

Nope, i might have placed it incorrectly,

Code: Select all

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx
# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
	. "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
Last edited by mzsade on 2015-07-18 18:49, edited 2 times in total.
Linux User #481272 Reg: 15th Sept., 2008

User avatar
Head_on_a_Stick
Posts: 13593
Joined: 2014-06-01 17:46
Location: /dev/chair
Has thanked: 1 time
Been thanked: 28 times

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

#14 Post by Head_on_a_Stick »

Well, I just changed my shell to BASH and ~/.bash_profile works just fine and persists across reboots so I don't know why your system does that.

The snippet also works in my system if it's placed at the end of ~/.profile :?

What is the output of:

Code: Select all

echo $DISPLAY $XDG_VTNR $PATH
"It seems that UNIX has become the victim of cancerous growth at the hands of organizations such as UCB. 4.2BSD is an order of magnitude larger than Version 5, but, Pike claims, not ten times better."

— Murray Hill, Bell Laboratories

User avatar
mzsade
Posts: 91
Joined: 2011-12-08 01:25

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

#15 Post by mzsade »

My friend, my friend, you may yet make a man of this monkey..decided to READ the code for a change and it says right there as plain as can be;
"This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login exists."
Repositioned your code and deleted the blank ~/.bash_profile, and i cannot describe the joy of watching the magic of bash at work..
Linux User #481272 Reg: 15th Sept., 2008

User avatar
Head_on_a_Stick
Posts: 13593
Joined: 2014-06-01 17:46
Location: /dev/chair
Has thanked: 1 time
Been thanked: 28 times

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

#16 Post by Head_on_a_Stick »

Good stuff, glad you got it working :)

I'll edit the OP to reflect your very useful feedback -- thanks!
"It seems that UNIX has become the victim of cancerous growth at the hands of organizations such as UCB. 4.2BSD is an order of magnitude larger than Version 5, but, Pike claims, not ten times better."

— Murray Hill, Bell Laboratories

User avatar
Nili
Posts: 417
Joined: 2014-04-30 14:04
Location: $HOME/♫♪

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

#17 Post by Nili »

Heya there Head_on_a_Stick!!!

Good to be back, i was without system for 48h, during this time i fixed my mess :evil: mixing lenny with jessie :oops: let me outside.
...so glad to be back without formating :D

Ok lets go back right to question.

Perhaps you have posted somewhere, if so please guide me... Thank you.

ls -l /etc/systemd/system/getty.target.wants

Code: Select all

total 0
lrwxrwxrwx 1 root root 34 Jul 19 15:01 getty@tty1.service -> /lib/systemd/system/getty@.service
I think you know what i am looking for, an automatic login for one tty (tty1 precise) and an auto startx from /home/nili/.profile

Using this code

Code: Select all

    ExecStart=-/sbin/agetty -a <user name> %I $TERM
it's ok but log me in on both ttys 1&2. Let fix this first then checkup auto startx
Fedora GNOME // Devuan CWM

User avatar
Head_on_a_Stick
Posts: 13593
Joined: 2014-06-01 17:46
Location: /dev/chair
Has thanked: 1 time
Been thanked: 28 times

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

#18 Post by Head_on_a_Stick »

@Nili -- I think this may be a systemd bug.

AFAIU, the getty@tty1.service should *only* run for TTY1 but clearly this isn't happening.

On both my Arch & Debian systems, autologin is set for *all* TTYs

Does your system do this or is it only for TTYs 1&2?

Please post the output of:

Code: Select all

ls -lR /etc/systemd/system | grep -i tty
"It seems that UNIX has become the victim of cancerous growth at the hands of organizations such as UCB. 4.2BSD is an order of magnitude larger than Version 5, but, Pike claims, not ten times better."

— Murray Hill, Bell Laboratories

User avatar
Nili
Posts: 417
Joined: 2014-04-30 14:04
Location: $HOME/♫♪

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

#19 Post by Nili »

Then it may be such as you explain, perhaps a systemd issue. I have read and tried many ways during these days but none succeeded.
At the moment have turned off autologin, i'm only proceeding with auto startx this time. I really don't want to have many logged my username on other terminals.

I have two tty because... if you remember a thread and a chat that we have done therefore I have two because i choosed to use two tty.

Concretely, i have actived NAutoVTs=2 from "/etc/systemd/logind.conf" that reduces tty usages, so i chosed number 2.

Code: Select all

[Login]
NAutoVTs=2
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#HandlePowerKey=poweroff
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RemoveIPC=yes
I can test with more tty numbers, I believe that will be the same will autolog on every tty actived...
I will do a test tomorrow because today I have no more time sorry.

the output
nili@debian:~$ ls -lR /etc/systemd/system | grep -i tty

Code: Select all

drwxr-xr-x 2 root root 4096 Jul 19 15:01 getty.target.wants
/etc/systemd/system/getty.target.wants:
lrwxrwxrwx 1 root root 34 Jul 19 15:01 getty@tty1.service -> /lib/systemd/system/getty@.service
Fedora GNOME // Devuan CWM

User avatar
Head_on_a_Stick
Posts: 13593
Joined: 2014-06-01 17:46
Location: /dev/chair
Has thanked: 1 time
Been thanked: 28 times

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

#20 Post by Head_on_a_Stick »

Nili wrote:if you remember a thread and a chat that we have done therefore I have two because i choosed to use two tty.
From that thread:
I wrote:Disabling TTYs via /etc/logind.conf saves *no resources whatsoever*
The only TTY that is spawned at boot is TTY1, the other TTYs are spawned on demand -- ie, they do not exist until you switch to them.

Unless you want a TTY for root login there really is no harm having autologin on all TTYs; it certainly doesn't use up any extra resources.
"It seems that UNIX has become the victim of cancerous growth at the hands of organizations such as UCB. 4.2BSD is an order of magnitude larger than Version 5, but, Pike claims, not ten times better."

— Murray Hill, Bell Laboratories

Post Reply