On my linux server I signed in as the root user to access some files: su root... After checking the files I went to sign back in as my main user su username. In my terminal window it now says server ~: instead of username@server ~: to the left of the command line. Is there any way I can get this back to normal?
Do a few
exit commands. Your
su root started a subshell where you're root, and your
su user started another. Typing
exit will end those subshells and bring you back where you started -- one level deep.
You just need to change the prompt. You can use the following command:
export PS1="\u@\h \w: "
I personally prefer the following as my prompt, but that's just me:
export PS1="[\u@\h \w]\$ "
You can prevent your prompt from changing by adding the statement to the relevant bashrc files. See also Bash Shell PS1: 10 Examples to Make Your Linux Prompt like Angelina Jolie for more info about PS1.
su switches users by spawning a new (sub)shell. So when you logged in, you started a shell. With the first
su to root, you started a subshell as root. The next
su to your user started yet another subshell -- note that at this moment you have three shells running. So instead of
su-ing to your user from the rootshell,
exit-ing back to your login shell will solve your problems.
If you have
pstree -h will show you a graphical representation of what's going on.
Your prompt appears to be normally set by one of your shell startup files that is not being run when you
su from root to your user. If you're using bash,
man bash in the INVOCATION section might be enlightening. There are several startup files that bash might read, including but not limited to:
PS1 environment variable is just an environment variable, and may or may not get set depending on which combination of the above files is run.
su command has a
--login) switch which may be abbreviated to just
- that makes the new shell a login shell. This is probably what you want:
su - david
I always use
su with this option.
if this is a bash shell, try:
if that doesnt work run
echo $PS1 and see what has changed.
su by itself does not create a new session of the shell. that's why it doesn't set up the shell as it normally does. however,
will start a new login session