Deleted Myself from Admin Group - Now Getting Error usermod: cannot lock /etc/passwd; try again later [duplicate]
Possible Duplicate:
Cannot lock '/etc/group' in recovery mode
I have a laptop with Ubuntu 11.10 that is shared between myself and two other family members. My user id was setup as the only "Administrator" on the laptop. The other users were setup as "Standard" users. In my attempt to try to add myself to the user groups for the other users, I somehow deleted myself from the admin groups. I used the "usermod" command from the terminal. I must have neglected to include the proper switches or syntax for the update.
It looks like I successfully added my userid to the group associated with my wife's account. When I use the "groups" command, I can see only my id and my wife's id in the list. I no longer see the "admin" or "adm" groups, and others that used to be listed. When I go into System Settings > User Accounts it looks like my ID is now listed as a "Standard" user. I would like to change my account back to "Administrator", but now I can't.
I did some searches for solutions and found that I would need to boot into Recovery Mode and execute the usermod command from the root session. I was able to successfully boot into Recovery Mode and get to the root session. I was trying to execute the command "usermod -a -G admin user1" to add my id (user1) back to the admin group.
When I execute the command from the root session, I get the error message "usermod: cannot lock /etc/passwd; try again later". I tried preceding the usermod command with "sudo", but it didn't make a difference, same error. I then tried adding a new user using adduser, thinking I would try to create a new userid and make the new userid part of the admin group. I get the same error using the adduser command.
I saw some posts that recommend looking for and deleting files that end in ".lock" in the etc directory. The only file I found was .pwd.lock which I haven't touched.
I am at a loss as to what to try next. I am relatively inexperienced with Ubuntu and Linux, so alot of this is new to me. Any help you can provide would be much appreciated.
Solution 1:
I finally figured out why I was receiving the "usermod: cannot lock /etc/passwd; try again later" error message. The root cause of the issue had to do with the fact that when I booted into Recovery Mode, by default the filesystem was mounted as read-only. Because the filesystem was mounted as read-only, the adduser and usermod commands were not able to perform their functions and produced the error message.
What got me thinking the issue was not a file corruption or *.lock related issue was that there were no passwd.lock, group.lock, or shadow.lock files in the /etc folder. Also, I got a different error message when I tried to copy, rename or delete the .pwd.lock file that was in the /etc folder when I was booted into the Root Session in Recovery Mode. I got a different error message, something like unable to rename file read-only. I did some web searching on "Recover Mode Read Only" and came across the following post: http://www.linuxquestions.org/questions/linux-general-1/cannot-edit-fstab-in-recovery-mode-filesystem-is-read-only-540195/.
The post talks about the Recovery Mode being in read-only mode by default. It suggested remounting as read-write to allow changes to be made to files in the /etc folder. So here's what I did to resolve the issue:
- Shutdown the computer
- Boot into Recovery Mode --After BIOS load, hold down Shift key to access the grub menu --Once in grub menu, select the entry ending in "(recovery mode)"
- From the next menu selected option to enter Root Session
-
At the root session, execute the following command to remount the filesystem as read-write :
mount -o remount,rw /
Execute adduser command to add my userid back to the admin group. Command executed "adduser username admin" where I replaced username with my actual system username. This time I did not receive an error executing the command since the filesystem was mounted as read-write.
- Exit Root Session, exit recovery mode, and rebooted.
Once rebooted into Ubuntu, I could see that my userid was now listed as being a member of the admin group, by executing "Groups" command from the normal terminal session. I also verified the same in the GUI by going to "User Accounts" in the Ubuntu System Settings menu. There my userID was also listed as an "Administrator".
I went further to try to replicate my original issue to see if rebooting back to Recovery Mode and skipping Step #4 above (to remount the filesystem as read-write) would reproduce the "unable to lock /etc/passwd" error, and it did. The root cause of the issue had to do with how the filesystem was mounted in Recovery Mode.
It seems odd to me as a new user that booting into Recovery Mode would be read-only by default. Isn't that the idea of recovery, that you would need to make some changes to correct update files, correct issues that would otherwise not be possible as a normal user?
Anyway, I'm just happy to now have at least one user on the computer with Administrator access. Thanks again to all who responded to my issue.
Solution 2:
You can try to make the /etc/.pwd.lock
file empty (nano /etc/.pwd.lock
and delete everything) if it is not and use adduser your_user admin
from the root session to insert your user back in admin group. This file is to control access to /etc/passwd
and /etc/shadow
files avoiding simultaneous modifications. It should be empty if none of the files are being modified.