自动登录linux(不使用登录管理器)

设置X的鼠标主题
配置samba的访问密码和用户名

自动登录linux(不使用登录管理器)

獨立的圓 posted @ 2008年7月05日 01:03 in Linux with tags linux , 5822 阅读

 本站文章已轉移,敬請移步:http://www.xxb.me/ ,謝謝!

本文是指自动登录X

方法一

编辑/etc/inittab,确保启动级别为5,即:

id:5:initdefault:

并且在最后面添加一行:

x:5:once:/bin/su username -l -c "/bin/bash --login -c startx >/dev/null 2>/dev/null"

(注:要把原来类似的那行注释掉,username替换为要自动登录的用户名)

另外要取消GDM之类的登录管理器自动运行,最后重启即可。

方法二

源代码:

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

保存为autologin.c,其中your_user_here替换为要自动登录的用户名,然后编译并安装之:

$ gcc autologin.c -oautologin
$ sudo cp autologin /usr/sbin/autologin

配置 /etc/inittab

确保启动级别为3

然后修改

c1:2345:respawn:/sbin/agetty -8 38400 vc/1 linux

c1:2345:respawn:/sbin/agetty -n -l /usr/sbin/autologin 38400 vc/1 linux

配置 ~/.bash_profile

添加:

if [ -z "$DISPLAY" ] && [ $ (tty ) == /dev/vc/ 1 ]; then
    startx
fi

最后重启即可。

无论哪种方法,注销后都会回到文本界面,运行startx即可启动X并自动登录,请在~/.xinitrc里指定使用的桌面管理器。

附我的~/.xinitrc:

#!/bin/sh

#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)
#

source ~/.xprofile

DEFAULTSESSION=startlxde
case "$1" in
        "LXDE" )
                exec startlxde
            ;;
        "GNOME" )
                exec gnome-session
                ;;
        "KDE" )
                exec startkde
                ;;
        "XFCE4" )
                exec startxfce4
                ;;
        "ICEWM" )
                exec icewm-session
                ;;
        "FLUXBOX" )
                exec startfluxbox
                ;;
        * )
                exec $DEFAULTSESSION
                ;;
esac

方法二参考:HOWTO: Autologin and Autostart XFCE (just pushing power button)

  • 版权所有,转载请遵循“署名-非商业用途-保持一致”创作共用协议。 

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

HOWTO: Autologin and Autostart XFCE without login managers


Lightbulb  HOWTO: Autologin and Autostart XFCE without login managers

Are you tired off typing logins? Don't want to load heavy/waste of time login managers?

This guide let's you have autologin and autostart for your XFCE:   

Let's open a console and then create the file  autologin.c

Code:
sudo nano autologin.c
and paste this code inside (middle mouse button will paste the text you underline):

Code:
int main() {
     execlp( "login", "login", "-f", "your_user_here", 0);
 }
replace the string: your_user_here with the user you want to autologin. (ctrl+X to save) btw, use your prefered editor.

Let's compile.. you will need to have gcc installed:

Code:
sudo gcc -o autologin autologin.c
copy the compiled autologin file into /usr/local/sbin

Code:
sudo cp autologin /usr/local/sbin
now we need to edit the file /etc/inittab

Code:
sudo nano /etc/inittab
search for this:

Code:
1:2345:respawn:/sbin/getty 38400 tty1
put a # to comment this line and add this new line:

Code:
1:2345:respawn:/sbin/getty -n -l /usr/local/sbin/autologin 38400 tty1
it will look like this:
Code:
#1:2345:respawn:/sbin/getty 38400 tty1
1:2345:respawn:/sbin/getty -n -l /usr/local/sbin/autologin 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
this will make the autologin stuff...



let's make the autostart:

Code:
nano .bash_profile
put this code on the bottom and save it

Code:
if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty1 ]; then
    startxfce4
fi

then you just have to remove your login manager :
Code:
sudo apt-get remove gdm xdm kdm
reboot your machine 

I used this page as guide:

http://www.dicas-l.unicamp.br/dicas-l/20030129.shtml

Last edited by peekpt; May 2nd, 2005 at 05:18 PM..
peekpt is offline   Reply With Quote
Old May 5th, 2005   #2
abowman
Just Give Me the Beans!
 
Join Date: May 2005
Beans: 68
Ubuntu 6.10 Edgy
Re: HOWTO: Autologin and Autostart XFCE (just pushing power button)

All I did was install Xfce with synaptic and then opened up the Login Screen Setup which can be found under Settings and clicked on Auto Login and selected a user.
abowman is offline   Reply With Quote
Old May 6th, 2005   #3
anggarda
First Cup of Ubuntu
 
