Shell/Bash: how to change hostname in ubuntu Example


Shell/Bash Example: This is the "how to change hostname in ubuntu" Example. compiled from many sources on the internet by

how to change hostname in ubuntu

#1- Delete the old name and setup new name
sudo hostnamectl set-hostname newHostname

#2- Edit the /etc/hosts file:
sudo nano /etc/hosts

#3- Reboot the system 
sudo reboot

#4- To check the new hostname

linux change hostname

sudo nano /etc/hostname
sudo nano /etc/hosts
sudo reboot

change username ubuntu

# -l changes login name
# -d changes home directory
# -m copies over contents from old home directory
usermod -l  -d /home/ -m 

# NOTE: will not work if you are currently logged on as user
# - workaround by temporarily enabling root account and running above command there
# [sudo passwd root] 
# - after root account has been used to change username lock it using
# [sudo passwd -l root]

ubuntu chang host name

Type the following commands:
$ sudo hostname new-server-name-here

* Summary: This "how to change hostname in ubuntu" Shell/Bash Example is compiled from the internet. If you have any questions, please leave a comment. Thank you!