Categories: 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:~$. 

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.

 


Share
Leave a Comment

Recent Posts

How to migrate from LastPass to Bitwarden

As a LastPass user, you might have noticed the changes introduced last day. The message… Read More

2 years ago

Amazon AWS network security checklist

This post presents with a few bunches of AWS network security checklist. It is basically… Read More

3 years ago

The long curated web security checklist based on OWASP

What is this web security checklist? Here is a curated web security checklist for developers… Read More

3 years ago

Penetration Testing for dummies – Part 3: Networking basics

In the last part of the blog series we have seen the history of internet… Read More

3 years ago

Penetration Testing for dummies – Part 2: Understanding web applications

Welcome back budding pen-testers. :) In the first part of the blog series we have… Read More

3 years ago

How to enable SSH on Google Cloud Compute Engine

Last day I was riddling with Evilginx, a phishing attack tool. It needs to be… Read More

4 years ago