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:

  1. Linux Boot process (Kernel and init scripts)
  2. XDM (or any other login manger) kicks in
  3. You enter username and password (PITA)
  4. Fluxbox (or any other Window manager or Desktop Manager – like GNOME/KDE) launches
  5. Any your application finally runs.

And this is what we will achieve:

Desired Scenario:

  1. Linux Boot process (Kernel and init scripts)
  2. Fluxbox (or any other Window manager or Desktop Manager – like GNOME/KDE) launches automatically
  3. 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.

Be Sociable, Share!