4

UNIX users are usually managed in the well-known passwd file format. The corresponding file usually resides at /etc/passwd.

Since editing this file by hand is very inconvenient (mostly because of the encrypted passwords), there are tools to edit it, like useradd (and its wrapper adduser), and passwd, which make editing these files very easy.

The format is in fact so practical, that system users aren't the only users which are kept in this format, but other services like dovecot also offer functionality to read users from such a file.

You would think that this is very convenient, as you can use the same set of tools for managing the users of a whole range of services. However, the tools mentioned above seem to be hardwired to work to work on /etc/passwd (and etc/shadow if it's in use).

Now I would be surprised, if there isn't a convenient way to edit passwd files, other than /etc/passwd, but I couldn't find any. How can I do that on a Debian Linux/GNU system?

My concrete problem is, that I want to create a password file for dovecot, according the the format documented here. The most problematic thing is getting the encrypted passwords into it.

2
  • Keep in mind that local password files are not the only way Unix systems can authenticate users (NIS, LDAP, etc).
    – Jeff Schaller
    Commented Nov 16, 2015 at 20:50
  • Proftpd uses passwd format and has a tool to manage that file, see proftpd.org/docs/contrib/ftpasswd.html
    – Tom Bille
    Commented Jun 3, 2020 at 16:46

1 Answer 1

2

Actually the official program to edit passwd and shadow entries is vipw.

There are htpasswd files for password files for web sites, which have a simplified format. If you are thinking of an example of other type of password files.

Besides that, the only alternatives that comes to my mind that may do something similar to what you propose are chroot / jails / VServers /containers. Or recompiling the needed utils with a different file path.

At the end of the day the format is not so complicated, and you can write scripts for that, albeit I do recommend testing them beforehand in mock files. The probability of messing up is big, and these files are important for the integrity of the system.

As for your last question, install and use the command makepasswd:

makepasswd --crypt-md5 --chars=10

makepasswd besides generating random passwords, can also create encrypted passwords from clear text ones.

4
  • I already stumbled across htpasswd, but AFAIK it uses a simpler syntax than /etc/passwd.
    – Kritzefitz
    Commented Nov 16, 2015 at 20:46
  • I just edited the answer to improve it. Commented Nov 16, 2015 at 20:47
  • Sure I can write a script to do it, but I thought that, since editing such files for services like dovecot is so common, that there already is a finished solution for that.
    – Kritzefitz
    Commented Nov 16, 2015 at 20:51
  • I would prefer to use MySQL then text files for users. Commented Nov 16, 2015 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .