Create a Group on Linux

Hi, I would like to know if there is something in the standard library to generate group or user in Linux System ? I didn’t found in the documentation

There is some very simple APIs for this in the stdlib. What APIs are you looking for?

https://crystal-lang.org/api/1.7.2/System/Group.html
https://crystal-lang.org/api/1.7.2/System/User.html

I saw that yet, thank you. But it’s only to get the group name or the group id, not to generate new one

The group records of /etc/group consists of a group_name:password:GroupID:user_list
The password is always ‘x’
The GID is a unique number, most of the times the one of the previous record increased by 1, but it would be good to check the existing numbers.
So it would be simple to add to your code when no API can be found.
Or simply call /usr/sbin/useradd if available.

2 Likes