3

When I ssh as root to a remote machine, the command output looks like this:

root@Machine:/current/path#:

However, if it's a non-root user, all I see is:

$

How can I get the same behavior as for the root user? Why is it different?

1 Answer 1

3

The "command output" that you referred to is called "the prompt". At the end of the prompt usually there is a character (in bash usually # or $) to indicate the end of the prompt and the start of user input. It is different so that you know if you are the root user or not. Generally when you see a # at the end of you prompt you know that you are root and should be careful with your commands.

Controlling the prompt depends on the shell that you use. For bash you use the environment variable PS1 to do so. For example if you run:

export PS1='\u@\h \w \$ '

Your next prompt will change to something like:

phunehehe@workstation ~/Desktop $ 

Refer to the PROMPTING section in man bash for the format of the PS1 variable. A point of interest to your question:

\$     if the effective UID is 0, a #, otherwise a $

To change the prompt permanently, put the export line in /etc/profile (system-wise), or ~/.profile (user-wise), or something equivalent.

3
  • Thanks, that makes sense. However, my ssh session is still broken. When I am logged in as user, it doesn't evaluate \u@\h \w as variables. I also can't use the up or down arrows, instead I see ^[[A.
    – m33lky
    Commented Apr 16, 2011 at 19:44
  • What is your shell? Other shells may have different format to the PS1 variable. Check this question in case you don't know. About the up and down arrows, I think it has little to do with the prompt. You should ask that in another question.
    – phunehehe
    Commented Apr 17, 2011 at 2:11
  • I am asking this here.
    – m33lky
    Commented Apr 17, 2011 at 3:32

You must log in to answer this question.

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