Results 1 to 8 of 8

Thread: Unable to login after a username change

  1. #1
    Join Date
    Dec 2020
    Beans
    3

    Unable to login after a username change

    Hi all,

    I changed my username as follows:
    1. Created 'temporary':
    Code:
    sudo adduser temporary
    2. Added it to sudo group:
    Code:
    sudo adduser temporary sudo
    3.Changed oldUsername to a new:
    Code:
    sudo usermod -d newUsername oldUsername
    4.Changed home folder:
    Code:
    sudo usermod -d newHomeDir -m newUsername
    After I restarted the machine and:
    - my newUsername doesn't appear on the login screen
    - oldUsername is on the login screen, and it doesn't accept my password
    - I can login only to the temporary user
    - when I list users with
    Code:
    cat /etc/passwd
    I get:
    Code:
    temporary:x:1001:1001:,,,:/home/temporary:/bin/bash
    Code:
    newUsername:x:1000:1000:oldUsername,,,:/home/newUsername:/bin/bash
    What should I do to fix this?

    Thanks!
    Last edited by sunreaver; December 31st, 2020 at 04:58 AM.

  2. #2
    Join Date
    Jun 2014
    Beans
    6,136

    Re: Unable to login after a username change

    Your command to add the user temporary to sudo group doesn't look right. Take a look at the instructions at the link below. When you created the new user temporary, you should have been prompted to create a password for that user, were you and did you?

    https://phoenixnap.com/kb/how-to-cre...user-on-ubuntu

  3. #3
    Join Date
    Dec 2020
    Beans
    3

    Re: Unable to login after a username change

    Thank you. I forgot to mention that, I created the password for 'temporary', and I have no problem with this user.

    My problem is that I cannot login to the user that I was renaming.

    I guess the issue is that I have 'oldUsernane' in here
    Code:
    newUsername:x:1000:1000:oldUsername,,,:/home/newUsername:/bin/bash
    but I don't know how to get rid of it.

    So if my 'oldUsernane' was 'john' and the new name 'david', now this line in
    Code:
    cat /etc/passwd
    looks like this
    Code:
    david:x:1000:1000:john,,,:/home/david:/bin/bash
    Last edited by sunreaver; December 31st, 2020 at 11:05 PM.

  4. #4
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Unable to login after a username change

    check the group membership.

  5. #5
    Join Date
    Dec 2020
    Beans
    3

    Re: Unable to login after a username change

    There's no group or user with my old name. I logged as root and if I check with cat /etc/passwd, I have 2 users: the renamed one 'david' and 'temporary', but when I check root home directory, I have 'john' and 'temporary'. I think at this point I'll just reinstall Ubuntu.

  6. #6
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Unable to login after a username change

    Quote Originally Posted by sunreaver View Post
    There's no group or user with my old name. I logged as root and if I check with cat /etc/passwd, I have 2 users: the renamed one 'david' and 'temporary', but when I check root home directory, I have 'john' and 'temporary'. I think at this point I'll just reinstall Ubuntu.
    Why? I never use usermod. Just edit the passwd and group files directly, with their shadow files too. They aren't complex. The fields are clearly spelled out in the manpages for each file. They only need to be consistent. I find changing a userid quick and trivial this way. Make the edits quickly, so that sudo checks don't prevent changes.

    You can always boot off Ubuntu Install / Try Ubuntu, mount the storage/partition with /etc/ and edit the files if too slow. Those files just need to be "consistent." Editing is much easier than trying to remember commands and options for me. There is no reason the username's HOME must match the username. It is not required, only helps humans. Computers don't care. They always lookup the answer using getent() or getent passwd or getent group

    BTW, use the 'id' command to see fully the group membership for any userid.
    Last edited by TheFu; January 1st, 2021 at 08:30 PM. Reason: s/it/if/ and added clearer getent stuff.

  7. #7
    Join Date
    Aug 2011
    Location
    51.8° N 5.8° E
    Beans
    5,771
    Distro
    Xubuntu 20.04 Focal Fossa

    Re: Unable to login after a username change

    But do make sure that the home directory mentioned in /etc/passwd matches the name of the actual directory. You haven't told us yet what that is.

    The only old username left in your /etc/passwd is in the comment field. That shouldn't be much of a problem.

  8. #8
    Join Date
    Apr 2014
    Beans
    724

    Re: Unable to login after a username change

    Seems like an awful complicated process. Why didn't you just add a new user with proper groups, chown -R and rename the entire /home /"$USER" dir and move on with life? Are you trying to save the uid / gid?

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •