TECHNOPHILE

How to hide $username @ hostname in ubuntu linux terminal

Basic Linux commandline structure

Basically it follows the format username @ hostname:working_directory ~:$ by default. Eg: something like: user@Ubuntu-pc:~/Desktop:~$. hostname

But sometimes you might want to hide these information, because of privacy reasons. You can actually do that. These values are controlled by the bashrc file in Linux.

What are prompt variables?

Prompt variable control and configure the command-line structure. There are many prompt variables in bashrc. We can add our own custom variable if necessary. We will only concentrate on the PS1 variable for this article.

Open a terminal and type the following:

echo $PS1

\u indicates the username

@ indicates the @ sign

\h indicates the hostname (computer name)

: indicates the :character

\w indicates the working directory

\$ indicates a $ if you’re a normal user account or # if you’re root.

So, putting that all together, you get username@hostname:working_directory$.

 

In order to hide this and show something like ~:$ alone, then you can refer the steps below.

Run the commands:

  1. $ gedit ~/.bashrc
  2. Find the line similar to, PS1=’${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ‘ and PS1=’${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ‘
    # uncomment for a colored prompt, if the terminal has the capability; turned
    # off by default to not distract the user: the focus in a terminal window
    # should be on the output of commands, not on the prompt
    #force_color_prompt=yes
    
    if [ -n "$force_color_prompt" ]; then
     if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
     # We have color support; assume it's compliant with Ecma-48
     # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
     # a case would tend to support setf rather than setaf.)
     color_prompt=yes
     else
     color_prompt=
     fi
    fi
    
    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
    unset color_prompt force_color_prompt
  3. Replace the values of PS1 with PS1=’$’
  4. Leave the text editor for now— save and exit gedit.
  5. Now to appear the changes we have made on terminal, either restart the terminal or type:
    $source ~/.bashrc

If you need video assistance please watch the video below.

 

Leave a Reply

Your email address will not be published. Required fields are marked *