Skip to content

Instantly share code, notes, and snippets.

@nixjobin
Created April 15, 2015 09:17
Show Gist options
  • Save nixjobin/f6a1cbd1f88f3f5a1919 to your computer and use it in GitHub Desktop.
Save nixjobin/f6a1cbd1f88f3f5a1919 to your computer and use it in GitHub Desktop.
Use this script to rename a user in RHEL / CentOS / Ubuntu etc
#!/bin/bash
# Author : Jobin Joseph
clear
echo "Script for renaming a User
Use at your own risk"
echo -n "Enter the current username: "
read joldname
echo -n "Enter the new username: "
read jnewname
echo "########################
The user * $joldname * will be renamed to * $jnewname *
Press ctrl+c to cancel, The commands will be executed in 10 seconds
########################"
sleep 10
# rename the user
usermod -l $jnewname $joldname
#rename group
groupmod -n $jnewname $joldname
#move home
usermod -m -d /home/$jnewname $jnewname
if [ $? -eq 0 ] ; then
echo "########################
The account has been renamed, Please update the sudeors file if the user has sudo access
########################"
id $jnewname
else
echo "********* Something went Wrong !!! Please check the above error message *********"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment