72

I use sudo su command to do something in Mac OS X but don't know how to switch back.

Hope you guy can do me a favour.

2
  • 1
    By the way, a more straightforward way to get a root shell with sudo is sudo -s.
    – Spiff
    Mar 23, 2012 at 9:45
  • 3
    how is -s more straightforward than su ? does it behave any differently?
    – Damon
    Feb 24, 2014 at 3:03

5 Answers 5

97

Type exit. This will logout the super user and go back to your account.

1
  • This also works to get out of sudo -i Sep 22, 2016 at 19:15
22

If you run sudo su, that will open a shell as the superuser. Type exit or Ctrl-D to exit this shell.

Normally, you don't run sudo su, but you just run sudo command. Once you type your password, sudo will record a timestamp and let you run more commands under sudo without having to type your password for a few minutes. If you want to clear that timestamp (so that someone else can't run sudo without a password), you can run sudo -k.

1

su is used to login into the root account, to logout from this , use Ctrl+D or type exit. Playing with su is very dangerous if not really necessary. The better idea is to add the used into sudo group and use the sudo command. And how come you use sudo su??

0

Just type exit, and to verify that you're back to "you" type "whoami" and it should NOT say root.

0

I entered sudo su and my password and the cursor changed from my user name to sh-3.2# typing the command whoami indicates "root". Exiting and entering sudo -s adds the designator root# to the cursor and entering whoami indicates "root". From this I conclude that the two commands are equivalent. The exit command reverts to the standard user account in either case.

6
  • This just duplicates the previous answers.
    – fixer1234
    Jun 4, 2016 at 23:16
  • This duplicates another answer and adds no new content. Please don't post an answer unless you actually have something new to contribute.
    – DavidPostill
    Jun 4, 2016 at 23:22
  • Sorry for offending you folks. Just trying to clarify. So have fun all you critics.
    – user601576
    Jun 5, 2016 at 1:49
  • I will be deleting this fine information an dropping my participation in your limited blog website.
    – user601576
    Jun 5, 2016 at 1:50
  • Hope you critics are happy. Good bye!
    – user601576
    Jun 5, 2016 at 1:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .