Rename a user on a Linux desktop system
This time, I won't go into details about the context, but let's just say that for some compliance reasons, I needed to rename a user on a Linux desktop computer.
Rename ? Why not create a new user ?
3 things :
- I wanted to keep the same UID/GID, and I don't like having 2 users with the same UID;
- I wanted to keep all the existing configurations in the $HOME directory ; I could have moved from the old one to the new one and chown everything, but I would not have prevented some of the funny things that happened along the way ;
- who doesn't like some challenge ?
The easy part
The basic change itself is the easyest. I renamed the user in /etc/passwd
and in /etc/shadow
using vipw
/ vipw -s
. I also needed to update /etc/group
and /etc/sudoers
(or maybe some other file in /etc/sudoers.d
but you get the idea).
Of course I renamed the home directory.
On the graphical side of things, the wallpaper needed to be set up.
The hard part
I run a lot of virtual machines. Not as much as I would like to, but on every desktop system I have, I tend to install a hypervisor and run at least one or two VM. When I run libvirt on a desktop or laptop, I usually create storage pools in my home (${HOME}/libvirt/images
for VM disks and ${HOME}/libvirt/boot
for ISO files). This implies the virtual machines are running in my home directory.
Two ways to operate here :
- the "good" way : use the graphical Virt-Manager tool or
virsh edit|pool-edit
to change the paths ; - the "bad" way : explore
/etc/libvirt/qemu
and/etc/libvirt/storage
and mass-replace the paths using sed.
Guess which one I chose. Don't forget to restart the libvirt related services, or reboot.
If you have a laptop, it means you're somewhat mobile. Multiple Wi-Fi networks are set up, and maybe one or two VPN access. Paths are also used for these settings, using Network Manager. I don't know if there is a good way to do this, but I found connection settings saved in /etc/NetworkManager/system-connections
. This was especially useful for certificate files location for a VPN access.
But for my OpenVPN access, this may be not enough. It's no secret I mainly use Fedora on my laptop, and like all Red Hat-based distributions, SELinux is enforced. So, yes, I had to modify some SELinux settings. A "bad" way could be to look at /etc/selinux/targeted/contexts/files/file_contexts.local
.
Some other files I forgot to modify in the first part are /etc/gshadow
, /etc/subuid
and /etc/subgid
. My notes tell me I had to run podman system migrate
following the last two changes.
The hardest part
The most annoying part is the Firefox profile. Here, I had to run firefox --ProfileManager
to get everything back to normal.
Something else ?
From what I remember, and my notes on the matter, that's all. If someone ever stumbles upon this post, trying to do the same, I would suggest to go and search for other settings by running grep -R <oldusername> /etc/*
and grep -R <oldusername> /home/*
.
And if you don't feel the courage to go through all theses changes, you can still keep the old path to your home directory.
I hope you enjoyed this post ! If you did, please share it on your favorite social networks :-)
Photo by Pierre Bamin on Unsplash.