how to change display name or nickname of ubuntu server? (AWS EC2)

I'm wondering how I can change the displaying name when I log into my server.

So for example I SSH into the server and it display my username @ ec2 instance ip.

example: username@ip-10.0.0.129
what I want: username@production

I don't want it to affect any DNS, host, hostname or Ip stuff only to give it a nickname, any suggestions?

another example: When Cron finishes its job it sends an email from root

Cron <root@ip-10-0-0-129>.....
what I want: Cron <root@production>.....

Thanks!

1 Answer

What you are trying to change is the PS1 variable. It is not an environment variable but a bash shell variable. If you are interested in learning more about that look here.

To be brief, if you want to just change the part where traditionally you'll see the server name, just to the following:

1 In a terminal echo $PS1. You will probably see something like:

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$

In it \u stands for Username and \h stands for Hostname.

2 Still in the terminal try doing:

PS1="\[\e]0;\u@\What you want the hostname to be: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@What you want the hostname to be\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$"

Notice the quotes that need to be added here but won't be in stage 3.

3 When you are satisfied with the results go to your .bashrc file and replace what it says in the line where PS1 is defined. Notice that it appears several times in the file and that each one should be changed differently and separately (ideally, at least). Save and quit the file.

4 Type . ~/.bashrc, this should reload the file and start presenting the prompt you have set. All we did currently will change it for your user. It will not change it for the root user. To do that you must edit the file /root/.bashrc in a similar fashion.

Good luck!

10

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like