Change username
From ArchWiki
Contents |
Introduction
Changing a username under Arch (or any flavor of Linux) is safe and easy when done properly. You can also change the associated groupname for the user if you wish. Following the procedure below will do just this retaining your UID/GID for the affected user thus not roaching any file permissions you have setup.
Procedure
Warning: Make certain that you're not logged in as the user whose name you can changed! Open a new tty (Ctrl+Alt+F1) and log in as root or as another user and su to root.
Changing the username/group
Basically, you have four commands to type as root to change the username and group. They are as follows:
# mv /home/oldname /home/newname # usermod -l newname oldname # usermod -d /home/newname newname
If you want to change the group also:
# groupmod -n newname oldname
If you want to see what each command is doing, check out the manpages for usermod and groupmod.
Gotchas
- If you're using sudo make sure you update your /etc/sudoers to reflect the new username(s) (via the visudo command as root)
- If you modified your PATH statement in your ~/.bashrc, make sure you change it to reflect the new username
- Likewise, be sure you change any config file such as /etc/rc.local or whatever if you are pointing it to a script or mountpoint, etc. within the old user's home directory.
- I had to repeat the procedure to [enable spell checking] in Firefox or else the check-as-you-type spelling didn't work for me after renaming my user.
- I had to reinstall my Thunderbird addons ([Enigmail]) after renaming my user.
- Anything on your system (desktop shortcuts, shell scripts, etc.) that uses an absolute path to your home dir (i.e. /home/oldname) will need to be changed to reflect your newname. To avoid these problems in shell scripts, simply use the ~ variable for home directories.