Solved: cannot lock /etc/passwd; try again later

Published 19 June 2018
Last updated 22 June 2022
An older guide that hasn't been re-checked yet, so commands or versions may have moved on.
How guides are made and checked
I encountered a “cannot lock /etc/passwd; try again later” issue whilst trying to create a new user on my Ubuntu 18.x server.
The root cause eludes me, but I did find that the following helped to resolve the issue.
Step 1 - Remount the file system
Remount the file system in read-write (rw) mode:
- sudo mount -o rw,remount /
Step 2 - Remove lock files
Under the /etc folder remove any of the following files: passwd, shadow, group and gshadow -.lock.
- sudo rm -rvf /etc/passwd.lock /etc/shadow.lock /etc/group.lock /etc/gshadow.lock
Now, lets go add that user!