A bit of Unix history on ‘su -‘
July 17, 2023
These days, modern versions of su
interpret ‘su -‘ as ‘su -l’ (via). Although they have different
implementations of su
, this is true on Linux, FreeBSD, and OpenBSD. However, it turns out that this
feature wasn’t always in Unix’s su.
The V7 su(1)
is quite minimal, and has no equivalent of ‘-‘ or ‘-l’. In fact,
V7 su takes no options at all; it treats its first argument as the
username to su to and ignores all other arguments to just run the
shell (passing it the nominal program name of ‘su’, cf). Su
became rather more complex in System III, where it gained
both ‘su -‘ and the ability to use additional arguments, which were
passed to /bin/sh as command line arguments (su also got other
changes, such as logging). Based on reading the System III code
for su.c, I
believe that you could use both ‘su -‘ and ‘su login args’ together,
with the meaning that ‘su – login args’ would reset $HOME, chdir
to the target login’s home directory, setuid to them, and then run
‘/bi