보안 루피

리눅스 마스터 1급 실기 : 사용자 관리 개념 정리 본문

리눅스 마스터 1급

리눅스 마스터 1급 실기 : 사용자 관리 개념 정리

잔망 루피 2023. 5. 2. 22:37

사용자 ( /etc/passwd )

 

비밀번호  ( /etc/shadow )

 

뼈대 ( /etc/skel )   :  /etc/skel 안에있는 파일들이 사용자 생성시 복사가된다.

useradd -D 하면 나오는 내용 

  • 홈디렉터리 변경, 쉘 등을 변경할 수 있다.
[root@localhost ~]# cat /etc/default/useradd

# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

 

" 그룹 생성시"  , "사용자 생성시" ( /etc/ login.defs)

특정 유저 생성시면 명령어를 이용한 옵션을 따로 준다. 

 

 

 

 

 

 

/etc/gshadow

 

 

  • 이 /etc/passwd        /etc/shadow 파일 검사 명령어          pwck   (password cheak)
  • /etc/shadow 파일 생성 명령어                                         pwconv   ( password conv)

useradd

더보기

Options:
  -b, --base-dir BASE_DIR       base directory for the home directory of the           #skel 파일 홈디렉 수정
                                new account
  -c, --comment COMMENT         GECOS field of the new account                   
  -d, --home-dir HOME_DIR       home directory of the new account                       #홈디렉터리 설정
  -D, --defaults                print or change default useradd configuration                   # skel 설정 값 출력 
  -e, --expiredate EXPIRE_DATE  expiration date of the new account
  -f, --inactive INACTIVE       password inactivity period of the new account
  -g, --gid GROUP               name or ID of the primary group of the new                #group 설정
                                account
  -G, --groups GROUPS           list of supplementary groups of the new                #group 추가
                                account  
  -h, --help                    display this help message and exit
  -k, --skel SKEL_DIR           use this alternative skeleton directory
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -l, --no-log-init             do not add the user to the lastlog and
                                faillog databases
  -m, --create-home             create the user's home directory
  -M, --no-create-home          do not create the user's home directory
  -N, --no-user-group           do not create a group with the same name as
                                the user
  -o, --non-unique              allow to create users with duplicate
                                (non-unique) UID
  -p, --password PASSWORD       encrypted password of the new account
  -r, --system                  create a system account
  -R, --root CHROOT_DIR         directory to chroot into
  -P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files
  -s, --shell SHELL             login shell of the new account
  -u, --uid UID                 user ID of the new account                                           #UID 지정
  -U, --user-group              create a group with the same name as the user         #사용자 이름과 같은 그룹 생성
  -Z, --selinux-user SEUSER     uㄴse a specific SEUSER for the SELinux user mapping

useradd -d : 홈디렉터리 설정

#useradd -D -b /home/insa

/etc/skel 값 변경

 

# useradd -e 2023-05-13 test1

생성할때 설정 값 같이변경

# usermod -e 2023-05-13 test1

이미 생성되어있는 계정 설정 값 변경

= 똑같은 명령이다.

 

usermod

더보기


Options:
  -c, --comment COMMENT         new value of the GECOS field
  -d, --home HOME_DIR           new home directory for the user account                 #홈디렉 변경
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE     # 계정 만기일 지정
  -f, --inactive INACTIVE       set password inactive after expiration                          # 패스워드 만기 후 유예기간
                                to INACTIVE 

패스워드 만기일은 passwd (max , min) 설정에서 가능

 -g, --gid GROUP               force use GROUP as new primary group
  -G, --groups GROUPS           new list of supplementary GROUPS
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                the user from other groups
  -h, --help                    display this help message and exit
  -l, --login NEW_LOGIN         new value of the login name                                    #UID 랑 다른거임 이건 닉변
  -L, --lock                    lock the user account
  -m, --move-home               move contents of the home directory to the
                                new location (use only with -d)
  -o, --non-unique              allow using duplicate (non-unique) UID
  -p, --password PASSWORD       use encrypted password for the new password
  -R, --root CHROOT_DIR         directory to chroot into
  -P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files
  -s, --shell SHELL             new login shell for the user account
  -u, --uid UID                 new UID for the user account
  -U, --unlock                  unlock the user account
  -v, --add-subuids FIRST-LAST  add range of subordinate uids
  -V, --del-subuids FIRST-LAST  remove range of subordinate uids
  -w, --add-subgids FIRST-LAST  add range of subordinate gids
  -W, --del-subgids FIRST-LAST  remove range of subordinate gids
  -Z, --selinux-user SEUSER     new SELinux user mapping for the user account

chage : 사용자 패스워드 정보 관리 (passwd 랑 같이 기억)

일단 usermod -e ( 비밀번호 만기 날짜 )  와 -f ( 비밀번호 만기 후 ,유예기간) 와 겹침

 

더보기

Options:
  -d, --lastday LAST_DAY        set date of last password change to LAST_DAY            #패스워드 변경 날짜 수정
  -E, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE         # 계정 만기 날짜 수정
  -h, --help                    display this help message and exit
  -I, --inactive INACTIVE       set password inactive after expiration                               #패스워드 만료후 유예기간
                                to INACTIVE
  -l, --list                    show account aging information
  -m, --mindays MIN_DAYS        set minimum number of days before password            # 비번 바꾸는 최소날짜
                                change to MIN_DAYS
  -M, --maxdays MAX_DAYS        set maximum number of days before password         # 비번 변경 더이상 못미뤄
                                change to MAX_DAYS
  -R, --root CHROOT_DIR         directory to chroot into
  -W, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS          #패스워드 만기 며칠전부터 경고 보낼건지

chage   -l   사용자 

더보기
마지막으로 암호를 바꾼 날                                       : 5월 02, 2023
암호 만료                                       :안함
암호가 비활성화 기간                                    :안함
계정 만료                                               :안함
암호를 바꿀 수 있는 최소 날 수          : 0
암호를 바꿔야 하는 최대 날 수           : 99999
암호 만료 예고를 하는 날 수             : 7

--inactive INACTIVE       set password inactive after expiration                               #패스워드 만료후 유예기간
                                to INACTIVE

chgrp : 그룹 소유권 변경

d---rw----   4    1005 1006   89  5월  2 21:27 insa
# chgrp insa /home/insa 
d---rw----   4    1005 insa   89  5월  2 21:27 insa

gpasswd : 그룹 암호 설정 , 그룹 관리자 설정

더보기

Options:

gpasswd [그룹이름]

비번입력 : 

비번설정 

                                                                        
  -a, --add USER                add USER to GROUP                               # 그룹에 유저 추가

useradd -G

usermod -G
  -d, --delete USER             remove USER from GROUP
  -h, --help                    display this help message and exit
  -Q, --root CHROOT_DIR         directory to chroot into
  -r, --delete-password         remove the GROUP's password
  -R, --restrict                restrict access to GROUP to its members
  -M, --members USER,...        set the list of members of GROUP
  -A, --administrators ADMIN,...                                                           #그룹 관리자 변경
                                set the list of administrators for GROUP

#gpasswd -A posein admin

# cat /etc/gshadow

insa:!::
admin:!:posein:

groupmod -n 이름변경


문제1. 아래에 해당하는 파일명 또는 디렉터리

1. 사용자 추가 시 .forward 라는 파일을 사용자에게 기본적으로 제공하려고 한다.

2. 그룹 생성 시에 부여 되는 GID의 최솟값을 1000으로 변경하려고 한다.

3. 사용자 생성 시에 사용자의 패스워드를 변경하지 않고 최대로 사용할 수 있는 기간을 60일로 지정하려고 한다.

4. 사용자 생성 시에 할당 되는 셸을 /bin/dash 로 지정하려고한다.

 

더보기

1. /etc/skel                #디렉토리

2. /etc/login.defs       #그룹 생성시    GID최솟값

3. /etc/login.defs      # 사용자 생성시

4. /etc/default/useradd     # 쉘이니까  /etc/default/useradd