su
and sudo -s
are different commands with different APIs and semantic and behaviour, you shouldn't alias one to the other.
Here it seems you want a command that starts root
's login shell as root
via sudo
but only when invoked from a non-privileged shell, so I would write a script called rootshell
for instance as:
#! /bin/sh -
die() {
printf >&2 '%s\n' "$@"
exit 1
}
[ "$#" -eq 0 ] || die "Usage: $0
Starts a root shell, no argument accepted."
[ "$(id -u)" -eq 0 ] && die "You're already superuser!"
exec sudo -s
Or if you don't want to make a script, make it a shell function by wrapping that code as rootshell() (<that-code>)
to add in your shell rc file (change $0
to the name of the function as not all shells put the function name in $0
).