Auto login and `startx` without a display manager — jessie

Share your own howto's etc. Not for support questions!

Auto login and `startx` without a display manager — jessie

Postby Head_on_a_Stick » 2015-07-18 01:06

This Howto is aimed at users who wish to automatically login to their Debian jessie system and start the Xserver 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 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 man startx for more on this).

For automatic login, create a file at /etc/systemd/system/getty@tty1.service.d/override.conf (as root!) with the following content:
Code: Select all
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin <user name> --noclear %I $TERM

Replace <user name> with your user name.

For automatic `startx` add this snippet to the end of the file at ~/.profile (or ~/.zprofile for zsh users):
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 2017-09-19 20:31, edited 7 times in total.
"Are you quite sure that all those bells and whistles, all those wonderful facilities of your so called powerful programming languages, belong to the solution set rather than the problem set?" — Edsger W. Dijkstra
User avatar
Head_on_a_Stick
 
Posts: 6602
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby mzsade » 2015-07-18 03:59

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
mzsade
 
Posts: 91
Joined: 2011-12-08 01:25

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

Postby Head_on_a_Stick » 2015-07-18 09:14

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
"Are you quite sure that all those bells and whistles, all those wonderful facilities of your so called powerful programming languages, belong to the solution set rather than the problem set?" — Edsger W. Dijkstra
User avatar
Head_on_a_Stick
 
Posts: 6602
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby mzsade » 2015-07-18 09:30

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
mzsade
 
Posts: 91
Joined: 2011-12-08 01:25

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

Postby Head_on_a_Stick » 2015-07-18 09:37

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
"Are you quite sure that all those bells and whistles, all those wonderful facilities of your so called powerful programming languages, belong to the solution set rather than the problem set?" — Edsger W. Dijkstra
User avatar
Head_on_a_Stick
 
Posts: 6602
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby mzsade » 2015-07-18 09:53

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
mzsade
 
Posts: 91
Joined: 2011-12-08 01:25

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

Postby Head_on_a_Stick » 2015-07-18 09:56

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
"Are you quite sure that all those bells and whistles, all those wonderful facilities of your so called powerful programming languages, belong to the solution set rather than the problem set?" — Edsger W. Dijkstra
User avatar
Head_on_a_Stick
 
Posts: 6602
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby mzsade » 2015-07-18 10:24

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
mzsade
 
Posts: 91
Joined: 2011-12-08 01:25

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

Postby Head_on_a_Stick » 2015-07-18 10:24

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

Code: Select all
# systemctl set-default graphical.target
"Are you quite sure that all those bells and whistles, all those wonderful facilities of your so called powerful programming languages, belong to the solution set rather than the problem set?" — Edsger W. Dijkstra
User avatar
Head_on_a_Stick
 
Posts: 6602
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby mzsade » 2015-07-18 10:33

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

Postby mzsade » 2015-07-18 18:14

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
mzsade
 
Posts: 91
Joined: 2011-12-08 01:25

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

Postby Head_on_a_Stick » 2015-07-18 18:18

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?
"Are you quite sure that all those bells and whistles, all those wonderful facilities of your so called powerful programming languages, belong to the solution set rather than the problem set?" — Edsger W. Dijkstra
User avatar
Head_on_a_Stick
 
Posts: 6602
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby mzsade » 2015-07-18 18:27

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
mzsade
 
Posts: 91
Joined: 2011-12-08 01:25

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

Postby Head_on_a_Stick » 2015-07-18 18:45

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
"Are you quite sure that all those bells and whistles, all those wonderful facilities of your so called powerful programming languages, belong to the solution set rather than the problem set?" — Edsger W. Dijkstra
User avatar
Head_on_a_Stick
 
Posts: 6602
Joined: 2014-06-01 17:46
Location: /dev/chair

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

Postby mzsade » 2015-07-18 18:49

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
mzsade
 
Posts: 91
Joined: 2011-12-08 01:25

Next

Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable