I checked a lot of information on the Internet to implement the Linux Automatic Login method a few days ago and found many methods. However, some methods on the Internet are not very clear or outdated. Therefore, I specially sorted out the setting methods for Linux automatic login.
The testing environment in this article is centos 5.5.
1. Set
Using the gnome Display Manager, you can set its configuration file/etc/TPD/custom. conf to enable automatic account logon.
The setting method is as follows:
Add the following content to the/etc/TPD/custom. conf file:
[Daemon]
Automaticlogin = Username
Automaticloginenable = true
Here, username is the user name for automatic login.
Note: username cannot be root, which means Automatic Root Login cannot be implemented.
2. Set preofdm
In the last line of the/etc/inittab file, this line of command is used to start X Windows, and/etc/X11/preofdm is the specific script to start X Windows.
Add the command to start X Windows in/etc/X11/preofdm and exit.
/Usr/bin/startx
Exit 1
Note:
(1) The two lines of code must be
[-N "$ preferred"] & exec $ preferred "$ @">/dev/null 2> & 1 </dev/null
Before the code.
(2) This method automatically logs in as root because it is root when running to/etc/X11/preofdm.
3. Start X Windows in RC. Local
Add the command to start X Windows in/etc/rc. Local.
/Usr/bin/startx
Note: This method is automatically logged on as root because it is root when running to/etc/rc. Local.
4. Change the mingetty and login source code.
This method is only valid for the text mode. Therefore, you must set/etc/initab:
ID: 3: initdefault:
/Sbin/mingetty is used to obtain the login user name and call/bin/login as the parameter.
One function of/bin/login is to obtain the password entered by the user.
(1) view the software packages of/sbin/mingetty
[Root @ localhost ~] $ Rpm-qf/sbin/mingetty
Mingetty-1.07-5.2.2
(2) download the mingetty source code.
Mingetty-1.07-5.2.2.src.rpm
(3) decompress the source code package
[Root @ localhost desktop] # rpm-IVH mingetty-1.07-5.2.2.src.rpm
The Directory of the decompressed source code package is/usr/src/RedHat/sources/
View files
[Root @ localhost ~] # Ls/usr/src/RedHat/sources/mingetty *
/Usr/src/RedHat/sources/mingetty-1.00-opt.patch
/Usr/src/RedHat/sources/mingetty-1.07.tar.gz
Decompress the source code package
[Root @ localhost ~] # Tar zxvf/usr/srsrc/RedHat/sources/mingetty-1.07.tar.gz
Mingetty-1.07/
Mingetty-1.07/mingetty.8.
Mingetty-1.07/copying
Mingetty-1.07/makefile
Mingetty-1.07/mingetty-0.9.4-autologin.patch
Mingetty-1.07/mingetty. c
(4) modify the code in mingetty. C.
To change the mingetty code, two steps are required.
Char * LOGNAME, * s;
Changed to char * LOGNAME = "root", * s;
Comment out line
/* If (autologin ){
Do_prompt (0 );
Printf ("login: % s (automatic login) \ n", autologin );
LOGNAME = autologin;
} Else
While (LOGNAME = get_logname () = 0)
/* Do nothing *//*;*/
(5) compile and generate mingetty
[Root @ localhost ~] # Cd/usr/src/RedHat/sources/mingetty-1.07/
[Root @ localhost mingetty-1.07] # Make
(6) Update mingetty
[Root @ localhost mingetty-1.07] # cp mingetty/sbin/mingetty
The mingetty source code is changed.
(1) view the packages to which/bin/login belongs
[Root @ localhost ~] # Rpm-qf/bin/login
Util-linux-2.13-0.47.el5
(2) download the source code of login.
Util-linux-2.13-0.47.e15.src.rpm
(3) decompress the source code package
[Root @ localhost desktop] # rpm-IVH util-linux-2.13-0.47.e15.src.rp
The Directory of the decompressed source code package is/usr/src/RedHat/sources/
View the extracted files:
[Root @ localhost ~] # Ls/usr/src/RedHat/sources/util-linux-2.13 * tar *
Util-linux-2.13-pre7.tar.bz2
Continue to decompress the file
[Root @ localhost ~] # Tar xf/usr/src/RedHat/sources/util-linux-2.13-pre7.tar.bz2
The decompressed folder is a util-linux-2.13-pre7.
The login source code directory is/usr/src/RedHat/sources/util-linux-2.13-pre7/login-utils
The make file does not exist in the login-utils file. Therefore, you need to compile the command to generate login.
(4) modify the code in login. C.
Set passwd_req = 1 In the first row;
Change to passwd_req = 0;
Add the locale. h header file to the file.
# Include <locale. h>
(5) compile and generate Login
[Root @ localhost login-utils] # gcc-O login Login. C ../lib/setproctitle. c checktty. C-wall-lcrypt-I ../include/
(6) Update login
[Root @ localhost login-utils] # cp login/bin/login
Restart to log on with the root account in text mode.
References
1. http://www.ibm.com/developerworks/cn/linux/l-tip-prompt/tip20/
2. http://www.ibm.com/developerworks/cn/linux/l-tip-prompt/tip20/index2.html