change username and home directory linux 1

change username and home directory linux

# login as root and make sure that there are no active processes for user
usermod -l NEW_USERNAME OLD_USERNAME
# if user is running kill user w the following command
userUID=$(id -u OLD_USERNAME) && pkill -U $userUID

Here is what the above code is Doing:
1. We’re getting the user’s UID (user ID) by running the id command with the -u flag.
2. We’re then using the pkill command to kill all processes running under that UID.
3. We’re then renaming the user with the usermod command.

Similar Posts