2

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: [email protected]

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 1

0

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
  • Thank you, I appreciate your help!
    – paul9494
    Oct 11, 2019 at 17:00
  • @paul9494 ,welcome. Can I suggest that you edit the tags? If the is one for bashrc, or for the command prompt (or even terminal in general), they’re more relevant than ec2 or aws).
    – Uberhumus
    Oct 11, 2019 at 17:16
  • @paul9494 did this solve your issue?
    – Uberhumus
    Oct 12, 2019 at 15:09
  • Making these changes you suggested works while I'm logged in but on reboot it resets to the IP, I changed my /etc/hosts to: 127.0.0.1 localhost production and then change my /etc/hostname to: production Do a reboot and now my terminal always has: username@production BTW: so far I've not experienced any troubles changing these files, should I be worried? Thank you!
    – paul9494
    Oct 14, 2019 at 16:56
  • @paul9494 did you save the .bashrc files?
    – Uberhumus
    Oct 14, 2019 at 16:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .