Exit superuser mode in terminal

I entered superuser mode in terminal using the command "sudo cd .." to add a new command to bash. When attempting to exit superuser mode, I tried typing "exit" and was given the following:


Name-MBP:/ User1$ exit

logout


Saving session...

...saving history...truncating history files...

...completed.


[Process completed]


There is a blinking cursor directly after the end bracket and I cannot use the terminal after doing this (Control + C does nothing, etc)

I have tried "q" and "quit" instead of "exit" to no avail.

I have tried quitting the terminal application but am still in superuser mode when I reopen terminal.

I have tried restarting the computer but am still in superuser mode when I reopen terminal.

I must be missing something obvious but cannot figure it out... any help is appreciated as I would like to logout for security reasons.


MacBook Pro 2019 (Intel core) running Ventura 13.4.1 if it helps

MacBook Pro 13″

Posted on Sep 4, 2023 6:35 PM

Reply
Question marked as Top-ranking reply

Posted on Sep 5, 2023 12:19 PM

You never were in superuser mode, just a temporarily elevated (sudo) privilege mode that required your admin password.


In Terminal, either typing exit or a control-D will end the current Terminal session. That is what [ Process completed] is advising, and you will need to formally quit Terminal at that point as your Terminal session is over.


Under normal circumstances, your Terminal prompt should not change by running sudo. It certainly does not here using the Zsh shell. If your shell prompt normally ends with a % and it is now #, then press command+D to exit the privileged shell back to your default shell.


You can reset the PS1 Terminal prompt by either quitting and relaunching Terminal, or by running the following command at the Terminal prompt based on the SHELL you are using:


ZSH

source ~/.zshrc


BASH (pick the one where your PS1 prompt setting resides)

source ~/.bashrc
source ~/.bash_profile
source ~/.profile

6 replies
Question marked as Top-ranking reply

Sep 5, 2023 12:19 PM in response to apple9485

You never were in superuser mode, just a temporarily elevated (sudo) privilege mode that required your admin password.


In Terminal, either typing exit or a control-D will end the current Terminal session. That is what [ Process completed] is advising, and you will need to formally quit Terminal at that point as your Terminal session is over.


Under normal circumstances, your Terminal prompt should not change by running sudo. It certainly does not here using the Zsh shell. If your shell prompt normally ends with a % and it is now #, then press command+D to exit the privileged shell back to your default shell.


You can reset the PS1 Terminal prompt by either quitting and relaunching Terminal, or by running the following command at the Terminal prompt based on the SHELL you are using:


ZSH

source ~/.zshrc


BASH (pick the one where your PS1 prompt setting resides)

source ~/.bashrc
source ~/.bash_profile
source ~/.profile

Sep 6, 2023 2:04 PM in response to apple9485

sudo cd ..


DOES NOT give you a root prompt.


All it does is start a subprocess, run the command "cd .." as root, then the subprocess terminates, because you did not start a shell, and you are back at your normal user prompt.


So when you type 'exit' you are logging out of your normal user account.


sudo will execute the specified command as root, then terminate.


If you wish to stay running as root, then you need to use a sudo command something like:


  • sudo -s
  • sudo bash -i
  • sudo zsh -i
  • sudo bash -l
  • sudo zsh -l


There are other variations on the theme, but "sudo cd .." is not one of them.

Sep 8, 2023 9:34 AM in response to apple9485

You actually terminated your current shell session. You must close that Terminal window and launch a new Terminal window. When you launch the Terminal app or a new tab/window in the Terminal app...you are put into a new shell session. With macOS when you exit the last shell session associated with a tab/window, then you get that message and the tab/window remains open. macOS does not close the Terminal tab/window once a shell session exits (at least by default settings anyway).


Also, be very careful using "sudo" since it will give you temporary root privileges which can have catastrophic consequences. Even if the command you are using when elevating your privileges is safe, you should only do so if it would otherwise fail with standard user privileges. The command line is very unforgiving and there are no safety nets when using the command line. If you issue a valid command, then that command will be carried out whether it does what you intended or not.


I suggest you review some basic command line tutorials to learn the basics....the basics can allow you to do a lot and may help to become aware of some dangers. Here is one tutorial geared for macOS. Most tutorials will be focused on Linux which is fine since the basic commands & utilities exist on both platforms, however, macOS is still using very old outdated versions of those commands & utilities due to licensing issues so some of their options will not exist on macOS. Plus those Linux based tutorials may have examples for using Linux only frameworks or commands not available with macOS.....macOS will also have their own unique commands/utilities as well. There may be other macOS centric command line tutorials out there:

https://scriptingosx.com/2017/07/first-steps-in-terminal/




This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Exit superuser mode in terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.