How to Automatically Log User Into Local Console on Boot in FreeBSD
C'mon in, it's not locked!
Default FreeBSD installation will boot into command line login prompt, requiring users to log into the system before gaining access to the programs, which is usually done by typing username and password interactively. In some cases, however, we want to login certain user automatically on boot. Steps to accomplish this task are described in the following article.
Provided that user testuser already exists, we will append the following to /etc/gettytab in order to instruct system not to ask it for password:
# log in testuser automatically
testuser:\
:ht:np:sp#115200:al=testuser:
Above can be done by typing comands below as root:
echo "# log in testuser automatically" >> /etc/gettytab
echo "testuser:\" >> /etc/gettytab
echo " :ht:np:sp#115200:al=testuser:" >> /etc/gettytab
Automatic login is configured in /etc/ttys by replacing Pc with testuser on a tty of our choice. As we prefer to keep system console ttyv0 reserved for syslog notifications, we will comment out line referencing first virtual terminal and add edited one:
#ttyv1 "/usr/libexec/getty Pc" xterm onifexists secure
ttyv1 "/usr/libexec/getty testuser" xterm onifexists secure
Unless we really need commented line, we can perform in-place string replacement by typing below command as root:
sed -i '' '/ttyv1/s/Pc/testuser/g' /etc/ttys
Once we reboot, testuser will be automatically logged into system on first virtual terminal, to which one can switch by pressing Alt + F1.