# Passwordless console / x user logins [Working]

## gi1242

[Edit] The audio bug has been fixed, and works fine on my system.[/Edit]

[Edit2] I've fixed this post so that it works with either the bash or tcsh shell.[/Edit]

[Edit3] I replaced the original post with a much simpler, and better method to do the same. The current post reflects some suggestions from posters below. [/edit3]

If you're the only person who uses your computer, you might want to set it up to start consoles with you automatically logged in at boot up. Additionally, you might also want to start X as your user after boot. This post tells you how to do this (without having to install kdm / gdm).

Note: After using this for a long time on my home computer, I now do the same on my laptop. I figure if someone has physical access to my laptop, he'll just take it away, instead of trying to login in and hack my passwords. Any sensitive information on my laptop I keep encrypted (using encfs). All network services are appropriately firewalled and secured. However a user with *physical* access to the computer never requires a password to login at boot time, or become root via su or sudo.

Instructions to do this are below. Use it only if you know that only trusted will have physical access to the computer.

Password-less Console logins

The follwing will make the virtual consoles at boot time password-less (i.e. will be the login shell of your user, without requiring you to authenticate it):

First create the file /root/bin/autologin, and put the following in it:

```
#! /bin/bash

exec login -f <username>
```

Make it executible via chmod a+x /root/bin/autologin.

Next modify your /etc/inittab: Replace the line

```
c2:12345:respawn:/sbin/agetty 38400 tty2 linux
```

with

```
np2:12345:respawn:/sbin/agetty -l /root/bin/autologin -n 38400 tty2 linux
```

This starts up one console on vt2 where the user (specified in /root/bin/autologin) is automatically logged in. If you'd like more than one console automatically logged in, repeat the above replacement for lines c3 -- c6 as desired. (Don't forget to change 'np2' and 'tty2' to 'np3' and 'tty3' etc.).

Note Once you logout of the console, it will restart (passwordless ofcourse)! If you want a 'dead console' once you logout, then replace the respawn with once above. If you want anything fancier, you need to write a script.

Passwordless X logins (without kdm / gdm)

Display managers like gdm and kdm have a feature that enables you to log in a user automatically. However if you think gdm or kdm take up too much memory (especially if you want to use a twm / openbox / fluxbox / fvwm / lightweight session) you can avoid running a display manager as follows:

Edit /etc/conf.d/local.start and add the lines

```
# Start X as user if tty7 is free

if ! fuser /dev/tty7 >& /dev/null; then

    su - <username> -l -c 'exec startx -- vt7 >& ~/.xsession-errors' &

fi
```

Note: If you use tcsh, you should remove the -l flag.

If local is not part of your default runlevel, then add it:

```
rc-update add local default
```

Running 'su' without typing your password

Once logged in, if you want to become root without typing the password every time, you can do the following:

```
echo <username> > /etc/security/suauth.nopass
```

Then edit /etc/pam.d/su and uncomment the line

```
auth       sufficient   pam_listfile.so item=ruser sense=allow onerr=fail file=/etc/security/suauth.nopass
```

Last edited by gi1242 on Wed May 23, 2007 8:32 am; edited 6 times in total

----------

## Hauser

```
c2:12345:respawn:/usr/bin/openvt -s -e -- /bin/su - gautam
```

While this is insteresting, it seems the console will always belong to gautam, namely you can't exit and login as a different user at that console.

```
c3:45:once:/usr/bin/openvt -e -- /bin/su - gautam -c /usr/X11R6/bin/startx
```

This doesn't work here, as I always get:

```
/usr/X11R6/bin/startx: line 111: xauth: command not found

/usr/X11R6/bin/startx: line 112: xauth: command not found

/usr/X11R6/bin/startx: line 111: xauth: command not found

/usr/X11R6/bin/startx: line 112: xauth: command not found

/usr/X11R6/bin/startx: line 150: xinit: command not found

/usr/X11R6/bin/startx: line 1: xauth: command not found
```

----------

## gi1242

 *Hauser wrote:*   

