Problem: Well it’s more of an irritation. My new hosting provider does allow SSH access, but when logged in the bash prompt looks like this, regardless of which account I’m logged-in as, or where I am:
What I want is for it to show something like:
Solution: The bash prompt can be customised via a profile script, ideally anything that loads when you log in like ‘.bash_profile’, ‘.bashrc’ or ‘.profile’. If one of these files doesn’t already exist in your home directory (check with
ls -la ~ to list the contents) then create one. Here is an example of creating, editing and loading a login script to show a better prompt.
Step 1: Create the file and open it for editing.
$ touch ~/.bash_profile $ nano ~/.bash_profile
– Deciding which file to create probably depends on your OS flavour. Maybe Google it? I searched for “centos 6 user login script” and found that when using an “interactive login shell” these two files are read: ‘.bash_profile’ and ‘.profile’.
– `touch` creates the file with owner and permissions given to the currently logged-in user.
– `nano` is a nice easy to use text editor. If it’s not available, try `vim`, or if you hate yourself use `vi` and spend 30 mins googling the correct commands to save and exit the file again.
Step 2: Add the following to the file, then save it.
export PS1="\u@\h:\w$ "
– An explanation of the special characters that can be used with the prompt can be found under ‘PROMPTING’ on the bash man page. But for brevity:
‘u’ = username of current user.
‘h’ = the hostname up to the first ‘.’.
‘w’ = the current working directory, with $HOME abbreviated with a tilde.
Step 3: Make the change take effect.
Just logging-out and logging-in again should show your changes. Maybe a more solution is to load the script again with the following command:
$ source ~/.bash_profile
– If this has no effect, it might be that ‘.bashrc’ or ‘.profile’ should have been used for your server.
Result: On my server, when logged in right now I get the following:
which is much better than:
Please let me know if this post was useful with a click!