To change the hostname from an SSH terminal, follow these steps:
-
Log in to your server via SSH using a user with root or sudo privileges.
-
Open the file /etc/hostname in a text editor. For example:
sudo nano /etc/hostname
-
Replace the existing hostname with the new hostname that you want to set. Save and close the file.
-
Open the file /etc/hosts in a text editor. For example:
sudo nano /etc/hosts
-
Find the line that contains the old hostname and replace it with the new hostname. Save and close the file.
-
Reboot the server for the changes to take effect. You can do this by running the command:
sudo reboot
After the reboot, your server will use the new hostname.