Difficulty: ★★☆☆☆
The easy way
- Backup your important files.
- Create a new user
a. Standard user
b. Admin useruseradd -mUG <new_user_name>
useradd -mUG lp,network,power,wheel <new_user_name>
- Remove the previous user and the user’s home
userdel -rf <old_user_name>
- Restore the files to the new user.
The hard way
Username should be chosen with care for while it is possible to change it - it does have implications beyond recognition.
Implications to consider
- Configuration file may no longer work as expected.
- Scripts and service units relying on the old username.
- Symlinks may point to invalid destinations.
Be sure to read the comments to below too …
If you still think you are up for the change - please read on.
The GNU way
By reading the man pages you find the GNU system has thought of it.
man usermod
man groupmod
Login as root!
You cannot login as the user you want to change - you must use root.
root access caveat
If you have chosen omit the root password upon initial installation - you need to set a root password before trying to change the username. This must be done using a sudo enabled user.
sudo passwd root
root access option 1
- Reboot and don’t login.
- Open a TTY pressing CtrlAltF4
root access option 2
- Reboot and edit the grub entry.
- Press e on the selected grub entry and add the number 3 to the kernel command line and press F10 to continue boot.
Manjaro usually creates a user group matching the username and assigns the user to the specific group. This makes it necessary on Manjaro to rename both the login and group.
When you are logged in as root first rename the user and rename the user’s home
usermod --login $NEWLOGIN --move-home --home /home/$NEWLOGIN $OLDLOGIN
Then rename the user’s group
groupmod --new-name $NEWGROUP $OLDGROUP
NOTE: This can also be done from a live ISO using chroot.
Remedy implications
Contributed by @freggel.doe
Some symlinks in that new home-directory might be broken after, because their target contain the full path with the old username. Wine and it’s default $HOME/.wine
-prefix comes to mind.
To find dead symlinks:
find /home/$NEWLOGIN -xtype l
Some config-files contain full paths as well (desktop background image for example). To find files with “old” username:
grep -rn "/home/$OLDLOGIN/"
Crossposted from nix.dk