1

I have a problem that "corrupted" my user, let's call it olduser. I got stuck in the login screen and nothing I tried could fix it.

Luckily I had backups, but I didn't need them because the files are still all there.

The only way to login was through a new user newuser. But all my aliases and mounting places are on olduser or pointing to it (aliases). Also my ssh points to olduser.

For example, my other partitions are on /media/olduser/, aliases point to /home/olduser/Desktop/.

So,

My question is: how can I rename olduser to foo or whatever so that then I can rename newuser to olduser?


If you are curious, here is my problem and some of the solutions I tried:

Unity doesn't load, no Launcher, no Dash appears

What to do when nothing seems to fix Ubuntu 14.10 stuck after log in?

Unity doesn't load, no Launcher, no Dash appears

2 Answers2

1
  1. Boot to root shell in recovery mode
  2. mount filesystem in read-write mode with mount -o remount,rw /
  3. Delete the new user that you created
  4. Change your username in /etc/passwd file.
  5. Reboot.

Repeat steps 1-2 if you need to undo the changes in /etc/passwd

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
  • Thanks for the answer, but won't this keep the corrupted user and delete the good one?

    My goal is to have the new user have the name of the old one, without deleting the old user.

    Or will this move the old user's files to an uncorrupted user?

    – Ed Nicara Nov 07 '15 at 20:36
  • @EdNicara OK, so you were not clear in your question. I answered exactly the renaming part. What you could do, and it's better approach imho, give that user new sudo privileges, add new user to old user's group, and use find to chmod all files of old user to new user. I am running out of battery on my laptop so more detailed answer will come later. Let me know if you have any further questions – Sergiy Kolodyazhnyy Nov 07 '15 at 20:46
  • This would work and the answer from @cas showed me how to do the renaming part. Thank you! :p – Ed Nicara Nov 08 '15 at 10:26
0

If you have given root a password you can do this without rebooting to recovery mode. Otherwise you'll have to either give root a password (e.g. with sudo passwd root) before you start this procedure or reboot.

  1. Press Ctrl-Alt-F1 and login as root. or reboot to recovery mode and bring up a root shell.

  2. Use vipw and vipw -s to change your usernames in /etc/passwd and /etc/shadow respectively. e.g. change olduser in both files to foouser and then change newuser to olduser.

    • Remember to change the home directory fields for the users.
  3. Do the same with vigr and vigr -s for the /etc/groups and /etc/gshadow files.

  4. cd to the directory where all the user home directories are. This is almost certainly /home.

  5. mv olduser/ foouser

  6. mv newuser/ olduser
  7. Change the ownership and group on all files in olduser/.

    chown -R olduser olduser/

    chgrp -R olduser olduser/

  8. Change the ownership and groups on all files in foouser/

    chown -R foouser foouser/

    chgrp -R foouser foouser/

  9. If you had to reboot to recovery mode, reboot again, and then login as olduser. Otherwise, just press Ctrl-Alt-F7 (or whatever Fn key corresponse to your GUI login screen) and login as olduser

cas
  • 161