Autologin in Linux

Autologin on boot up will be useful when you want to execute some application or program on boot up and you call some scripts or terminal commands from within that program.
This is because the commands will only be executed if you get the prompt. Also when you get tired of typing your username and password over and over again then autologin comes to rescue. Here's what you'll need to do to enable autologin on boot up feature in Linux:

    1)  Creating the autologin command.

        For this create a C file with the name autologin.c. Then type the following code into this file:

       
        #include <unistd.h>

        int main()
        {
                execlp("login", "login", "-f", "root", 0);
        }

        Save and exit. Compile this file or cross compile it for some target architecture to get a binary in the name of 'autologin'.

        This file uses the execlp() function which will execute the binary given as the argument and will replace the current process image with it. See the    

    manual entry for more information.

    2)  Editing /etc/inittab.

        Open the /etc/inittab file ( if you are doing this for some target architecture open the /etc/inittab of that device). Now make the following changes in the file:

        Change this line
        c1:12345:respawn:/sbin/getty 38400 tty1 linux
   
        to

        c1:12345:respawn:/sbin/getty -n -l /usr/sbin/autologin 38400 tty1 linux

        ( You will be having a similar line for your PC OS. For some target architecture the baud rate and the serial console name will change. But the line will already be existing in the file. You'll not need to create a new line.)

    3)  Next we un-comment the following line in the /etc/login.defs so that no password will be asked on login. ( Un-comment by removing a '#' from front.)

        NO_PASSWORD_CONSOLE tty1:tty2:tty3:tty4:tty5:tty6

No comments:

Post a Comment