27 February 2019

recreating a user

a short while back, i made an attempt to switch my home shell from bash to xonsh. in the process of doing this, i took more of a raw approach. despite the learning process that was, it left me with scars.

these scars are specific to my system's user management and my account (see the last paragraph of the shell switch post). i no longer had a recognized user requiring me to type in my username rather than just typing in my password.

today, i made the attempt to fix that. now, i will admit there might be a better way out there to do this, but i took this (raw) route again.

with superuser privileges, i edited the /etc/passwd file and appened a digit to my username and changed my user id to 1001. i did this in the /etc/group and /etc/shadow files.

i then created a new user with my original name using this command (as root):

# useradd mock -d /home/mock -M -u 1000 -G wheel -U

i set the password for the replacement user, and i rebooted the system for all the things to be recognized. (i came back later to add the other groups to which this user belonged.)

the command created the new user with the established name assigning the original user id to the new user and the original user's home directory also to the new user. because the user id is the same, all filesystem permissions still belong to the appropriate user.

i then removed the old, modified username from the /etc/passwd and /etc/group files.

now, things are back to normal.