3. MANAGING USERS AND GROUPS (사용자와 그룹에 대한 관리)


User 는 실질적으로 사용하는 사용자와 연결된 계정, 특정 응용 프로그램이 사용하기 위해 사용되는 계정이 될수 있다. 

Group 은 논리적으로 공통의 목적을 가진 사용자들을 연결, Group 내의 사용자는 해당 Group 이 소유한 파일을 읽거나 쓰거나 실행할수 있는 동일한 권한을 가짐


User 는 User ID 라 하는 "UID" 고유한 식별 번호를 가짐

Group 은 Group ID 라 하는 "GID" 고유한 식별 번호를 가짐

User 가 파일을 생성하게 되면 User 는 해당 파일에 대한 소유자 이며, Group 소유자 이기도함, 파일에는 User, Group, 다른 모든사용자에 대해 읽기, 쓰기, 실행 권한이 할당이 됨, 파일 소유자는 변경이 가능하며, root access 권한은 root 사용자와 파일 소유자 모두 변경이 가능

RHEL 은 파일 및 디렉토리에 대한 ACL 을 지원


RESERVED USER AND GROUP IDS


RHEL 은 User 및 Group ID 에 대해 1000번 이하의 값을 예약 해놨다.

User Manager 는 system user 를 보여주지 않음

예약된 User 와 Group을 보려면 아래의 명령어로 가능하다.


cat /usr/share/doc/setup*/uidgid


앞으로도 RHEL 에서 예약된 User 와 Group이 증가할수 있음으로 일반 User 및 Group ID 값으르 5000 이상으로 할당하는것을 권장함

/etc/login.defs 파일에서 수정이 가능함


[file contents truncated]
UID_MIN                  5000
[file contents truncated]
GID_MIN                  5000
[file contents truncated]

위의 파일에서 Default 로는 1000 으로 되어 있다. 


위의 설정을 5000 이상으로 하였다 하더라도, 혹시 모를 충돌을 대비해서 system user 에 대한값을 1000 으로 제한을 거는게 좋다. 


User Private Groups


RHEL 은 UNIX Group을 좀 더 쉽게 관리하기 위해 UPG (User Private Group) 체계를 사용

파일과 디렉토리를 새로 생성하는경우 umask 설정이 적용됨 /etc/bashrc 에 설정되어 있음, UNIX-based system에서는 umask 는 022 로 세팅되어 있다.

UPG 를 사용하게되면 모든 사용자가 자신의 개인 Group 을 가지고 있다. 


Shadow Passwords


여러명의 사용자가 있는 환경에서는 shadow-utils 패키지가 제공하는 shadow passwords 를 이용해서 시스템 인증 파일을 보호할수 있다. 

기본 설치 프로그램은 Default 로 shadow passwords 를 활성화 함


- /etc/passwd 파일을 /etc/shadow 로 암호화를 하며 해당 파일은 root user 만 읽기 가능함

- shadow password 는 password 에 대한 정보를 저장함

- shadow password 를 사용하면, /etc/login.defs 에 설정된 보안정책을 적용할수 있다. 

shadow-utils 패키지가 제공하는 유틸리티는 shadow password 사용여부와 관계없이 제대로 동작함, 하지만 암호 aging 정보는 /etc/shadow file 에만 저장됨으로 shadow password 를 먼저 활성화 하지 않으면 일부 util 및 command 가 작동하지 않음

- "chage" 은 password-aging parameters 를 설정하는 utility 이다.

- "gpasswd" 는 /etc/group file 을 관리하는 utility 이다.



USING COMMAND-LINE TOOLS


UtilitiesDescription
idDisplays user and group IDs.
useraddusermoduserdelStandard utilities for adding, modifying, and deleting user accounts.
groupaddgroupmodgroupdelStandard utilities for adding, modifying, and deleting groups.
gpasswdUtility primarily used for modification of group password in the /etc/gshadow file which is used by the newgrp command.
pwckgrpckUtilities that can be used for verification of the password, group, and associated shadow files.
pwconvpwunconvUtilities that can be used for the conversion of passwords to shadow passwords, or back from shadow passwords to standard passwords.
grpconvgrpunconvSimilar to the previous, these utilities can be used for conversion of shadowed information for group accounts.


Adding a New User


system 의 신규 user 를 만들때 사용하는 shell prompt


useradd [options] username

useradd 명령어로 유저를 만들면 기본적으로 계정이 잠겨저 있다. 계정을 활성화 하려면 passwd 명령어를 사용해야한다.


passwd username

password aging policy 관련 세팅도 가능하다. 


