加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > 教程文章 > java开发

Linux中如何自动登录虚拟控制台

时间:2011-05-15 11:25:12  来源:  作者:

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
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
在CentOS下搭建Android 开发环境
在CentOS下搭建Androi
轻松搭建属于自己的Ubuntu发行版
轻松搭建属于自己的Ub
利用SUSE Studio 打造自己的个性化Linux发行版
利用SUSE Studio 打造
那些采用PHP技术的IT大企业
那些采用PHP技术的IT大
相关文章
    无相关信息
栏目更新
栏目热门