In this short tutorial I am going to show you how to change your bash prompt when you login through SSH permanently.
Every user with their own directory should have their own /$HOME/.bashrc file and that is where the prompt configuration is stored. To change the bash prompt you need to edit the ~/.bashrc file for each user manually. E.g The root bash prompt is stored in /root/.bashrc
If you only customized the bash prompt and want the same format you can always copy the bash prompt from a user with the same profile to another user.
You can check out my youtube video on that.
- Let me show you how you can customized the Bash Prompt for the user demo
Edit the ~/.bashrc (/home/demo/.bashrc), you can use any editor to do it. In this example I am using nano. Locate the prompt section. Make the necessary changes and save the changes.
Here is an example of changing the color and adding new line to the prompt.
PS1=’${debian_chroot:+($debian_chroot)}\n[\033[01;31m]\u[\033[00m]@[\033[01;32m]\h[\033[00m]:[\033[01;34m]\w[\033[00m]\n\n\$ ‘
Once you completed the change you can issue the command source </user folder/.bashrc> file.
Some of the common options that are available for customizing bash prompt.
Options | Desciptions |
\u | Display the current user. When you issue the whoami command the user is what will be displayed if you use this option. echo $USER will show you the current user as well. |
\h | Display the hostname. echo $HOSTNAME will show you the current server hostname up to the first . DOT if you have specified a FQDN for your hostname |
\H | The whole hostname e.g dracocyberlinux.com including .DOT if you have setup a FQDN as your hostname |
\w | The current working directory |
\W | The basename of $PWD |
\$ | If you are not root user you will get the $ inserted to the end of the prompt. If you are root user you will get # |
\n | Add A new line |
\d | The date, in “Week Month Day” |
\s | The name of shell e.g bash |
\j | Number of Jobs currently managed by the shell |
\t | The time, in 24 hour format |
\T | The time, in 12 hour format |
\@ | The time, in am/pm format |
\v | version of Bash |
\V | The release of Bash, version, patch level |
\[ | Begin a sequence of non-printing characters. This allows bash to calculate word wrapping correctly. Commonly use in color escape sequences. E.g \[033\[01;32m\] = Bold Green. |
\] | End a sequence of non-printing characters. |
Now let’s look at the basic Foreground color options. You can replace \e with \033 if you are using the escape sequence.
The \[\033[00m\] options ends the color for the range.
Options | Descriptions |
\e[0;30m | Dark Gray |
\e[1;30m | Bold Dark Gray |
\e[0;31m | Red |
\e[1;31m | Bold Red |
\e[0;32m | Green |
\e[1;32m | Bold Green |
\e[0;33m | Yellow |
\e[1;33m | Bold Yellow |
\e[0;34m | Blue |
\e[1;34m | Bold Blue |
\e[0;35m | Purple |
\e[1;35m | Bold Purple |
\e[0;36m | Turquoise |
\e[1;36m | Bold Turquoise |
\e[0;37m | Light Gray |
\e[1;37m | Bold Light Gray |
Now let’s look at the basic Background color options. You can replace \e[ with \033 if you are using the escape sequence
Options | Descriptions |
\e[40m | Dark Gray |
\e[41m | Red |
\e[42m | Green |
\e[43m | Yellow |
\e[44m | Blue |
\e[45m | Purple |
\e[46m | Turquoise |
\e[47m | Light Gray |
Some of the additional prompt variables that are not set in the .bashrc that you might want to customized.
PS1 is the default prompt and that is what is mostly set in the .bashrc
PS2 – use this if you want to change the continuation interactive prompt (When a long command is broken by \ at the end of the line) default is “>”
PS3 – use this for the “select” loop inside a script.
PS4 – use this when a shell script is executed in debug mode (“set -x” will turn this on) default =”++”
Therefore it is command to use the PS1 variables as the rest of the variable are rarely use by normal users.
To test out the prompt before making the change permanent you can issue the command e.g PS1=’Test Prompt \[\033[01;31m\]\u\[\033[00m\]\$’ to change the prompt to display the following.
The \[\033[00m\] options ends the color for the range.
Recent Comments