0

What's the distincton between:

sudo su -

and

su -i

and where would one be preferred over the other?

   -, -l, --login
          Start the shell as a login shell with an environment similar to a real login:

             o      clears all the environment variables except TERM and variables specified by --whitelist-environment

             o      initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH

             o      changes to the target user's home directory

             o      sets argv[0] of the shell to '-' in order to make the shell a login shell

and

   su - run a command with substitute user and group ID

excerpts from the man su page.

0

1 Answer 1

2

There is no -i argument to the su command, so the difference would be that one works and the other doesn't.

If you meant su -l, it still doesn't work by default on an Ubuntu box since the root account is locked and there's no password to enter.

There's no difference between the - and -l arguments. They're both variations on the same option. You actually included the line from the man page that tells us that in your question.

The difference between using the -, -l, or --login argument (they're all the same) and using no argument are mostly explained in the excerpt you included in your post. This part tells what it does without the argument:

For  backward compatibility, su defaults to not change the current directory and to only set the environment variables HOME and SHELL (plus USER and LOG‐
NAME if the target user is not root).  It is recommended to always use the --login option (instead of its shortcut -) to avoid  side  effects  caused  by
mixing environments.

Note that su isn't just for root. It doesn't stand for super user as it does with the sudo comment. It stands for substitute user and you can specify the user you want to use as an argument to run a command as that user

Not the answer you're looking for? Browse other questions tagged or ask your own question.