He, Peng

A Roboticist.

The secret of getting ahead is getting started.

How to change the Username and Hostname on Ubuntu

Change the username

At the start screen press Ctrl+Alt+F1.
Log in using your username and password.
Set a password for the "root" account.

sudo passwd root  

Log out.


Log in using the "root" account and the password you have previously set.
Change the username and the home folder to the new name that you want.

usermod -l <newname> -d /home/<newname> -m <oldname>  

Change the group name to the new name that you want. I'm not so sure about which group should I change to

groupmod -n <newgroup> <oldgroup>  

Lock the "root" account.

passwd -l root  

If you were using ecryptfs (encrypted home directory). Mount your encrypted directory using ecryptfs-recover-private and edit <mountpoint>/.ecryptfs/Private.mnt to reflect your new home directory.
Log out.


Press Ctrl+Alt+F7.

Change the hostname, which is the computer name

Type the following command to edit /etc/hostname using nano or vi text editor:

sudo nano /etc/hostname  

Delete the old name and setup new name.
Next Edit the /etc/hosts file:

sudo nano /etc/hosts  

Replace any occurrence of the existing computer name with your new one.
Reboot the system to changes take effect:

sudo reboot  

Change the password


Super easy, isn't it?

Recent Posts

My Machine Learning Summary Part.1 How to NOT get confused by the "Cost Functions"

Abstract: I have been studying Andrew Ng's (吴恩达) Machine Learning introduction class on Coursera. Ne…

In Machine LearningRead More
Earlier Posts

Linux Essentials

Install Deb. Pkg from Command Line You can install it using sudo dpkg -i /path/to/deb/file followe…

In ConfigsRead More
comments powered by Disqus