2

I just want to change the username of a user with an encrypted home directory. Is there a simple way instead of the suggested restoring and so forth?

LiveWireBT
  • 28,763

1 Answers1

5
  1. It's best to unmount your home directory and execute the commands from another administrator account on the computer. You could use ecryptfs-umount-private or just reboot to unmount the directory.
  2. Change the login name and directory name from old_user to new_user:

    sudo usermod -l new_user -m -d /home/new_user old_user
    
  3. Here comes the important part for the proper configuration:

    • There exists a file named /home/.ecryptfs/$USER/.ecryptfs/Private.mnt it usually contains the following: /home/$USER
    • The following symlinks exist in your home directory when eCryptfs is not mounted:

      .ecryptfs -> /home/.ecryptfs/$USER/.ecryptfs
      .Private ->  /home/.ecryptfs/$USER/.Private
      
    • Make sure that $USER in all these instances reflects the changes you intended to make, e.g. new_user. You can use nano to edit text files and ln -s to create new symlinks.

You should be able to login again. I just tried it on my own. If you cannot log in through the GUI try from the terminal and check again that everything is in place.

LiveWireBT
  • 28,763
  • Which version of Ubuntu does this work on? (Just in case it doesn't work on a future/past version) – Xen2050 Dec 31 '18 at 23:41
  • @Xen2050 Based on this answer I'd say it should work on all non-EOL releases. In this example though I actually used Fedora 29. I made similar modifications to Ubuntu hosts years ago like providing an unencrypted .ssh/authorized_keys file for remote login, so I'd say once you understood where your data and configuration is and how the individual parts come together it's pretty basic and solid. – LiveWireBT Jan 01 '19 at 00:42
  • This worked for me, except renaming the /home/.ecryptfs/$USER directory. If I rename it, I can no longer access the directory, regardless if I change the reference in the files in my home directory. No biggie though, I don't mind if that directory has a different name, it's hidden inside .ecryptfs directory anyway. – Alex Burdusel Dec 10 '22 at 10:32