Automated login, X and xdm

Polytropon freebsd at
Fri Oct 9 22:57:18 UTC 2009

Dear list,

in order to do something that I haven't done for many years,
I'd like to have some suggestions or pointers if I do it
right. It's a strange, but still typical idea. :-)

Here's the problem:

A FreeBSD workstation should run X for a specified user
after system startup. If the user logs out, he should not
drop to CLI mode; instead, an xdm login should be shown
to allow him (or someone else) to log in and use X.

In the past, I created the auto-login as follows:

First, I create an entry in /etc/gettytab, right after
the "default:" entry; it contains the al= definition for
auto-login as explained in "man 5 gettytab". The name of
the user is USER in this example; in fact, is is a valid
username on the system:


Then I change the getty argument from "Pc" to "autologin"
in /etc/ttys:

	ttyv0 "/usr/libexec/getty autologin" cons25l1 on secure

This automatically logs in the user USER specified as above.
In order to start X when he logs in, I put the following lines
in his ~/.login:

	mesg y
	[ ! -f /tmp/.X0-lock ] && startx

The user's shell is the C-Shell, so it works.

I see the upcoming problem: If a user already started X,
then xdm cannot start (as usually done by setting "on" for
xdm in /etc/ttys). My idea would be to do something like
this into the user's ~/.login file:

	mesg y
	# very first start of X at (automatic) login
	# this line will fail if X is already running, but
	# start it if not
	[ ! -f /tmp/.X0-lock ] && startx
	# after leaving X, xdm should be started, but not if
	# it's already running
	[ ! -f /tmp/.X0-lock ] && sudo xdm
	# after xdm is started, dialog mode is back, so the
	# last entry quits any session after exiting from X

Normally, there would be the following setting to only run
xdm, without autologin, in /etc/ttys:

	ttyv8 "/usr/local/bin/xdm -nodaemon" xterm on secure

But this interferes with the autologin, right?

What is the usual way to go? Is there something more elegant?

How about "exec startx"?

Thanks for your ideas and time!

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list