Last active
May 28, 2016 12:48
-
-
Save benhoyle/7ed1b7966a81c556fbbc35e35090e609 to your computer and use it in GitHub Desktop.
Linux - Change Username
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful for changing the default 'pi' user on the Raspberry Pi.