Skip to content

About

Seamlessly change a user's login name.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

chusername

Rename a Linux user's login name, primary group, and home directory in one step.

The primary group is renamed only if it has the same name as the user (e.g. not users). The home directory is moved only if it is named after the user, and it stays in the same parent directory (/srv/old → /srv/new).

Handles /etc/subuid and /etc/subgid for rootless containers, renames the user's crontab and systemd linger file, and lists sudoers files that still mention the old name. Rolls back automatically on partial failure.

Requires bash and shadow's usermod/groupmod (on Alpine: apk add bash shadow).

Tested on Arch, Debian, Fedora, and Alpine.

Usage

Run as root:

# ./chusername.sh old_name new_name

Warning

From the Arch Wiki:

Also keep in mind the following notes:

  • If you are using sudo make sure you update your /etc/sudoers to reflect the new username(s) (via the visudo command as root).
  • Personal crontabs need to be adjusted by renaming the user's file in /var/spool/cron from the old to the new name, and then opening crontab -e to change any relevant paths and have it adjust the file permissions accordingly.
  • Wine's personal directories/files' contents in ~/.wine/drive_c/users, ~/.local/share/applications/wine/Programs and possibly more need to be manually renamed/edited.
  • Certain Thunderbird addons, like Enigmail, may need to be reinstalled.
  • 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 new name. To avoid these problems in shell scripts, simply use the ~ or $HOME variables for home directories.
  • Also do not forget to edit accordingly the configuration files in /etc/ that relies on your absolute path (e.g. Samba, CUPS, so on). A nice way to learn what files you need to update involves using the grep command this way: grep -r old_user *

Occurrences of old_user in backup files (files with trailing hyphen), such as /etc/group-, /etc/gshadow-, etc., can be safely ignored.

Tests

Requires Docker.

./tests/test.sh

About

Seamlessly change a user's login name.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages