0

I have a user that I created via the pw utility on FreeBSD. The full command I used was:

pw add user example -s /usr/local/scripts/example.sh -w none

The user can login as example without requiring a password which will run the example script. Once the script is done running the user will be automatically logged out.

I want to duplicate this user, but I'm looking into a way of doing it without requiring a utility. For example, I looked into modifying the /etc/passwd file, but it doesn't look like that worked. The reason I say it didn't work is because it prompts me for a password and of course I don't have one for this user I tried to add.

Is what I'm after possible? Do I absolutely have to use utilities such as pw?

Just a quick edit. Perhaps the only thing I'm missing is setting the user to not require a password. My edit of /etc/passwd could be correct, and all I require would be to somehow set this new user to not require a password.

  • what do you mean with duplicate? Also you cannot only edit the /etc/passwd, because there are more file related to a user – demonking Dec 10 '15 at 15:47
  • @demonking: By duplicate, I mean create an identical user, besides the username. The user I created is a simple user that just runs a script upon login. No password. What other files do I need to edit besides the /etc/passwd file? That's essentially what I'm looking for. – quickblueblur Dec 10 '15 at 16:02
4

You're editing the wrong file, and you're not actually modifying the system accounts database, which is why you aren't seeing any modifications.

This is not Linux. The master source file for the accounts database is /etc/master.passwd. /etc/passwd is a Version 7 Unix compatibility file, a subordinate file generated from the source. The actual system accounts database that is consulted by applications wanting to look stuff up is a pair of Berkeley DB files, also generated from the source file by pwd_mkdb.

vipw runs pwd_mkdb automatically. If you hand-edit /etc/master.passwd, you must (carefully) run pwd_mkdb yourself.

If you hand-edit /etc/passwd your changes will be lost the next time that pwd_mkdb gets run and will not be seen by applications anyway.

  • That's exactly what I needed to do; hand modify master.passwd and run pwd_mkdb. This works perfectly and answers the original question. I will mark this as the accepted answer. – quickblueblur Dec 10 '15 at 16:54
2

If you want to edit the passwd(5) file, use vipw(8). The file /etc/passwd is just a shadow file.

To set the password to empty, simply remove the second parameter (between two : characters). For example, if root had an empty password, vipw would show you something like this:

  root::0:0::0:0:Charlie &:/root:/bin/csh

The real username and password database is located in /etc/pwd.db. See pwd_mkdb(8) for more details.

  • I'm looking for a way of editing without using a utility. vipw will add a user, but I'm looking for a way without using a utility. I had a quick go using vipw. I notice that it modifies the /etc/passwd file and the /etc/master.passwd file. If I delete the user from these files manually, I can still login with the user I created. So it seems that vipw modifies more than just those 2 files. – quickblueblur Dec 10 '15 at 16:20
  • @quickblueblur The other file is /etc/pwd.db. Which is the real username and password database. – Richard Smith Dec 10 '15 at 16:23
  • Thank you! That was handy information. If I hand edit the /etc/passwd file and the /etc/master.passwd file and run the following command pwd_mkdb -p /etc/master.passwd I am able to create the user and login successfully. If you would like to edit your answer to include the information about /etc/pwd.db I can accept the answer. – quickblueblur Dec 10 '15 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.