container-xrdp icon indicating copy to clipboard operation
container-xrdp copied to clipboard

userlist / uid

Open toastie89 opened this issue 1 year ago • 3 comments

Adding the username, password and sudo as argument is simple and very convenient.

Still, for more complicated setups, I would wish to define users and passwords as a list. Further, in my case, predefined UIDs are important to ensure access to shared volumes.

Would you accept a PR to run this script (link) when /etc/users.list exists and go for the existing solution, with the arguments, in case the file is missing?

toastie89 avatar Feb 28 '23 15:02 toastie89

It is a good idea, but all containers must be zero-config for all users. The additional config can be added if someone wants more functionality. It looks only need to add this test:

test -f /etc/users.list || exit 0

Can you attach an example for user.list?

danchitnis avatar Feb 28 '23 20:02 danchitnis

The users.list has the following format: id username password-hash list-of-supplemental-groups E.g.: 1005 johndoe $1$6kLbPAuX$Wzw7rZNFedew3RLRCiXJb0 sudo

The following part would need to be added to your entrypoint script:

test -f /etc/users.list && {

while read id username hash groups; do
        # Skip, if user already exists
        grep ^$username /etc/passwd && continue
        # Create group
        addgroup --gid $id $username
        # Create user
        useradd -m -u $id -s /bin/bash -g $username $username
        # Set password
        echo "$username:$hash" | /usr/sbin/chpasswd -e
        # Add supplemental groups
        if [ $groups ]; then
                usermod -aG $groups $username
        fi
done < /etc/users.list
}

test -f /etc/users.list || {
# your user creation code
}

toastie89 avatar Mar 02 '23 11:03 toastie89

Sound good. Feel free to do a PR, and I will test it.

danchitnis avatar Mar 03 '23 22:03 danchitnis