On Debian/Ubuntu systems I can use the following line to create a user and group named "dv" just for usage on a daemon service (systemd). No SSH login, no password, no home directory etc:

adduser --system --no-create-home --group dv

I realized that this does not work on Suse and RedHat/CentOS distributions (and many more). As this should be a helping bash script for installation, I need the above in a cross distro way. I found that useradd command is available on all these distros. But how to get the same result on all of them?

Is there a generic way of calling useradd to gain the same as with the above adduser command? Or do I need to have some if/then/else constructs to support them? Maybe there is already some working example somewhere?

  • This command will work on RHEL/Fedora systems if you change --group to --gid Apr 6, 2021 at 8:10
  • Thanks @ArtemS.Tashkinov, I just tried on CentOS and it seem to work. Still looking for Suse options...
    – Kukulkan
    Apr 7, 2021 at 9:28

1 Answer 1


Short answer - not really, but there are possibilities.

Low-level commands like are often distribution-specific. There's no generic way of calling useradd (or adduser) specifically in a cross-platform way, but there is the potential of using an Ansible playbook to create a generic way of adding a user to a given distribution. You will have to ensure that the prerequisites for running an Ansible playbook are available on the distro you're working on, but in most cases that should be trivial, if not included as part of the default install.

  • Thanks, but I think I will try to use a distro switch in my installation shell script.
    – Kukulkan
    Apr 7, 2021 at 9:58

You must log in to answer this question.

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