Operating a standard bash shell on a server, the PS1 prompt defaults to ending in a $ for non-root users, and # for root.
IE:
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ce9fee9f2e8e9dceff9eeeaf9ee">[email protected]</a>:~$ sudo su <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="275548485367544255514255">[email protected]</a>:/home/ubuntu#
Why is this?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Historically the original /bin/sh Bourne shell would use $ as the normal prompt and # for the root user prompt (and csh would use %). This made it pretty easy to tell if you were running as superuser or not.
# is also the comment character, so anyone blindly re-entering data wouldn’t run any real commands.
More modern shells (eg ksh, bash) continue this distinction of $ and # although it’s less important when you can set more complicated values such as the username, hostname, directory 🙂
Method 2
Tradition.
The POSIX standard says (my emphasis):
PS1
This variable is used for interactive prompts. Historically, the
“superuser” has had a prompt of#. Since privileges are not required
to be monolithic, it is difficult to define which privileges should
cause the alternate prompt. However, a sufficiently powerful user
should be reminded of that power by having an alternate prompt.
See also this answer to virtually the same question on the SuperUser forum.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0