How To change or hide [email protected] in Bash terminal and replace it with your own

Maybe you want to hide the username, because you don’t want to show it to anyone? For example, on forums or in video tutorials? Maybe something strange or indecent is written there. Or did you need more space on the command line? Or does it distract you and you consider it unnecessary?
All these reasons are taking place. Let’s hide our username and hostname in bash commandline!

username@hostname default display
How bash prompt looks by default

Replace [email protected] with simple ‘$’

If you need it for a short time, just use the command

export PS1='$ '

You just need to restart the terminal and then the settings will return.

If you need a more detailed explanation, as well as a way to save the settings, then read below.

First you need to open the .bashrc file in home directory. Use any text editor you like.

nano ~/.bashrc

Then, scroll down, until you see these lines

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

Now, you can comment the former variable. And add a new one, your own. The text you write will be displayed in the command line instead of username. For example, let’s try to do so

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

Save space after the $ character if you want it to look good.

It will not show the current directory, if you want to add it replace replace it with

PS1='\w $ '

Where \w means current directory path.

Keep in mind when you want to return the display of [email protected] again, you can comment your variable and uncomment the old variable.

You can now restart (close and start) the terminal and immediately see the result. If for some reason you don’t want to do it, read below. It will be helpful anyway. It is about how to update the bash config settings without leaving the terminal.

In any case, the result will be

Linux commandline prompt with hidden username
username and hostname are both hidden

Two ways to update bash config settings

The next thing you need to do is update your bash configuration. You can either restart the terminal, or you can update your settings without leaving it. Type this command

source ~/.bashrc

OR with a dot

. ~/.bashrc

source and . is the same command.

How to change username and keep untouched the others settings?

If you want to keep the colors of the letters and keep the display of the current directory, then this is what you need

In this line \u means username, \h means hostname, \w means current directory path and \$ means $ at the end of prompt line

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

Just change these parts in a variable. Here is an example

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]NEW_USERNAME@NEW_HOSTNAME\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '