Computer >> 컴퓨터 >  >> 프로그램 작성 >> BASH 프로그래밍

Linux에서 그룹에 사용자를 추가하는 방법(예제 포함)

이 자습서에서는 그룹에 사용자를 추가하는 방법을 살펴보겠습니다. Bash 셸 명령은 특정 요구 사항을 달성하기 위한 강력한 도구입니다. 그룹은 정보를 공유하고 보호하는 효과적인 방법입니다. Linux의 파일 권한을 사용하면 사용자 권한, 그룹 권한 및 전역으로 소유권을 설정할 수 있습니다. 또한 루트에 대한 사용자 권한을 유지하는 완벽한 방법입니다.

자세히 알아보겠습니다.

그룹으로 사용자 추가(휠)

새 관리자를 등록했으며 파일 서버의 관리자로 지정해야 합니다. useradd 명령은 사용자를 추가하기 위한 간단하고 강력한 도구입니다. 사용자를 추가하고 그룹에 할당할 수 있습니다.
NAME
       useradd - create a new user or update default new user information

SYNOPSIS
       useradd [options] LOGIN

이것이 useradd 매뉴얼 페이지의 기본 사항이므로 새로운 사용자인 Admin Bob과 Admin Jane을 추가하여 처음부터 시작하겠습니다.

luseradd의 일반 옵션

-c, --comment COMMENT
-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]

이것이 우리의 두 가지 기본 분야입니다. 이제 Bob을 추가해 보겠습니다.

[admin@wsxdn.com ec2-user]# useradd -c "USA/CO/Denver Office" Admin.Bob

그리고 Jane을 추가해 보겠습니다.

[admin@wsxdn.com ec2-user]# useradd -c "USA/CO/Denver Office" Admin.Jane -G wheel
이제 Bob이 관리자이고 관리 권한이 필요하다는 것을 알고 있습니다. 그러나 때로는 알지 못하거나 단순히 잊어 버렸을 수도 있습니다. 따라서 나중에 그에게 그룹을 추가해야 합니다. Jane은 이미 휠에 추가되었습니다. 휠 그룹은 대부분의 Linux 시스템에 포함된 그룹입니다. 권한 상승을 허용하는 기본 그룹입니다.
[admin@wsxdn.com ec2-user]$ sudo su

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for Admin.Jane: 
Sorry, try again.

잊혀진 단계에 대해 이야기합니다. 비밀번호 설정을 잊은 것 같습니다. useradd 명령으로 암호를 설정하는 것은 권장하지 않습니다. 대신, passwd 명령으로 후속 조치를 취하는 것을 잊지 마십시오. Passwd는 기록에 저장되지 않는 보안 터미널로 프롬프트합니다. 또는 read -sp를 사용하여 비밀번호를 인라인으로 저장할 수 있습니다.

[admin@wsxdn.com ec2-user]# passwd Admin.Jane
Changing password for user Admin.Jane.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
[admin@wsxdn.com ec2-user]# su Admin.Jane
[admin@wsxdn.com ec2-user]$ sudo su

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for Admin.Jane: 
[admin@wsxdn.com ec2-user]#

그리고 우리는 간다. 한 명의 사용자가 그룹, wheel에 추가되었습니다. 그룹 명령이 필요하지 않습니다. 처음에 Jane을 여러 그룹에 추가해야 하는 경우:

[admin@wsxdn.com ec2-user]# useradd Admin.Jane -G wheel,ec2-users
[admin@wsxdn.com ec2-user]# passwd Admin.Jane
[admin@wsxdn.com ec2-user]# su Admin.Jane
[admin@wsxdn.com ec2-user]$ groups
Admin.Jane wheel ec2-users
[admin@wsxdn.com ec2-user]$

그리고 우리는 간다. Admin.Jane은 자신의 사용자 그룹, sudo 액세스를 위한 wheel 및 ec2-users 그룹에 속합니다.

하지만 밥은? Bob은 wheel에 대한 그룹 액세스 권한 없이 생성되었으므로 다른 명령을 사용해야 합니다.

그룹에 사용자 추가

관리자 권한이 없는 관리자로 Bob을 추가했습니다. groupmem으로 해결해 봅시다.

groupmem에 대한 공통 옵션

SYNOPSIS
       groupmems -a user_name | -d user_name | [-g group_name] | -l | -p

OPTIONS
       The options which apply to the groupmems command are:

       -a, --add user_name
           Add an user to the group membership list.

           If the /etc/gshadow file exist, and the group has no entry in the /etc/gshadow file, a new entry will be created.

       -d, --delete user_name
           Delete a user from the group membership list.

           If the /etc/gshadow file exist, the user will be removed from the list of members and administrators of the group.

           If the /etc/gshadow file exist, and the group has no entry in the /etc/gshadow file, a new entry will be created.

       -g, --group group_name
           The superuser can specify which group membership list to modify.

       -h, --help
           Display help message and exit.

       -l, --list
           List the group membership list.

먼저 그룹의 구성원 목록을 가져오는 것부터 시작하겠습니다.

[admin@wsxdn.com ec2-user]# getent group wheel
wheel:x:10:ec2-user,samberry,Admin.Steve,Admin.Jane

우리는 Bob이 거기에 없다는 것을 압니다. 밥을 추가해 보겠습니다.

[admin@wsxdn.com ec2-user]# groupmems -a Admin.Bob -g wheel
[admin@wsxdn.com ec2-user]# groupmems -g wheel -l
ec2-user  samberry  Admin.Steve  Admin.Jane  Admin.Bob

우리는 거기에 갈. Admin.Bob은 이제 wheel의 구성원이며 groupmems -l, –list, 옵션으로 확인하여 확인했습니다.

이것이 Linux에서 그룹 관리의 기본입니다. Linux의 홈 인스턴스의 경우 기본 그룹이 wheel 대신 adm으로 표시될 것입니다.

admin@wsxdn.com:/home/samuelberry# groupmems -g adm -l
syslog  samuelberry

궁금한 점이 있으면 /etc/sudoers 구성 파일에서 어떤 파일이 있는지 확인하세요.

admin@wsxdn.com:/home/samuelberry# cat /etc/sudoers
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo	ALL=(ALL:ALL) ALL

[admin@wsxdn.com ec2-user]$ cat /etc/sudoers
## Allows people in group wheel to run all commands
%wheelALL=(ALL)ALL

## Same thing without a password
# %wheelALL=(ALL)NOPASSWD: ALL

사용자를 EC2 인스턴스에 추가했음을 눈치채셨을 것입니다. 다음 주에는 사용자/그룹 관리의 일환으로 EC2를 통해 Linux 인스턴스에 사용자를 추가하는 방법을 안내해 드리겠습니다.