When you provide a double-hyphen the experience you will have is identical to if you had just executed sudo su
without any hyphen.
Passing a single hyphen is identical to passing -l
or --login
. The man page for su
describes the behavior as:
Provide an environment similar to what the user would expect had the user logged in directly.
This includes setting your directory to your home directory and setting a bunch of other environment variables.
Passing a double-hyphen to a command is typically used to mark the end of command-line flags and the beginning of non-flag arguments. For example, if you run touch -R
you'll receive an error saying that -R is not an option to touch
, but if you run touch -- -R
it will create a file named -R
. This is true of many command-line tools (ls -R
will do a recursive ls
whereas ls -- -R
will perform an ls
on a file or directory named -R
.
So, to wrap this up, when you pass only --
to su
it is basically ignoring the --
and acting like you did not pass any option at all.
sudo su -
andsudo su -l
differs. On an account where I ssh into with a key only, and I have sudo rights to change to a specific other user,sudo su -
changes the user without problems butsudo su -l
orsudo su --login
will ask for a sudo password, which I don't have (although by examiningsudo -l
I could execute/bin/su
with NOPASSWD) – karatedog Jun 14 '16 at 12:49su
man page. – Erick G. Hagstrom Oct 18 '21 at 19:12