Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Short version

Can I just edit the /etc/hosts file, meaning can I login as user@<hostname I wish to change> without unintentionally breaking something? Would this be enough or is there something else to do?


Long version

I'm trying to create an Ubuntu 16 guest OS in VirtualBox on a Windows 10 host. I have downloaded the Ubuntu 16 .vdi from oxboxes.org, but I don't like the fact that I have to login as osboxes@osboxes. Ultimately I want to login as ab@ab.

First I changed the user name using usermod as described here in @ValentinUveges answer. This worked and so I can now at least login as ab@osboxes. To change @osboxes to @ab I have tried groupmod -n ab osboxes, but this failed.

But at least I think what I really need to change is the /etc/hosts file, which currently contains

cat /etc/hosts  
127.0.0.1   localhost  
127.0.1.1   osboxes

So can I just edit /etc/hosts and change osboxes to ab in order to allow me to login as ab@ab without unintentionally breaking some parts of the OS? Would this be enough or is there something else to do?

Apart from the steps I mentioned before, this is a "fresh" osboxes.vdi virtual operating system file.

share|improve this question
2  
Please do not post text or textfiles as screenshots or images.# – Thomas 21 hours ago
3  
Possible duplicate of How do I change the hostname without a restart? – wjandrea 12 hours ago
1  
Perhaps I need to phrase it to something like "how can I change the login name from osboxes@osboxes to bespokeUser@bespokeHostname", will consider doing this for when I have more time. Reckon it will change the duplicated status/help future searchers? – hello_there_andy 12 hours ago
1  
Then it would simply be a duplicate of two questions: the hostname one and askubuntu.com/questions/34074/how-do-i-change-my-username – muru 11 hours ago
up vote 14 down vote accepted

To change the host name permanently, you will have to change it in two files.
In the Ubuntu guest system open a terminal and execute these commands :

sudo nano /etc/hostname ... now edit the file (change the host name).

Press Ctrl + X to close the file and confirm the change by pressing Y.

sudo nano /etc/hosts ... now edit the file (change the host name).

Press Ctrl + X to close the file and confirm the change by pressing Y.

Then reboot the virtual operating system - now the host name has changed.
Additional information : Changing the host name this way is completely safe.

share|improve this answer

Short Answer:

Yes you can.

Full Answer:

If you do so, you'll have to restart the system to take the changes into effect. Once restarted, the hostname would be permanently changed to "ab". If you want your system to change the hostname only for the current boot, you can use

sudo hostname ab

This change will not be permanent and will be reversed as soon as you restart.

Hope it helps.

share|improve this answer
    
Cheers, a bit of confusion as to why the change will not be permanent, how can I make this permanent then? – hello_there_andy 19 hours ago
1  
@hello_there_andy : As I mentioned, If you edit the file, the changes will persist but if you simply choose to execute sudo hostname ab, the changes will be reversed after reboot. – 7_R3X 18 hours ago
    
You basically need to do both, tell the kernel using the hostname command, and change /etc/hostname, because a startup script will call hostname with the contents of that file. – Simon Richter 2 hours ago
1  
"Once restarted, the hostname would be permanently changed to "ab"." It's not permanent; you can change it again. The correct term is "persistent". – Lightness Races in Orbit 1 hour ago

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.