Skip to content

사용자 관리

  • root 계정의 UID 값은 0이다.
  • root 이외에 UID가 0인 사용자가 없도록 해야 한다.
  • TMOUT 환경 변수를 사용해 일정시간 미사용시 자동으로 로그아웃 되도록 설정하여 보안을 강화할 수 있다.
  • 사용자 인증 모듈인 PAM을 이용해 root 계정으로의 직접 로그인을 차단할 수 있다.
  • 일반 사용자에게 특정 명령어에 대한 root 권한이 필요할 때는 su 명령어보다는 sudo 명령어를 이용하도록 한다.

계정 관리

계정 정보가 저장되어있는 디렉토리에 대해 알아보자.

  • /etc/passwd

  • 비밀번호를 파일 내 계정 정보와 함께 저장하는 일반 정책에서 사용된다.

  • passwd 파일의 로그인 쉘을 점검하여 로그인이 불필요한 계정에 대한 접근권한을 설정해야 한다.

  • [user_account]: [user_password] : [UID] : [GID] : [comment] : [home_directory] : [login_shell]
    1. user_account: 사용자 계정
    2. user_password: /etc/shadow 파일에 암호화되어 저장되어 있다.
    3. UID: User ID. 보통 100번 이하는 시스템이 사용, 0번은 시스템 관리자를 나타낸다. 4) GID: Group ID
    4. comment: 부가 설명
    5. home_directory: 로그인 성공 후에 사용자가 위치할 홈 디렉터리의 절대경로
    6. login_shell: 로그인 셸의 절대경로
  • /etc/shadow

  • 파일에 비밀번호를 별도로 저장하는 shadow 패스워드 정책에서 사용된다.

  • shadow 파일은 암호화된 패스워드를 가지고 있어 보안 상 shadow 정책을 사용하는 것이 안전하다.

  • [user_id] : [encryption_pw] : [last_change] : [minlife] : [maxlife] : [warn] : [inactive] : [expires]

`1. user_id: 사용자 계정 2. encryption_pw: 일방향 해시 알고리즘을 이용해 암호화한 패스워드

  • 형식: $ id $ salt $ encrypted_password
  • id: 적용된 일방향 해시 알고리즘 (1: MD5 / 5: SHA-256 / 6: SHA-512 등)
  1. last_change: 마지막으로 패스워드를 변경한 날 (1970.01.01.부터 지난 일수로 표시)
  2. minlife: 최소 패스워드 변경 일수(패스워드를 변경할 수 없는 기간)
  3. maxlife: 최대 패스워드 변경 일수(패스워드 변경 없이 사용할 수 있는 일수)
  4. warn: 경고 일수(maxlife 필드에 지정한 일수가 얼마 남지 않았음을 알림)
  5. inactive: 최대 비활성 일수
  6. expires: 계정이 만료되는 날 (1970.01.01.부터 지난 일수로 표시)`

encryption_pw 필드의 기호 뜻

기호설명
*패스워드 잠긴 상태, 별도의 인증방식을 사용하여 로그인
!!패스워드 잠긴 상태, 모든 로그인이 불가능
(빈값)패스워드가 설정되지 않은 상태
  • /etc/login.def
    • 사용자 계정의 설정과 관련된 기본 값을 정의한 파일
    • 기본 메일 디렉터리, 패스워드 에이징, 사용자 계정의 UID/GID 값 범위 등의 기본값을 설정할 수 있다.
  • /etc/skel
    • 사용자 계정 생성 시 공통으로 배포할 파일이나 디렉터리를 저장하는 디렉터리
  • /etc/default/useradd
    • useradd 명령어로 계정 생성 시 기본 값을 지정한 파일

그룹 관리

  • /etc/group
    • 그룹 명 : 그룹 패스워드 : GID : 그룹 멤버
    • /etc/passwd 파일에는 기본 그룹의 GID가 저장되고, /etc/group 파일에는 2차 그룹의 정보가 저장
  • /etc/gshadow
    • 그룹 명 : 암호화 된 그룹 패스워드 : 관리자 : 그룹 멤버