> While this is insteresting, it seems the console will always belong to gautam, namely you can't exit and login as a different user at that console.

 

If you want to log in as a different user, try su - <username>. The primary purpose for this post was for people (like me) who essentially have only one user using their machine. So if you have multiple users who use your machine, you probably won't want to do this anyway ...  :Smile: 

If you *really* want to have the 'regular' login screen apear after you're done, replace the command with a script which first runs openvt -e ..., and then runs agetty after it. You can use fgconsole to get the number of the console.

 *Hauser wrote:*   

> 
> 
> ```
> c3:45:once:/usr/bin/openvt -e -- /bin/su - gautam -c /usr/X11R6/bin/startx
> ```
> ...

 

That's strange. It's been working fine for me for a *while*. It might be because the path's are not set right? Does it work if you replace the 'startx' with a shell script which starts X?

[Edit]I figured out why it doesn't work for you. My default shell is tcsh. It reads the environment files by default. Bash doesn't do it unless you pass a -l. I've edited the post above to reflect this.  :Smile: 

GI

----------

## Hauser

```
c2:12345:respawn:/usr/bin/openvt -s -e -- /bin/su - gautam
```

It seems there's some problem here, after startx, I can't play cd, dvd anymore.  If I change back to agetty and relogin, everything works fine again.  :Confused: 

----------

## gi1242

 *Hauser wrote:*   

> It seems there's some problem here, after startx, I can't play cd, dvd anymore. If I chage back to agetty and relogin, everything works fine again

 

I have the same problem. It is because of the permisions of the mixer / sound files in the /dev directory.

When you login the conventional way, devfsd has an event where it gives you all the permissions. If you don't login (i.e. use openvt), then devfsd does not automatically give you the permissions. I've been trying to figure out how to configure devfsd to give permissions on a particular event etc, but the man page confuses me! Hopefully I'll have better luck later.

If I figure it out, I'll post it. The not so nice temp workaround is to manually change the apropriate permissions  :Smile: 

If someone knows somethign, I'd be glad to hear it.

GI

----------

## gi1242

Ok. I finally figured out the cause of both reported bugs. I've edited the original post to fix them. Works fine on my system ...  :Smile: 

----------

## twiggy

Looks nice.. gonna check it out later tonight   :Smile: 

----------

## ktm

Another simple way to do this is just to add these lines...

```
/bin/su - root -l -c /usr/X11R6/bin/startx 

/sbin/poweroff 
```

... to your /etc/conf.d/local.start and then set local to start on boot:

```
rc-update add local default
```

Now you can forget everything about /etc/inittab and remove all the terminals to get some more of that  precious memory  :Twisted Evil: 

----------

## gi1242

That's a neato trick ktm. I would also add an

```
openvt -fsec 2 -- /bin/su - gautam
```

or something similar to the same file for passwordless consoles  :Wink: . And then ofcourse modify my inittiab to get rid of those CPU/memory wasting consoles ...

----------

## nanodust

1) emerge mingetty

2) edit /etc/inittab, replace normal line with 

1:2345:respawn:/sbin/mingetty --autologin root tty1

3) if you also want to startx, not simply auto-login, then edit/create

~/.bash_profile

if [ `tty` = "/dev/tty1" ]; then

startx

fi

note those are backticks around tty, not quotes.

that's it!

it's quick & dirty, but works great !!!

----------

## gi1242

 *nanodust wrote:*   

> it's quick & dirty, but works great !!!

 

I guess I haven't updated this in a while. Autologin consoles can be done using agetty itself. All you have to do is replace the login program (using -l) with a shell script that does "login -f <username>".

Starting X should probably be done using local.start too. I'll edit my original post to show this.

GI

----------

## swimmer

I'm using it the same way nanodust describes above and am very happy with it since it works without glitches and is little hassle to setup  :Wink: 

Greetz

swimmer

----------

## gi1242

The reason I ddn't use nanodust's method is because it results in tty1 "dead" (with just error messages from startx), and another  tty used by X. Plus when I tried mingetty, I got some wierd message about "ioctl() failed, job control will be disabled" every time tcsh ran. Thus the agetty solution...

