Skip to content

Instantly share code, notes, and snippets.

@benhoyle
Last active May 28, 2016 12:48
Show Gist options
  • Select an option

  • Save benhoyle/7ed1b7966a81c556fbbc35e35090e609 to your computer and use it in GitHub Desktop.

Select an option

Save benhoyle/7ed1b7966a81c556fbbc35e35090e609 to your computer and use it in GitHub Desktop.
Linux - Change Username
#!/bin/bash
echo "Enter the name of the OLD user and press [ENTER]: "
read olduser
echo "Enter the name of the NEW user and press [ENTER]: "
read newuser
echo "Killing all processes for $olduser"
pkill -u $olduser
echo "Changing $olduser to $newuser"
usermod -l $newuser $olduser
echo "Changing group under old username $olduser"
groupmod -n $newuser $olduser
echo "Changing home directory to /home/$newuser"
usermod -d /home/$newuser -m $newuser
echo "Checking old id"
id $olduser
echo "Checking new id"
id $newuser
@benhoyle
Copy link
Author

Useful for changing the default 'pi' user on the Raspberry Pi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment