Customize the Login on NetBSD

Last edited on 2026-09-03 Tagged under  #netbsd   #bsd 

After entering a username and password, the NetBSD default login generates multiple lines of output, some of it more useful (Last login) than others (copyright dates).

To quiet this output, I create an empty hushlogin file in HOME:

touch ~/.hushlogin

However, this removes the Last login output, which I do want to display. I re-create the information using last(1) in a custom script.

Create the bin directory in HOME:

mkdir ~/bin

Create mylastlogin:

vi ~/bin/mylastlogin

…with:

#!/bin/sh
#
# Show last login information if available
if command -v last >/dev/null 2>&1; then
    last | grep $USER > /tmp/logins
    sed -i.bak '/boot/d;/shutdown/d;/reboot/d;/tmux/d' /tmp/logins
    head -2 /tmp/logins | tail -1 | tr -s ' ' > /tmp/last
    logdate="$( cat /tmp/last | cut -d ' ' -f 3- )"
    logtty="$( cat /tmp/last | cut -d ' ' -f 2 )"
    echo "Last login: $logdate on $logtty"
fi

Save changes and exit.

Make the script executable:

chmod 700 ~/bin/mylastlogin

Modify .profile:

vi ~/.profile

Add:

# Show last login information if available
if command -v mylastlogin >/dev/null 2>&1; then
    mylastlogin
fi

Save changes and exit.

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

Thanks for reading! Read other posts?

« Previous: Configure SSH for Passwordless Logins to NetBSD Servers