Raspberry pi comes with a default user account that is added to multiple groups:
username@hostname:~ $ groups pi
pi : pi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio
I'd like to script adding a new primary user with the same group membership as the default. I think this would also be practical for adding new admins to any Unix/Linux system. Windows has the functionality from ADUC by Copying an existing account.
I believe the script will need to:
- Use a loop
- Prompt for existing username (eu) input
- Store the existing user's current groups as a variable (eg) -
groups
- Prompt for new username (nu) input
- Add the new user with the existing user's groups -
useradd
I presume this will work to also gain sudo permission, based on ændrük's answer to a similar question. Another similar question is Rahul's about adding a list of users to multiple groups.