Changing Hostname in Ubuntu

Having built a new server in the summer, I thought I’d post a little tip for if you decide to change the hostname in Ubuntu. I got caught out after completing steps 1 to 3 and then rebooting the server! Couldn’t SSH into it after it rebooted. Had to get the spare monitor out and figure out what I’d missed…

  1. check firewall rules ufw that 22 is open
  2. change /etc/hosts
  3. change /etc/hostname
  4. change /etc/ssh/*.pub with new hostname otherwise you won’t be able to SSH into the machine any more!

Now you can reboot