I also like ktm's suggestion about using local.start for starting X.

GI

----------

## Abecedarian

You can also do it with a C program, a trick I've retained from my time on ArchLinux:

```
#include <unistd.h>

int main() {

   execlp( "login", "login", "-f", "george", 0);

}
```

Compiled it with 

```
gcc -o autologingeorge autologingeorge.c
```

and modified /etc/inittab to something like

```
c1:2345:respawn:/sbin/agetty -n -l /usr/local/sbin/autologingeorge 38400 vc/1 linux
```

Straight outta ArchWiki.

----------

## saFFyre

Hi, the local.start method is not working from me. It works if i do /etc/init.d/local start but not on boot.  Any ideas?

----------

## gi1242

 *saFFyre wrote:*   

> Hi, the local.start method is not working from me. It works if i do /etc/init.d/local start but not on boot.  Any ideas?

 

What error message do you get? Something on stdout? Or something logged into your .xsession-errors?

Btw -- you have disabled your xdm from starting right?

GI

PS: Nanodust -- Your mingetty trick works wonderfully! I realize that if I called mingetty from the shell, it always gave me the "ioctl failed" junk error. But when called by init, it works great!

----------

## ekz

This worked for me (I modified a bit   :Smile:  )

```

### Start X as user if tty7 is free ###

if ! fuser /dev/tty7 >& /dev/null; then

    su USERNAME -l -c startx -- vt7 >& '~/.xsession-errors' &

fi

```

thanks for the trick

SAludos!

----------

## OnlyTux

Thank you very much for the trick.

I have a machine with LXDE, and with this script I can login immediately without problems.

I only have a little glitch: X starts in English and not in the right tongue. However, if I close the graphic session and then start X again from the auto-logged-in user terminal, everything is in the expected language.

The LANG variable is correctly configured, and I see no differences in the output of the env command inside the English and Italian sessions user xterms.

Does anybody know where I am wrong?

Thanks in advance for any hints.

Best regards.

----------

## Satoshi

 *gi1242 wrote:*   

> 
> 
> First create the file /root/bin/autologin, and put the following in it:
> 
> ```
> ...

 

Would login -f <username> be more resource-friendly than mingetty --autologin?

----------

## Dominique_71

I want to be able to login and startx, and to be sure than all my customizations in ~/.bash_profile and ~/.bashrc are enforced. I want it to be so less intrusive than possible and I want the user login on tty2.

 *gi1242 wrote:*   

> The follwing will make the virtual consoles at boot time password-less (i.e. will be the login shell of your user, without requiring you to authenticate it):
> 
> First create the file /root/bin/autologin, and put the following in it:
> 
> ```
> ...

 

Question: Is it a way to make the same but by using only /etc/local.d/local.start instead of modifying /etc/inittab that is already managed by portage?

EDIT: Stupid question. I am reading man inittab and it look like to be the right way to go anyway.

After, for launching startx, I modified ~/.bash_profile:

```
# start X

if [[ -z $DISPLAY && ! -e /tmp/.X11-unix/X0 ]] && (( EUID )); then

exec startx

#    while true; do

#   read -p 'Veux-tu démarrer X? (o/n): '

#   case $REPLY in

#       [Oo]) exec startx ;;

#       [Nn]) break ;;

#       *) printf '%s\n' 'Stp réponds o ou n!' ;;

#   esac

#    done

fi

```

The commented out code will let you to choose if you want to run startx or login into the console.

----------

## Tin

First of all, thank you very much for that nice solution.

This part of the tutorial is not working for me.

 *gi1242 wrote:*   

> 
> 
> Edit /etc/conf.d/local.start and add the lines
> 
> ```
> ...

 

What I had to do is to create a file in /etc/local.d

which a filename finishing with .start

and the same content as yours

and its working

I choose to create file /etc/local.d/startx.start

Best regards and again thank you  :Smile: 

----------