명령어

  • useradd

    • 사용자 계정을 생성하는 명령어
    • 옵션 없이 계정 생성할 경우 패스워드를 설정하지 않았기 때문에 /etc/shadow 파일에 패스워드 항목이 !!로 지정되어 있다. (패스워드가 잠겨 있음)
      • useradd --help
        Usage: useradd [options] LOGIN
        useradd -D
        useradd -D [options]
        Options:
        -g, --gid GROUP name or ID of the primary group of the new account
        -G, --groups GROUPS list of supplementary groups of the new account
        -o, --non-unique allow to create users with duplicate (non-unique) UID
        -c, --comment COMMENT GECOS field of the new account
        -d, --home-dir HOME_DIR home directory of the new account
        -e, --expiredate EXPIRE_DATE expiration date of the new account
        -f, --inactive INACTIVE password inactivity period of the new account
        -s, --shell SHELL login shell of the new account
        -u, --uid UID user ID of the new account
        -U, --user-group create a group with the same name as the user
        ...
  • usermod

    • 사용자 계정의 정보를 변경하는 명령어
    • useradd 명령어와 옵션 동일
    • -l: 계정 이름 변경
    • -L, --lock lock the user account
      -U, --unlock unlock the user account
  • userdel

    • 사용자 계정을 삭제하는 명령어
    • -r: 홈 디렉터리 제거
  • chage

    • 패스워드 에이징에 대한 설정 명령어
    • $ chage --help
      Usage: chage [options] LOGIN
      Options:
      -l, --list show account aging information
      -E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
      -I, --inactive INACTIVE set password inactive after expiration to INACTIVE
      -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
      -W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS
      ...
      $ chage -l ubuntu
      Last password change : Nov 06, 2022
      Password expires : never
      Password inactive : never
      Account expires : never
      Minimum number of days between password change : 0
      Maximum number of days between password change : 99999
      Number of days of warning before password expires : 7
  • passwd

    • 사용자 계정의 패스워드를 변경/관리하는 명령어
    • $ passwd --help
      Usage: passwd [options] [LOGIN]
      Options:
      -a, --all report password status on all accounts
      -d, --delete delete the password for the named account
      -e, --expire force expire the password for the named account
      -l, --lock lock the password of the named account
      -u, --unlock unlock the password of the named account
      -n, --mindays MIN_DAYS set minimum number of days before password change to MIN_DAYS
      -x, --maxdays MAX_DAYS set maximum number of days before password change to MAX_DAYS
      -w, --warndays WARN_DAYS set expiration warning days to WARN_DAYS
      ...
  • groupadd

    • 그룹을 생성하는 명령어
    • $ groupadd --help
      Usage: groupadd [options] GROUP
      Options:
      -g, --gid GID use GID for the new group
      -o, --non-unique allow to create groups with duplicate
  • groupmod

    • 그룹의 정보를 변경하는 명령어
    • groupadd 명령어와 옵션이 동일
    • -n: 그룹 이름 변경
  • groupdel

    • 그룹 삭제
  • gpasswd

    • 그룹의 패스워드를 변경하거나 그룹에 계정을 추가/삭제하는 명령어
    • $ gpasswd --help
      Usage: gpasswd [option] GROUP
      Options:
      -a, --add USER add USER to GROUP
      -d, --delete USER remove USER from GROUP
      -r, --remove-password remove the GROUP's password
      -A, --administrators ADMIN,...
      set the list of administrators for GROUP
      ...
  • newgrp

    • 계정의 소속 그룹을 변경하는 명령어
    • newgrp grp01 → grp01로 그룹을 변경

사용자 정보 확인

  • who

    • 현재 시스템을 사용하는 사용자의 정보를 출력하는 명령어
    • $ who --help
      Usage: who [OPTION]... [ FILE | ARG1 ARG2 ]
      Print information about users who are currently logged in.
      -a, --all same as -b -d --login -p -r -t -T -u
      -b, --boot time of last system boot
      -H, --heading print line of column headings
      --ips print ips instead of hostnames. with --lookup,
      canonicalizes based on stored IP, if available,
      rather than stored hostname
      -q, --count all login names and number of users logged on
      -r, --runlevel print current runlevel
      -s, --short print only name, line, and time (default)
      ...
      $ who
      ubuntu pts/0 2023-06-26 15:39 (14.50.190.128)
      ubuntu pts/1 2023-06-26 19:48 (14.50.190.128)
  • w

    • 현재 시스템을 사용하는 사용자의 정보와 작업 정보를 출력하는 명령어
    • $ w
      19:59:10 up 232 days, 59 min, 2 users, load average: 0.00, 0.00, 0.00
      USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
      ubuntu pts/0 14.50.190.128 15:39 1:35m 0.15s 0.04s -c
      ubuntu pts/1 14.50.190.128 19:48 1.00s 0.07s 0.00s w
  • whoami

    • 현재 작업하고 있는 자신의 계정을 출력
    • $ whoami
      ubuntu
  • id

    • 현재 작업하고 있는 자신의 계정명, 그룹명, UID, GID를 출력하는 명령어
    • $ id
      uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),20(dialout),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),118(netdev),119(lxd)
  • users

    • 현재 로그인 되어 있는 사용자의 계정을 출력
    • $ users
      ubuntu ubuntu ubuntu
  • groups

    • 사용자 계정이 속한 그룹을 출력
    • $ groups
      ubuntu adm dialout cdrom floppy sudo audio dip video plugdev netdev lxd
  • lslogins

    • 시스템 내에 있는 사용자 계정에 대한 정보를 출력
    • $ lslogins
      UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
      0 root 115 root
      1 daemon 0 daemon
      2 bin 0 bin
      3 sys 0 sys
      4 sync 0 sync

무결성 검사 명령어

  • pwck
    • /etc/passwd 파일과 /etc/shadow 파일 내용의 무결성을 검사하는 명령어
    • $ sudo pwck
      user 'lp': directory '/var/spool/lpd' does not exist
      user 'news': directory '/var/spool/news' does not exist
      user 'uucp': directory '/var/spool/uucp' does not exist
      user 'list': directory '/var/list' does not exist
      user 'irc': directory '/run/ircd' does not exist
      user 'gnats': directory '/var/lib/gnats' does not exist
      user 'nobody': directory '/nonexistent' does not exist
      pwck: no changes
  • grpck
    • /etc/group 파일과 /etc/gshadow 파일 내용의 무결성을 검사하는 명령어

참고