Skip to content

Instantly share code, notes, and snippets.

@andmax
Created December 5, 2018 12:37
Show Gist options
  • Save andmax/5816fbf5573fe59288e37e243b597817 to your computer and use it in GitHub Desktop.
Save andmax/5816fbf5573fe59288e37e243b597817 to your computer and use it in GitHub Desktop.
Bash script to change host name
#!/usr/bin/env bash
NEW_HOSTNAME=$1
echo $NEW_HOSTNAME > /proc/sys/kernel/hostname
sed -i 's/127.0.1.1.*/127.0.1.1\t'"$NEW_HOSTNAME"'/g' /etc/hosts
echo $NEW_HOSTNAME > /etc/hostname
service hostname start
su $SUDO_USER -c "xauth add $(xauth list | sed 's/^.*\//'"$NEW_HOSTNAME"'\//g' | awk 'NR==1 {sub($1,"\"&\""); print}')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment