I change the last line in /etc/passwd and I can't use sudo

5,854

Solution 1

The reason you got stuck after your edit is that the /etc/shadow file contained an entry for the password of tiny but no entry for abc, whereas the /etc/passwd file contained an entry for abc and not for tiny. When sudo looked, it identified you correctly (according to the password file) as abc based on the UID of the process you were running, but when it looked to compare what you entered as your password with the encrypted (hashed) password stored in /etc/shadow, it couldn't find an entry for abc, so it had to report the failure.

As shaddy said in his answer, don't edit the password or shadow files by hand. If you must break the rule, then edit both in a single invocation of vim, and don't exit from vim until you've proved that the changes are sane enough to work by using another terminal window, and do save backup copies of the files before you start hacking them, and do reconsider why you're breaking the rules in the first place, because it probably isn't a good idea.

Solution 2

You must NEVER edit your passwd file manually because you will mess things up.

The proper way to change your username is:

usermod -l newUsername oldUsername

Then change home folder:

usermod -d /home/newHomeDir -m newUsername

To change password you should use:

sudo passwd yourusername

I suggest you to revert your passwd file back, or if you can't edit it because you can not login with root - then boot with live cd and revert the file back. Then use the proper way.

Share:
5,854

Related videos on Youtube

tinyork
Author by

tinyork

Updated on September 18, 2022

Comments

  • tinyork
    tinyork over 1 year

    Here is what I have done:

    1. Change a username in the last line: tiny to abc

      • tiny@tty7:~$ sudo vim /etc/passwd
      • Change this:
        tiny:x:1000:1000:tiny,,,:/home/tiny:/bin/bash
        to this:
        abc:x:1000:1000:tiny,,,:/home/tiny:/bin/bash
    2. tiny@tty7:~$ sudo vim /etc/shadow

      • it shows: [sudo] passwork for abc:

      • I didn't change my password but it can't login root!

      • I type Ctrl+Alt+F1 to tty1 but neither tiny or abc can't login with my password

    and I try to look at ls ~ -la, here it shows like this:

    drwxr-xr-x 28 abc tiny 4096 Apr 6 03:04 .

    How can I login root? and why the user name in prompt tiny@tty7 still be tiny while in sudo it show the abc's password?

  • tinyork
    tinyork about 9 years
    thank you~ I thought the most difficult is to login with root then I reboot , choose revovery mode , root and then get my passwd file back~ it work~