Sometimes when writing for my blog, I need to post some screenshots of my terminal. For the sake of security, I don't want to expose my username and hostname on the public Internet. One handy approach is to modify the environment variable PS1 to change those strings temporarily.

user1@machine1:~$ echo $PS1
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ 

Here, \u corresponds to username and \h corresponds to hostname. We only need to change them. I suggest saving the current PS1 before committing any changes.

user1@machine1:~$ OLD_PS1="$(echo $PS1)"

We use command substitution here because PS1 may contain invisible characters. Then, we change the username and hostname to the desired names.

user1@machine1:~$ PS1="\[\e]0;user2@machine2: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]user2@machine2\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "
user2@machine2:~$ 

Remember to include one whitespace at the end of the PS1. Also, remember that this change will be reset in the new terminal session.