Customize the Login and Logout on FreeBSD

Last edited on 2025-05-23 Tagged under  #freebsd   #bsd   #shell 

Part of the "Exploring FreeBSD on a Laptop" series.

Tested on FreeBSD 14.2

I like to shorten the boot delay and customize the login with a different last login notification and a Daily Dose of Wisdom delivered courtesy of fortune(6) piped to cowsay(1).



Boot Delay

Open loader.conf(5) for editing:

# vi /boot/loader.conf

By default the system will pause at the boot menu for 10 seconds. I shorten this to 3 seconds by setting:

autoboot_delay="3"

Save changes and exit.

Hush

Quiet the default output after logging into the system by creating an empty .hushlogin file:

$ touch ~/.hushlogin

Last Login

View the list of all logins, reboots, and shutdowns with the last(1) command:

$ last

Display at login the who/when/duration of the last login by modifying .profile:

$ vi ~/.profile

Add:

# Last user login
last | head -10 > /tmp/recentlogins; \
sed -i.bak '/boot/d;/shutdown/d;/reboot/d;/tmux/d' /tmp/recentlogins; \
cat /tmp/recentlogins | head -2 | tail -1 | \
awk '{ ORS=""; print "Last login: " $1 " on " $2; $1=$2=""; print $0 }'; echo ""

Save changes and exit.

Source: .profile

Daily Dose of Wisdom

Command fortune prints an adage chosen at random from database files stored in /usr/share/games/fortune.

By default on FreeBSD there is a single textfile freebsd-tips and its companion freebsd-tips.dat file:

$ fortune freebsd-tips
To erase a line you've written at the command prompt, use "Ctrl-U".
		-- Dru <genesis@istar.ca>

Install:

# pkg install cowsay

Run:

$ fortune freebsd-tips | cowsay
 ________________________________________ 
/ To see the output from when your       \
| computer started, run dmesg(8). If it  |
| has been replaced with other messages, |
| look at /var/run/dmesg.boot.           |
|                                        |
\ -- Francisco Reyes <lists@natserv.com> /
 ---------------------------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Nice!

Now to make my own fortune(s)!

I create a file containing bits of wisdom I collect from all over:

$ vi dailyDoseOfWisdom

Add blocks of text separated by the % percent sign. Sample:

Barn's burnt down / now I can see the moon.
-- Mizuta Masahide
%
To belittle, you have to be little.
-- Kahill Gibran, The Prophet
%
If you don’t get everything you want, think of the things you don’t get
that you don’t want.
-- Oscar Wilde
%

Save changes and exit.

Convert this file to a format that fortune can use with the strfile(8) command, which generates the necessary *.dat file type:

$ strfile -c % dailyDoseOfWisdom dailyDoseOfWisdom.dat

Copy both files to the fortune data location:

# cp dailyDoseOfWisdom* /usr/share/games/fortune/

Get your wisdom straight from the cow:

$ fortune dailyDoseOfWisdom | cowsay
 _______________________________________ 
/ Barn's burnt down / now I can see the \
\ moon. -- Mizuta Masahide              /
 --------------------------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

To display at login my cow-ified fortunes, modify .profile:

$ vi ~/.profile

Comment out the current fortune entry if present:

# Display a random cookie on each login.
#if [ -x /usr/bin/fortune ] ; then /usr/bin/fortune freebsd-tips ; fi

Add:

# Daily dose of wisdom.
myfortune="/usr/share/games/fortune/dailyDoseOfWisdom"
if command -v fortune 2>&1 >/dev/null
then
  if command -v cowsay 2>&1 >/dev/null && [ -f "$myfortune" ]
  then
    fortune $myfortune | cowsay
  else
    fortune freebsd-tips
  fi
fi

Save changes and exit.

Clear Terminal at Logout

Here is a method that works in all modern shells (I'm using ksh).

Add to ~/.profile:

test -f $HOME/.exitrc && trap ". $HOME/.exitrc" EXIT

Create ~/.exitrc with:

echo "type clear >/dev/null 2>&1 && clear" > ~/.exitrc

See: https://unix.stackexchange.com/a/12013

You can like, share, or comment on this post on the Fediverse 💬

Thanks for reading! Read other posts?

» Next: Configure SSH on FreeBSD for Passwordless Logins to Servers

« Previous: Customize the Login on NetBSD