OptionDescription
-c 'comment'comment can be replaced with any string. This option is generally used to specify the full name of a user.
-d home_directoryHome directory to be used instead of default /home/username/.
-e dateDate for the account to be disabled in the format YYYY-MM-DD.
-f daysNumber of days after the password expires until the account is disabled. If 0is specified, the account is disabled immediately after the password expires. If -1 is specified, the account is not disabled after the password expires.
-g group_nameGroup name or group number for the user's default (primary) group. The group must exist prior to being specified here.
-G group_listList of additional (supplementary, other than default) group names or group numbers, separated by commas, of which the user is a member. The groups must exist prior to being specified here.
-mCreate the home directory if it does not exist.
-MDo not create the home directory.
-NDo not create a user private group for the user.
-p passwordThe password encrypted with crypt.
-rCreate a system account with a UID less than 1000 and without a home directory.
-sUser's login shell, which defaults to /bin/bash.
-u uidUser ID for the user, which must be unique and greater than 999.

RHEL 7 일반 사용자의 기본 ID 범위가 이전 릴리즈에서 변경이 되었다. (1~499 -> 1~999) RHEL 6 에서 500~999 까지의 사용자가 있다면 RHEL 7 로 마이그레이션 할때에 문제가 발생할수 있음


EXPLAINING THE PROCESS


"useradd juan" 에 대한 설명


- /etc/passwd 파일에 juan 관련 한줄이 생성됨


juan:x:1001:1001::/home/juan:/bin/bash
user name 은 juan
"x" 는 password field 이며, shadow passwords 로 보호
UID 는 1001 로 생성
GID 는 1001 로 생성
GECOS 필드는 빈공간으로 생성, GECOS 필드는 성명이나 전화번호와 같은 사용자에 관한 추가 정보를 기입하는데 사용가능
HOME 디렉토리는 "/home/juan"
Default shell 은 "/bin/bash "

- /etc/shadow 파일에 juan 관련 한줄이 생성됨

juan:!!:14798:0:99999:7:::

username 은 juan

!! marks 가 되며 계정을 잠금

password 가 만료되지 않도록 세팅됨


- /etc/group 파일에 juan 관련 한줄이 생성됨


juan:x:1001:

group 이름은 juan

"x" 는 password 가 shadow group passwords 를 통해 암호화 되있다는것을 표시

GID 는 /etc/password 에 기록된것과 동일


- /etc/gshadow 파일에 juan 관련 한줄이 생성됨


juan:!::

group 이름은 juan

! mark 는 group 이 잠겨 있음을 표시


- /home 디렉토리에 juan 유저 디렉토리가 생성


~]# ls -ld /home/juan
drwx------. 4 juan juan 4096 Mar  3 18:23 /home/juan

이 디렉토리는 juan 이 소유함, 다른 모든 사용자의 권한은 거부


- /etc/skel/ 디렉토리 내의 파일이 /home/juan/ 디렉토리에 복사됨


~] # ls -la /home/juan
총 28
drwx ------. 4 juan juan 4096 Mar 3 18:23.
drwxr-xr-x. 5 뿌리 4096 3 월 3 일 18:23 ..
-rw-r-r--. 1 juan juan 18 Jun 22 2010 .bash_logout
-rw-r-r--. 1 juan juan 176 6 월 22 2010 .bash_profile
-rw-r-r--. 1 juan juan 124 6 월 22 2010 .bashrc
drwxr-xr-x. 4 juan juan 4096 Nov 23 15:09 .mozilla

juan 계정은 잠긴상태가 됨, Passwd 명령을 사용해서 계정에 암호를 설정하고, 암호 aging 을 설정해야함



Adding a New Group


groupadd [options] group_name
OptionDescription
-f--forceWhen used with -g gid and gid already exists, groupadd will choose another unique gid for the group.
-g gidGroup ID for the group, which must be unique and greater than 999.
-K--key key=valueOverride /etc/login.defs defaults.
-o--non-uniqueAllows creating groups with duplicate GID.
-p--password passwordUse this encrypted password for the new group.
-rCreate a system group with a GID less than 1000.

Creating Group Directories


특정 그룹의 사용자는 /opt/myproject/ 디렉토리의 파일에 대해 작업이 필요함, 일부 사람들은 이 디렉토리의 내용을 수정할수 있지만, 모든 사람이 수정하면 안됨


/opt/myproject 디렉토리 생성


mkdir /opt/myproject

myproject 그룹을 시스템에 추가


groupadd myproject
/opt/myproject/ 디렉토리를 myproject Group 권한 설정


chown root:myproject /opt/myproject
Group 의 사용자가 디렉토리내에 파일으르 생성하고 setgid bit 를 설정하도록 허용


chmod 2775 /opt/myproject
지금 시점에서는 myproject Group 의 모든 구성원은 /opt/myproject 에 관리자가 파일사용 권한을 변경하지 않아도 디렉토리에 파일을  만들거나 편집이 가능하다. 사용권한이 올바른지 확인하려면 아래의 명령을 실행

