How to create a new user with all privileges of the current user in Linux terminal?

3

It is known that useradd is used to add new user accounts.

useradd newuser

The -G flag is used to add groups for respective privileges. Is there a simpler way to create a user will all privileges of a specific existing user?

Ébe Isaac

Posted 2016-07-30T17:12:19.207

Reputation: 141

Answers

2

There may be a cleaner way to do this, but if I understand correctly, this should work:

useradd -G $(groups | tr ' ' ',') newuser

groups gives you a list of the groups the current user (or a different user if specified) belongs to, seperated by spaces. tr converts the spaces to commas, since that is what useradd expects.

Brian

Posted 2016-07-30T17:12:19.207

Reputation: 56

Note that this doesn't necessarily place the user in the same "initial login group" as the current user. – agtoever – 2016-07-30T18:45:05.963