How to use custom hostname in shell prompt

Typically, the Linux shell prompt looks like this

user@hostname$

If you want to use a custom string instead of hostname, edit /etc/bash.bashrc: and find the following line:

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

Now, replace \h (i.e. hostname) with your custom string. For example, if you want to use mycustomhostname instead of the actual hostname, the line should look like this:

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

This might still not override it for individual users. If that’s the case, you can edit the PS1= line in ~/.bashrc:

Typically, in ~/.bashrc, there are two different PS1= lines, one for colored output and one for non-colored output.

Replace \h in both of them.

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else 
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi 

When replaced with mycustomhostname, it should look like this:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@mycustomhostname\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else 
    PS1='${debian_chroot:+($debian_chroot)}\u@mycustomhostname:\w\$ '
fi