Published Book on Amazon
|  | All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1 | 
|  | All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2 | 
출판된 한글판 도서
|  | 최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상) | 
|  | 최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하) | 
Original Book Contents
12.7.7 Assignment of User Account to User Group
12.7.7.1 Review of Processing Method
If a user account is assigned to a user group, that user inherits all the responsibilities and privileges that the group has. Also, when a certain user group is given a certain responsibility and privilege, all users belonging to that user group are given the same responsibility and privilege.
A particular user account always belongs to the primary group, and can belong to one or more other user groups at the same time. There are many ways to assign a user account to a user group. You can specify a user group at the same time you create a user account, or you can assign a user group as a separate task after creating a user account.
In this case, try to use the "adduser" command to specify how to assign the user group separately.
12.7.7.2 Assigning User Group with "adduser" Command
[Command Format]
| adduser [options] user group | 
[Command Overview]
■ This defines a new user account or assigns a user group to an existing user account.
■ User privilege -- Super user.
[Detail Description]
■ None
[Main Option]
| --group 
 | When combined with --system, a group with the same name and ID as the system user is created. If not combined with --system, a group with the given name is created. This is the default action if the program is invoked as addgroup. | 
| --system | Create a system user or group. | 
| 
 | 
 | 
[Files]
| /etc/group | Group account information. | 
| /etc/gshadow | Secure group account information. | 
[Used Example]
You want to assign the user "guser001" to the new group "ggroup001". If you look in the "/etc/passwd" file before doing the work, you can see that the user "guser001" is created. Also, in the "/etc/group" file, the user group "guser001" is given an id of "1004" and the same id is specified in the user "guser001" in "/etc/passwd" file.
Also, when you look up the "/etc/group" file, you can see that the user group "ggroup001" is created.
| pi@raspberrypi ~ $ sudo cat /etc/passwd | 
| root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/bin/sh ~~~~~ guser001:x:1001:1004:General User 001,,,:/home/guser001:/bin/bash guser002:x:1002:1005:General User 002,,,:/home/guser002:/bin/bash | 
| pi@raspberrypi ~ $ sudo cat /etc/group | 
| root:x:0: daemon:x:1: ~~~~~ guser001:x:1004: guser002:x:1005: ggroup001:x:1006: ggroup002:x:1007: | 
To assign the group "ggroup001" to the user account "guser001", perform the following operations.
| pi@raspberrypi ~ $ sudo adduser guser001 ggroup001 | 
When the operation is complete, check the data in the "/etc/group" file to see the results of the operation. It can be confirmed that the contents of the corresponding user are changed as follows.
| pi@raspberrypi ~ $ sudo cat /etc/group | 
| root:x:0: daemon:x:1: ~~~~~ guser001:x:1004: guser002:x:1005: ggroup001:x:1006:guser001 ggroup002:x:1007: |