As brought out in How can I detect if the shell is controlled from SSH?, if either of the variables $SSH_CLIENT
or $SSH_TTY
are set, it means you are connecting through SSH.
If you are on a Debian-based system (such as Ubuntu) you can edit your .bashrc
to something like this in order to achieve the desired effect (note that the string that PS1
is set to has to be defined with double quotes, not single quotes as it is by default):
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
if [ "$color_prompt" = yes ]; then
host="@\[\033[1;34m\]\h\[\033[00m\]"
else
host="@\h"
fi
fi
if [ "$color_prompt" = yes ]; then
PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]${host}:\[\033[01;34m\]\w\[\033[00m\]\$ "
else
PS1="${debian_chroot:+($debian_chroot)}\u${host}:\w\$ "
fi
unset host
unset color_prompt force_color_prompt
Which results in the following:

Side note: These changes should be made on the .bashrc
(or .profile
, depending on the distribution) on server you are connecting to over SSH. Setting them in your own local Bash profile has no effect on what is displayed when you connect to other remote servers.