linux change hostname code example
Example 1: 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
hostnamectl
Example 2: centos change hostname
# hostnamectl set-hostname your-new-hostname
Example 3: linux change username
# login as root and make sure that there are no active processes for user
usermod -l NEW_USERNAME OLD_USERNAME
# if user is running kill user w the following command
userUID=$(id -u OLD_USERNAME) && pkill -U $userUID
Example 4: linux change hostname
sudo nano /etc/hostname
sudo nano /etc/hosts
sudo reboot