Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an ec2 instance. When I log in, it will prompt this:

[ec2-user@ip-10-128-80-10 ~]$ 

I want to rewrite the ip-10-128-80-10 to some nickname, such as us1, us2, us3.

[ec2-user@us1 ~]$ 

How to set it ?

share|improve this question
add comment

3 Answers

up vote 11 down vote accepted

That's the system's hostname, which you can set in /etc/hostname.

Next, execute this as root

$ service hostname restart
share|improve this answer
1  
if by chance you want to go beyond just setting the host name, your shell has variables to set it's prompt string template (with the hostname and other things wherever you like, or without them). –  Skaperen Sep 8 '12 at 1:42
    
It works after rebooting :) –  qrtt1 Sep 8 '12 at 1:43
2  
You didn't have to reboot, but rather could have likely just run $ service hostname restart. –  EEAA Sep 8 '12 at 1:47
1  
Probably only needed a logout/logbackin, or maybe even just "exec ${SHELL} -i". –  Skaperen Sep 8 '12 at 2:13
add comment

Note that you don't have to change the hostname if you prefer not to. If you just want to change the prompt, you can set the shell variable PS1. At the moment, it's probably set to something like this:

PS1='[\u@\h \w]\$ '

You can set it to anything you like, e.g.

PS1='\u@test1234 \w\$ '
share|improve this answer
add comment

I have not been able to get ErikA's answer to work in recent versions of CentOS... to achieve success (as root):

  • Add yournewhostname into /etc/sysconfig/network in the HOSTNAME field...
  • Add yournewhostname into /etc/hosts for 127.0.0.1
  • echo "yournewhostname" > /proc/sys/kernel/hostname or service hostname restart
  • IMPORTANT: logout and log back in.

You have now renamed your system

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.