Linux系統字符終端自動登錄問題

Linux系統字符終端自動登錄的一解決辦法:

Linux中如何自動登錄虛擬控制檯

This article describes how to automatically login to a virtual console at the end of the boot process. This article only covers console logins; methods for starting an X server are described in Start X at Boot.

Using mingetty

This is the preferred (i.e. clean) method.

Install the mingetty package from the AUR. mingetty is designed to be a minimal getty and allows automatic logins. Then, in /etc/inittab change:

c1:2345:respawn:/sbin/agetty -8 38400 tty1 linux
c2:2345:respawn:/sbin/agetty -8 38400 tty2 linux
c3:2345:respawn:/sbin/agetty -8 38400 tty3 linux
c4:2345:respawn:/sbin/agetty -8 38400 tty4 linux
c5:2345:respawn:/sbin/agetty -8 38400 tty5 linux
c6:2345:respawn:/sbin/agetty -8 38400 tty6 linux

to

c1:2345:respawn:/sbin/mingetty --autologin USERNAME tty1 linux
c2:2345:respawn:/sbin/agetty -8 38400 tty2 linux
c3:2345:respawn:/sbin/agetty -8 38400 tty3 linux
c4:2345:respawn:/sbin/agetty -8 38400 tty4 linux
c5:2345:respawn:/sbin/agetty -8 38400 tty5 linux
c6:2345:respawn:/sbin/agetty -8 38400 tty6 linux

The user can change every line to use mingetty if preferred, but it is not necessary.

Using a C login program

As an alternative, a C login program can be written:

File: autologin.c
#include <unistd.h>

int main() {
   execlp( "login", "login", "-f", "USERNAME",  NULL);
}

Here, the C function execlp executes the command login -f USERNAME.

The program must be compiled and copied to an appropriate location:

# gcc -o autologin autologin.c
# cp autologin /usr/local/sbin/

Finally, edit etc/inittab and change:

c1:2345:respawn:/sbin/agetty -8 38400 tty1 linux
c2:2345:respawn:/sbin/agetty -8 38400 tty2 linux
c3:2345:respawn:/sbin/agetty -8 38400 tty3 linux
c4:2345:respawn:/sbin/agetty -8 38400 tty4 linux
c5:2345:respawn:/sbin/agetty -8 38400 tty5 linux
c6:2345:respawn:/sbin/agetty -8 38400 tty6 linux

to:

c1:2345:respawn:/sbin/agetty -n -l /usr/local/sbin/autologin 38400 tty1 linux
c2:2345:respawn:/sbin/agetty -8 38400 tty2 linux
c3:2345:respawn:/sbin/agetty -8 38400 tty3 linux
c4:2345:respawn:/sbin/agetty -8 38400 tty4 linux
c5:2345:respawn:/sbin/agetty -8 38400 tty5 linux
c6:2345:respawn:/sbin/agetty -8 38400 tty6 linux

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章