Making a User Live on Debian GNU / Linux

I am currently working on a Debian package for my own program. As part of this package, I need to create a user who performs most of the functions of the program. I do this in a postinst script. A Postinst script can be executed several times (for example, when updating), so it is important to ensure that I will not try to create a user each time.

So, how can I make sure that the user is created only the first time the script is executed, without affecting it the next time the script runs?

+3
source share
3 answers

Try:

[aiden@dev ~]$ id aiden
uid=500(aiden) gid=500(aiden) groups=500(aiden)
[aiden@dev ~]$ id foomonkey
id: foomonkey: No such user
[aiden@dev ~]$ 

The first $?is 0, the second is 1.

+9

, . adduser (8) , . man:

EXIT VALUES
       0      The  user  exists as specified. This can have 2 causes: The user
              was created by adduser or the user was already  present  on  the
              system  before  adduser  was  invoked. Invoking adduser a second
              time with the same parameters as before also returns 0.
+2

as mentioned before you can use the id command if you want the whole user on the system you can use:

getent passwd

in which all users of the system will be listed (even if they are in a remote database, such as ldap or nis, etc.)

+1
source

Source: https://habr.com/ru/post/1715882/


All Articles