~] # ls -ld /opt/myproject
drwxrwsr-x. 3 루트 myproject 4096 3 월 18:31 / opt / myproject

myproject Group 에 사용자 추가


usermod -aG myproject username


Setting Default Permissions for New Files Using umask


파일을 새로 생성하게 되면 -rw-rw-r--.  권한을 가지게 된다. 이런 초기 파일 권한은 umask 를 통해서 결정이 된다. 

모든 프로세스는 고유한 umask 를 가지고 있다. 예를 들면 bash 는 기본적으로 0022 umask를 가지고 있다. umask 를 변경이 가능하다. 




WHAT UMASK CONSISTS 



표준파일 권한에 맞는 bit로 구성이됨



0 = 아무런 의미없음 umask 는 특수효과를 주진 않는다.

1 = owner 권한에 대한 실행 bit

3 = Group 권한에 대한 실행 및 쓰기 bit

7 = 모든 사용자에 대한 실행, 쓰기, 읽기 bit



umask 는 2진수, 8진수, 기호식으료 표현이 가능, 8진수 0137은 u=rw-,g=r--,o=--- 동일함 기호표기는 8진법의 반대임, 8진법은 금지, 기호표기는 허용된 권한을 표기



HOW UMASK WORKS


umask 는 파일에 대한 권한 설정을 금지

umask 에 비트가 설정되면 파일에서 설정이 해지됨

umask 에 비트가 설정되어 있지 않으면 다른 요소에 따라 파일에 비트를 설정할 수 있음



파일 생성시 umask 의 적용


파일을 만들 때 umask 적용



보안상의 이유로 인해서 일반 파일은 기본적으로 실행 권한을 가지면 안됨

umask 가 0000 권한을 금지하지 않는 경우라도 새로운 파일에는 여전히 실행권한이 생성안됨, 하지만 실행권한을 가진 디렉토리는 생성가능


[john@server tmp]$ umask 0000
[john@server tmp]$ touch file
[john@server tmp]$ mkdir directory
[john@server tmp]$ ls -lh .
total 0
drwxrwxrwx. 2 john john 40 Nov  2 13:17 directory
-rw-rw-rw-. 1 john john  0 Nov  2 13:17 file


MANAGING UMASK IN SHELLS


umask 확인


~]$ umask
0022

umask 를 기호로 확인


~]$ umask -S
u=rwx,g=rx,o=rx


shell session 에 대해 umask 적용, 0000 의 4자리 숫자 이하로 설정하면 맨 앞설정은 0 으로 설정


~]$ umask octal_mask
ex. 새 파일의 소유자 및 그룹에 대해 쓰기 및 실행 권한을 가지지 못하게 하고 다른 사람에게 권한을 부여하는것을 금지하는 설정

~] $ umask 0337
~] $ umask 337
~] $ umask -S symbolic_mask


기호를 사용해서 umask 설정


0337 을 기호식으로 umask 설정


~] $ umask -S u=r,g=r,o=


WORKING WITH THE DEFAULT SHELL 


bash shell 에서 설정을 하려면 /etc/bashrc 에서 설정하면 됨


~]$ grep -i -B 1 umask /etc/bashrc

umask 022 사용하는 예제


~]$ grep -i -B 1 umask /etc/bashrc
    # By default, we want umask to get set. This sets it for non-login shell.
--
    if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
       umask 002
    else
       umask 022

/etc/bashrc 에서 수정작업 진행 Default umask bash 를 변경하는경우 umask 명령 호출 혹은 UMASK 변수를 변경

Default umask를 0227로 변경


    if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
       umask 002
    else
       umask 227


WORKING WITH THE DEFAULT SHELL UMASK OF A SPECIFIC USER


특정 사용자에 대해서 umask값을 변경하려면 $HOME/.bashrc 에 설정을 하면됨

john 사용자의 umask 를 0227 로 변경하는 예제임


john@server ~]$ echo 'umask 227' >> /home/john/.bashrc


SETTING DEFAULT PERMISSIONS FOR NEWLY CREATED HOME DIRECTORIES


/etc/login.defs 파일을 수정


# The permission mask is initialized to this value. If not specified,
# the permission mask will be initialized to 022.
UMASK 077
























'Linux > Redhat 7 system administrator's guide' 카테고리의 다른 글

8. YUM  (0) 2017.08.01
5. GAINING PRIVILEGES  (0) 2017.07.14
4. ACCESS CONTROL LISTS  (0) 2017.07.11
2. CONFIGURING THE DATE AND TIME  (0) 2017.03.16
1. system locale and keyboard configuration  (0) 2017.03.16

+ Recent posts