1

This question already has an answer here:

I'm using Ubuntu Server over SSH, and I see $ instead of the name of the user (let's say test@desktop, for example).

How can I make the terminal display test@desktop instead of $?

marked as duplicate by edwinksl, Panther, heemayl, Anwar, Eric Carvalho Aug 19 '16 at 19:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • This may not be an ideal choice of things to do as the $ shows you to be in standard mode and it will change to # when you are in as root user. For my system "david@david-Gizmo2 ~ $" standard and "david-Gizmo2 david #" after sudo su (change to Root user). – monkeyman_stones Aug 19 '16 at 16:19
  • 3
    You're talking about the PS1 prompt. Refer to Where can I find a complete reference for the $PS1 variable? – wjandrea Aug 19 '16 at 16:22
  • @wjandrea I don't understand your guide :/ – antonio8909 Aug 19 '16 at 16:29
  • @Zanna - voting to close as a duplicate as the problem/solution is the same change and changing PS1 local vs on server is trivial enough that IMO this is a dup. – Panther Aug 19 '16 at 17:14
  • 1
    Sounds to me like your shell is not /bin/bash – earthmeLon Aug 19 '16 at 17:45
2

You have to define the PS1 variable on the client system and make sure the definition is sourced when you ssh.

It's possible that it is already defined in .bashrc on the remote system and so you just need to source .bashrc by starting an interactive shell (replace remote-sys with your remote system's name obviously)

ssh remote-sys -t bash -i

If that doesn't work, because .bashrc doesn't exist on the remote system, or doesn't have PS1 defined, and you want to use the same settings on the remote system as your local system, then copy over your own .bashrc:

scp ~/.bashrc remote-sys:.bashrc

Or you can make a file purely to set the prompt the way you want it on the remote system... for example

nano .set-prompt

enter the text (this sets user@host as the prompt)

export PS1="\u@\h "

or if you want it to look like the Ubuntu prompt user@host:working-directory$

export PS1="\u@h:\w$ "

or customise however you like. Save the file and exit, then scp it to the remote system

scp .set-prompt remote-sys:.set-prompt

When you ssh to the machine you will have to source the file explicitly and tell bash to make the shell interactive:

ssh remote-sys -t "bash --rcfile ~/.set-prompt -i"

If you do sudo -i to change to root on the remote system, the prompt will change again as root's .bashrc will be sourced.

  • Let me arrive home and I'll try :) – antonio8909 Aug 19 '16 at 17:20
2

If you're SSH-ing into a sh session, which I think is the case judging by what you have currently, you can add variables and commands to your PS1:

PS1='$USER@$(hostname)\$ '

If you're SSH-ing into a bash session, you have endless options, but I'd recommend to use the default if you're just getting into this. To set the PS1 in only the current session, run this:

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

To make the change permanent, open the ~/.bashrc on the remote machine and add the above line to it.

See Where can I find a complete reference for the $PS1 variable? to understand what the above line does.

P.S. I don't use SSH very much myself, so you may have to change some other settings to make this stuff work.

  • @Zanna Thanks. Could he put it in ~/.profile instead? – wjandrea Aug 19 '16 at 17:25
  • Yes, that would work :) but remember .profile is only sourced if .bash_profile and .bash_login don't exist... and this is all on the remote system, not local, of course – Zanna Aug 19 '16 at 17:36
2

PS1="/u@/h" will give you what you are asking for although I don't recommend that you do this as it will make it difficult to ascertain if you are in standard or superuser mode.

To change it back to the default for 16.04 (and earlier?) use PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$"

You can make changes permanent by editing /etc/bash.bashrc and appending your changes with your favorite editor

Sources: this page and testing.

  • 1
    Elder Geek mirrors much of what I said above. You certainly want to know at a glance if you are in as standard user or Root and both of our answers explain this. This is why I + marked Elder Geek's answer above. – monkeyman_stones Aug 19 '16 at 16:38
  • 1
    That will only change it temporarily. – Panther Aug 19 '16 at 17:15
  • 1
    you missed a " and this sets the prompt to literally test@desktop not user@host ;) – Zanna Aug 19 '16 at 18:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.