Here is what I have done:
-
Change a username in the last line:
tiny
toabc
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
-
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?
Best Answer
The reason you got stuck after your edit is that the
/etc/shadow
file contained an entry for the password oftiny
but no entry forabc
, whereas the/etc/passwd
file contained an entry forabc
and not fortiny
. Whensudo
looked, it identified you correctly (according to the password file) asabc
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 forabc
, 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 fromvim
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.