Customise Your Bash Prompt

When you SSH onto your server, the command prompt you work with is the standard Ubuntu prompt. The format of this prompt is set in the .bashrc file in your home directory, but the code for customising the command prompt is not very easy to manually update or change.

There is a great site which generates customisations for your command prompt without having to learn any Bash code. Bashrcgenerator.com, let’s you drag and drop elements and then copy and paste the resulting configuration into your users .bashrc file. You can add your username, your computers hostname or even the time and date to your command prompt, and rearrange them or separate them using symbols such as @ or >.

The #/$ element switches between the dollar sign, indicating a normal user, or the hash sign when you are working as root. Double clicking on any element then allows you to change the colour of the text or its background colour.

To use the customisation, copy the PS1 code displayed in the Step 4 on the site into your .bashrc file. Comment out the existing PS1 line of code (add a # to the start of the line; do not delete this in case you need to roll back), add a new line and paste your PS1 code in (in PuTTY, do this using Shift + Prt Screen). Press Ctrl + O to save, then Ctrl + X to exit.

On my Ubuntu 18.04 server there were three separate lines starting with ‘PS1’. I found that replacing the first one worked. It may take some experimentation on your server if it is set up slightly differently.

To see the changes, reload your .bashrc file:

Your prompt should now show the changes you made.

Leave a comment