From Mageia wiki
Jump to: navigation, search

Rename user

From time to time it is necessary to rename a user. This may be for cosmetic reasons or it could related to issues with the username such as it containing characters that cause problems with various bits of the infrastructure.

Verifying the request

First, make sure the rename request is legitimate. See the section on verification in SOP Change user e-mail. Make sure the new username is available and that it isn't somehow inappropriate or confusing.

The actual user rename

As users are stored in LDAP, this requires interaction with the primary LDAP server.

Let's say that olduser is the username that we wish to change and newuser is the new one. Create a file rename.ldif containing:

 dn: uid=olduser,ou=People,dc=mageia,dc=org
 changetype: modrdn
 newrdn: uid=newuser
 deleteoldrdn: 1

Next, run this:

 [root@duvel ~]# ldapmodify -H ldaps://ldap.mageia.org -D uid=yourusername,ou=People,dc=mageia,dc=org -W < rename.ldif

Note the use of yourusername above in the bind DN. This is, as the text suggests *your* username. You should see:

 modifying rdn of entry "uid=olduser,ou=People,dc=mageia,dc=org"

That's it! You can just ctrl-d out of the ldapmodify shell after that. You can also write these commands to an LDIF file if you prefer.

Now, if the user has a home directory (e.g. is a packager), change the home directory by creating a renamehd.ldif file and executing it like above (note that this procedure is untested):

 dn: uid=newuser,ou=People,dc=mageia,dc=org
 changetype: modify
 replace: homeDirectory
 homeDirectory: /home/newuser

You should then rename the actual homedir on git.mageia.org (currently duvel):

 [root@duvel ~]# mv /home/olduser /home/newuser

And confirm this change worked:

 [root@duvel ~]# getent passwd newuser
 newuser:*:5123:5000:Joe User:/home/olduser:/usr/local/bin/sv_membersh.pl

Hmm, it didn't work??? But perhaps it's a caching issue:

 [root@duvel ~]# nscd -i passwd
 [root@duvel ~]# getent passwd newuser
 newuser:*:5123:5000:Joe User:/home/newuser:/usr/local/bin/sv_membersh.pl

That's better!

Other updates/propagating the change

Although it's run by cron, and the home directory is manually renamed, it is probably wise to run:

 [root@duvel ~]# /usr/local/bin/ldap-sshkey2file.py

to generate ssh key files (i.e. the authorized_keys).

If the old user maintains any packages, it is easiest to bulk change any maintainer db files with references to the old user:

 [root@duvel ~]# sed -i 's/^olduser$/newuser/' /var/lib/maintdb/db/*

See also SOP Reassign Package in Maintdb for more details on changing maintdb.

And to keep the generated people pages up-to-date instead of waiting for the next cron job run, it's nice to run:

 [root@sucuk ~]# mkpeople
 [root@sucuk ~]# rm -f /var/www/vhosts/people.mageia.org/u/olduser.html