HOWTO: Autologin into your Linux system without XDM, GDM, KDM, etc
Purpose: Are you in a need of a Linux system which can autologin into your Desktop environment in case of a power-failure or an unexpected restart? If yes, then this post is for you! Since quite some time I have been looking for a solution like this and I think I have found one finally.
If you are looking how to autologin as “root” or as any other user in console mode only i.e. when you don’t have “X”/Graphical environment installed, you can learn it here.
So let’s get started…
My System details:
Linux OS: Debian Linux 5.0 (Lenny)
Window Manager: Fluxbox
Suppose right now this is how your system boots currently:
Current Scenario:
- Linux Boot process (Kernel and init scripts)
- XDM (or any other login manger) kicks in
- You enter username and password (PITA)
- Fluxbox (or any other Window manager or Desktop Manager – like GNOME/KDE) launches
- Any your application finally runs.
And this is what we will achieve:
Desired Scenario:
- Linux Boot process (Kernel and init scripts)
- Fluxbox (or any other Window manager or Desktop Manager – like GNOME/KDE) launches automatically
- Any your application finally runs.
Step 1: Disable or un-install any login manager
Suppose you have XDM installed. Then you definitely don’t need XDM if you are looking for autologin only because XDM does not support autologin. If you search on the Internet with terms “autologin xdm” you will see what I am saying. If you think you sometime need the regular username and password method then you can just disable it by the following commands:
# update-rc.d -f xdm remove
or else if you think you will only need autologin feature then you can un-install it also, just so that there is no conflict, by giving the following command:
# apt-get purge xdm
or
# dpkg --purge xdm
Suppose you have GDM installed. Now as you may or may not know GDM does support autologin feature. However if you are running a very lean (size wise) system for very specific purpose (like a kiosk), you don’t need all those packages that gets installed with GDM i.e. you don’t want the “glitz”. You can disable or remove GDM just like the above commands.
Step 2: Install xinit package
Install xinit package like this:
apt-get install xinit
This program provides two executables: startx and xinit. startx is front-end wrapper for xinit and their purpose is exactly the same. We will work with startx here.
Now at this stage, suppose you reboot your system you will see that you end up with a login console (tty) just like when you first install a base Debian system (without X). Now if you enter your username and password you will end up with a command prompt. And if you run:
# startx
you will see that X servers launches automatically and fluxbox kicks in. Yes, you are almost there. Now the only hurdle with this approach is that you still need to enter login information and that was the whole point why we are reading this article. So let’s get rid of it.
Step 3: Edit rc.local file
You need to add the following line in your /etc/rc.local file.
su - <username> -c startx
before the line exit 0
Save and quit the file.
That’s it. You are done. Now restart your system you will be magically taken right into your fluxbox without you doing anything. Next time when your power goes up or your computer gets restarted accidentally, rest assured your system will boot nicely the way you want it to.
Disabling autologin
What if you decide that you don’t want autologin feature and would like to go back the way your system was? No problems, just do this:
1. Remove the line
su - <username> -c startx
from rc.local file
2. Enable or Install your login manager
To enable:
#update-rc.d xdm defaults
To install:
# apt-get install xdm
3. Reboot your system.
Important Notes
Let’s understand what happened here. Basically with the above method before the tty1 login console script gets called, “startx” is called by rc.local file. So basically when you are in your desktop environment you still don’t have a tty1 login console – The one that you get on pressing Ctrl-Alt-F1. However, you can still get tty1 console if you right-click on desktop and click on “Exit” from the menu in Fluxbox. When you do this, Exit 0 line in rc.local gets executed as per the sequence and you get your tty1 login console as you use to get before. Now if you give “startx” command again, fluxbox will launch automatically.
I am sure there must be some other method by which you can achieve autologin but I have found this method to be the most simple and works effectively without whacking or breaking your system.
I hope this method was useful to you. If you have any comments/feedback or a better method to do it please let us know in the comment section.


Email Subscription









March 26th, 2009 at 7:28 pm
This is the awesome!
Thanks so much. I’ve been needing to do exactly this for a kiosk-like application, and wasn’t sure how to go about it. Thanks again for the clear explanation.
Reply to this comment
Admin Reply:
March 27th, 2009 at 10:23 am
Hi,
Thank you for your comment. I am glad that it worked for you. Are you using Debian for your kiosk application? I was wondering if this method works on other distros too (non-Debian based).
Reply to this comment
April 15th, 2009 at 9:05 pm
Awesome article… helped me out with a project I am currently working on. Great job!
Reply to this comment
Admin Reply:
April 16th, 2009 at 12:38 pm
Glad it helped you! Took me a while to figure out. Wonder what are some other methods to achieve the same.
Reply to this comment
May 14th, 2009 at 11:47 pm
Thanks, your guide pointed me in the right direction.
However it didnt work very well in Debian Sid as X loaded before the hal daemon. So i had to delete the line from rc.local and instead made a little script which now is executed when entering runlevel 5.
Works perfectly now.
Reply to this comment
Admin Reply:
May 14th, 2009 at 11:50 pm
Hi Eric,
Thanks for your comment. Looks like in Sid the sequence of HAL and X must have changed. Can you post your script and tell us how did you do it?
Reply to this comment
October 3rd, 2009 at 5:28 am
Hi!
I’ve an other method:
-Edit /etc/inittab and replace the line
“1:2345:respawn:/sbin/getty 38400 tty1″
by “1:2345:respawn:/bin/login -f user tty1 /dev/tty1 2>&1″
Now, you’re autlogged.
-Create a /home/user/.bash_profile and add the command “startx” inside of the file.
With this method, you still have the console tty.
Thank you!
Reply to this comment
February 8th, 2010 at 12:07 pm
In Ubuntu 8.04 i have to edit the file /etc/X11/Xwrapper.config and change de property “allowed_users=console” to “allowed_users=anybody” and then, all works very well.
Reply to this comment
March 25th, 2010 at 7:42 pm
Thanks, It was exactly I needed for OpenBSD.
Reply to this comment
June 20th, 2010 at 11:58 am
Hi! This procedure indeed worked, at least in Debian Squeeze. Although, I have a comment and two questions:
after making this changes, one is logged as root, because the “su” commmand is written with a “-” before the , so the interpreter ignores that ‘parameter’. If one removes the “-” then an error occurs (“The user does not have privileges to start the X server”). What changes should be made in order to be logged as a normal user?
Is is possible to have the shutdown menues in gnome when logging by this procedure (not only log-out menu which takes back to the terminal)?
Reply to this comment
August 1st, 2010 at 8:10 am
A better method for debian:
As root
1) apt-get install mingetty
2) nano /etc/inittab
make the line
“1:2345:respawn:/sbin/getty 38400 tty1″
looks like this
“1:2345:respawn:/sbin/mingetty –autologin username –noclear tty1
where username is your account (can be root too!!!)
Now you autologin in the console after reboot with the user
you have chosen. To start X automatically we need to make a script (don’t worry, it’s easy!!!)
3) nano /bin/testx.sh
make it like this:
————-Start copying here—————
#!/bin/sh
if [ -z "$(pgrep Xorg)" ]
then startx
else clear
fi
————-Stop copying here—————-
For old debians that use XFree86 make the Xorg –> XFree86
4) chmod +x /bin/testx.sh
Now that you have our script that checks if Xorg is running,
and if not, starts it, it is safe to add it to our .bashrc
file so it can be executed immediately after console login.
Remember to edit the .bashrc of the user you have previously
added to inittab and not the one you are working now :-)
Speaking for “nick” user this would be:
/home/nick/.bashrc (for the root is /root/.bashrc).
5) nano /blah/blah/.bashrc
Add this in the last line
testx.sh
Remember:
nano saves with CTRL+O —> ENTER (Oo is omicron not ZERO)
nano exits with CTRL+X
Hope this helped someone out there!!!
Reply to this comment
François Lavoie Reply:
December 5th, 2011 at 6:25 pm
This does not work at all for me.
Working as root:
1)Intalled mingetty:
root@debian:~# apt-get install mingetty
Reading package lists… Done
Building dependency tree
Reading state information… Done
mingetty is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 40 not upgraded.
2)I changed in the inittab
#1:2345:respawn:/sbin/getty 38400 tty1
1:2345:respawn:/sbin/mingetty –autologin root –noclear tty12:23:respawn:/sbin/getty 38400 tty2
The booting process goes on until I get the usual login manager. I do not get root cli mode:
root@debian:~#
Reply to this comment
François Lavoie Reply:
December 5th, 2011 at 6:26 pm
I forgot to say I am working with wheezy, xfce 4.6 desktop environment.
Reply to this comment
August 1st, 2010 at 11:05 am
I’ve seen that this nasty webpage makes the double dashes (-)
look like one, so when you do the mingetty thing, remember
that (autologin) and (noclear) needs double dashes (-) in front of them or else you may get errors that you cannot see
because you’re not logged in yet!!!
Anyway, you will be able to correct the error (if already
happened to you…) by pushing CTRL+ALT+F2, logging in as root
in the second console, and correcting the /etc/inittab
After that do a reboot to login automatically in Xorg-XFree86
Hope that helped too…
Nikos Maragos
Reply to this comment
September 15th, 2010 at 5:56 pm
Wow, I was having all sorts of issues with gdm not auto logging me in even though it was set to, and it took significantly longer to boot to my gnome desktop with gdm… now I am just launched into gnome. Awesome.
Reply to this comment
February 9th, 2011 at 8:46 pm
Thanks, man!!!!
Finally no more gdm :)
Worked on my Ubuntu MiniCD 10.10 i386
:)
Reply to this comment
February 11th, 2011 at 9:31 am
Not sure since when Fedora started to use upstart instead of old initd. But I had to look again.
upstart, as of right now (F14), uses inittab only to define a default run level. leave it as 5 (graphical)
Now configurations for init go in /etc/init/
There is a file named prefdm.conf which is in charge of runing your prefered dm (gdm,kdm,xdm…) the prefered dm is defined on a DISPLAYMANAGER variable set on /etc/sysconfig/desktop
If this variable has a known value of KDE, GNOME, XDM or WDM, predefined actions are taken, however if it is not, then it is taken to be the path to an executable.
So an easy way on fedora 14 to get this autologin would be to define this variable on /etc/sysconfig/desktop to something like /usr/bin/my_autologin.sh
and have my_autologin.sh executable and with something like this:
#!/bin/sh
su – my_user -c startx
As a result, your graphical login will respawn if you exit, and you will still have the rest of the terminals available through (Ctrl+)Alt+Fn
Just my 2 cents
Reply to this comment
March 25th, 2011 at 8:15 am
[...] accustomed to customizable session managers like kdm or something. I read this and understand Enabling autologin in Debian Linux without using GDM, XDM, KDM or other login manager | Debian Ubunt… Sorry, for not understanding the problem completely. I just did a stupid bump lol Reply [...]
April 11th, 2011 at 12:42 pm
Hey guys, this method works well and just needs the minor modification of adding an “&” sign to the end of the command, this will allow the xserver to run in the background of tty1, giving you access to all other terminals. This method has the advantage of easily being able to move the startup priority of rc.local higher in rcS.d, giving you a faster startup of the window manager while other services begin in the background.
So just “sudo – user -c startx &” instead.
Reply to this comment
Joel Reply:
April 12th, 2011 at 5:14 pm
Ok, I try that in /etc/rc.local and I change for:
sudo – me -c startx &
I get on boot screen:
“sudo unknow command”..and yes I have sudo :(
Reply to this comment
Joel Reply:
April 12th, 2011 at 5:15 pm
PS:
Are you using two minus signs after sudo?
Reply to this comment
April 11th, 2011 at 12:43 pm
Actually it would be rc2.d not rcS.d, sorry about that.
Reply to this comment
May 25th, 2011 at 12:18 pm
[...] See the following link: http://linux.koolsolutions.com/2009/…m-gdm-kdm-etc/ [...]
April 22nd, 2012 at 6:13 pm
[...] Wi?cej info tutaj [...]
May 16th, 2012 at 9:54 am
reading your tutorial above is very exciting me since this is just what i’am looking for to make my own distro. And the comment by others bellow your tutorial are very interesting too… thanks a lot… It’s really worthed for me….
Reply to this comment