Join Date: May 2005
Beans: 2
Re: HOWTO: Autologin and Autostart XFCE (just pushing power button)

abowman, I think you missread the title of his thread. 

His howto is the *efficient way of loading xfce on a light system. 

The various, login managers, utilise memory in the background. 

Salut.
anggarda is offline   Reply With Quote
Old May 6th, 2005   #4
telmo
Ubuntu Extra Shot
 
Join Date: Dec 2004
Location: Braga-Portugal
Beans: 334
Re: HOWTO: Autologin and Autostart XFCE (just pushing power button)

I'll try it... But if i screw my Ubuntu... I'LL KICK YOUR ***!!! (gently!) 
Just kidding!
__________________
Linux user #383892

(\ /)
(O.o)
(> <)

This is Bunny. Copy Bunny into your signature to help him on his way to world domination.
telmo is offline   Reply With Quote
Old May 6th, 2005   #5
peekpt
First Cup of Ubuntu
 
Join Date: Apr 2005
Beans: 4
Re: HOWTO: Autologin and Autostart XFCE (just pushing power button)

Quote:
Originally Posted by  telmo
I'll try it... But if i screw my Ubuntu... I'LL KICK YOUR ***!!! (gently!) 
Just kidding!
 I just did this because it's no need to load gdm (lloading extra libs) when you are the only user on the system... I have the autologin running on my laptop with a customized kernel. It boots fast and with the autologin faster.
xfce rox... 
peekpt is offline   Reply With Quote
Old May 30th, 2005   #6
wirjo
5 Cups of Ubuntu
 
 
Join Date: May 2005
Beans: 20
Ubuntu Breezy 5.10
Send a message via MSN to wirjo
Re: HOWTO: Autologin and Autostart XFCE (just pushing power button)

Quote:
Originally Posted by  peekpt
 I just did this because it's no need to load gdm (lloading extra libs) when you are the only user on the system... I have the autologin running on my laptop with a customized kernel. It boots fast and with the autologin faster.
xfce rox... 
How do you bring back the login manager that you deleted?
wirjo is offline   Reply With Quote
Old March 16th, 2006   #7
ChrisNiemy
Just Give Me the Beans!
 
 
Join Date: Mar 2006
Location: Germany
Beans: 59
Ubuntu 10.10 Maverick Meerkat
Send a message via ICQ to ChrisNiemy
Re: HOWTO: Autologin and Autostart XFCE (just pushing power button)

Works even better when you uses "startx" instead of "startxfce4" in the ~/.bash_profile 

Otherwise I got problems with font savings etc. 

Looks like this (compared with first post here):
Code:
if [ -z "$DISPLAY" ] && [ $(tty) == /dev/tty1 ]; then
    startx
fi
Thanks so much for this! Just great! Couldn`t think of this would work. So cool 
ChrisNiemy is offline   Reply With Quote
Old March 19th, 2006   #8
conor
Just Give Me the Beans!
 
Join Date: Aug 2005
Location: ON, Canada
Beans: 46
Ubuntu UNR
Re: HOWTO: Autologin and Autostart XFCE (just pushing power button)

This is a great idea! I have a few problems though. When I turn on the computer the autologin works and then xfce4 will begin to load. After a few milliseconds though it boots me out to the command line again and I have to type "sudo startx". Then everything runs as root. What did I do wrong?

Nevermind, I was wrong. It works now.

Last edited by conor; March 21st, 2006 at 05:54 PM..
conor is offline   Reply With Quote
Old March 29th, 2006   #9
Haegin
Quad Shot of Ubuntu
 
 
Join Date: May 2005
Location: Marlborough, UK
Beans: 483
Ubuntu Karmic Koala (testing)
Send a message via MSN to Haegin 
Re: HOWTO: Autologin and Autostart XFCE (just pushing power button)

If you are using a newer version of ubuntu you will need to
Code:
sudo apt-get install gcc-3.4
then replace
Code:
sudo gcc -o autologin autologin.c
with
Code:
sudo gcc-3.4 -o autologin autologin.c
so it compiles correctly
__________________
Regards,
Haegin
If all else fails curl up in bed with a good book.
" rob: every time you don’t read the topic, god kills a lolcat"
Haegin is offline   Reply With Quote
Old May 3rd, 2006   #10
peschkaj
5 Cups of Ubuntu
 
Join Date: Mar 2006
Beans: 18
Re: HOWTO: Autologin and Autostart XFCE without login managers

Wouldn't it also be possible to use something like sysv-rc-conf to remove gdm from the boot order and still use the method you described?

你可能感兴趣的:(Linux)