별의 공부 블로그 🧑🏻‍💻
728x90
728x170

chage

I. 개념

사용자 패스워드 관리 : chage

  • 사용자의 패스워드에 대한 정보를 출력하고 설정
  • /etc/shadow의 날짜 관련 필드 설정을 모두 할 수 있는 명령

사용법

# chage [option] 사용자계정
  • -l
    • 사용자의 패스워드에 대한 정보를 보여줌.
    • --list
  • -d
    • /etc/shadow의 3번째 필드에 해당하는 값인 최근 패스워드를 바꾼 날(1970년 1월 1일부터 계산한 날짜 수)을 수정함.
  • -m
    • 패스워드 변경의 최소 날짜 지정
    • 패스워드 변경 후, 일정 기간 사용해야될 최소 날짜수 지정
  • -M
    • 패스워드 변경 없이 사용 가능한 최대 날짜 지정
    • 한번 설정한 패스워드의 만기일 지정
  • -I
    • 패스워드 최대 사용기간 만료 후에 실제 패스워드에 잠근(LOCK)을 설정하기까지의 유예 기간 지정
  • -E
    • 계정이 만기되는 날 지정
    • MM/DD/YY 또는 YYYY-MM-DD 형태로 지정
  • -W
    • 패스워드 만료 전, 변경을 요구하는 경고 날짜 지정
  • -h
    • 명령어 사용법 및 주요 옵션 정보를 간략히 출력
    • --help

 

사용 예

  • starrykss 의 패스워드 정보 출력
# chage -l starrykss
마지막으로 암호를 바꾼 날                    :안함
암호 만료                    :안함
암호가 비활성화 기간                    :안함
계정 만료                        :안함
암호를 바꿀 수 있는 최소 날 수        : 0
암호를 바꿔야 하는 최대 날 수        : 99999
암호 만료 예고를 하는 날 수        : 7
# chage -m 10 -M 100 -W 5 -I 3 starrykss
  • starrykss의 패스워드의 최소 사용 날짜는 10일,
  • 최대 사용 가능한 날은 100일로 설정
  • 또한, 패스워드 만기일로부터 5일전에 경고 메시지를 보여주고,
  • 만기일 이후 3일이 지나도 변경하지 않으면 패스워드에 잠금을 설정해서 로그인을 막음.
# chage -E 2013-12-22 yuloje
  • yuloje의 계정 만기일을 2013년 12월 22일로 설정
# chage -d 15917 jalin
  • jalin의 패스워드 변경일(/etc/shadow의 3번째 필드값)을 15917(2013년 7월 31일)로 수정

 

참고
  • /etc/shadow와 날짜 관련 명령어 옵션 비교
username : password : last : may : must : warn : expire : disable : reserved
------------------------------------------------------------------------------
               chage   -d    -m     -M     -W     -I        -E
              passwd         -n     -x     -w     -i
             usermod                              -f        -e

II. MAN 명령어로 살펴보기

CHAGE(1)                         User Commands                        CHAGE(1)



NAME
       chage - change user password expiry information

SYNOPSIS
       chage [options] LOGIN

DESCRIPTION
       The chage command changes the number of days between password changes
       and the date of the last password change. This information is used by
       the system to determine when a user must change their password.

OPTIONS
       The options which apply to the chage command are:

       -d, --lastday LAST_DAY
           Set the number of days since January 1st, 1970 when the password
           was last changed. The date may also be expressed in the format
           YYYY-MM-DD (or the format more commonly used in your area). If the
           LAST_DAY is set to 0 the user is forced to change his password on
           the next log on.

       -E, --expiredate EXPIRE_DATE
           Set the date or number of days since January 1, 1970 on which the
           user's account will no longer be accessible. The date may also be
           expressed in the format YYYY-MM-DD (or the format more commonly
           used in your area). A user whose account is locked must contact the
           system administrator before being able to use the system again.

           For example the following can be used to set an account to expire
           in 180 days:

                        chage -E $(date -d +180days +%Y-%m-%d)


           Passing the number -1 as the EXPIRE_DATE will remove an account
           expiration date.

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

       -I, --inactive INACTIVE
           Set the number of days of inactivity after a password has expired
           before the account is locked. The INACTIVE option is the number of
           days of inactivity. A user whose account is locked must contact the
           system administrator before being able to use the system again.

           Passing the number -1 as the INACTIVE will remove an account's
           inactivity.

       -l, --list
           Show account aging information.

       -m, --mindays MIN_DAYS
           Set the minimum number of days between password changes to
           MIN_DAYS. A value of zero for this field indicates that the user
           may change their password at any time.

       -M, --maxdays MAX_DAYS
           Set the maximum number of days during which a password is valid.
           When MAX_DAYS plus LAST_DAY is less than the current day, the user
           will be required to change their password before being able to use
           their account. This occurrence can be planned for in advance by use
           of the -W option, which provides the user with advance warning.

           Passing the number -1 as MAX_DAYS will remove checking a password's
           validity.

       -R, --root CHROOT_DIR
           Apply changes in the CHROOT_DIR directory and use the configuration
           files from the CHROOT_DIR directory.

       -W, --warndays WARN_DAYS
           Set the number of days of warning before a password change is
           required. The WARN_DAYS option is the number of days prior to the
           password expiring that a user will be warned their password is
           about to expire.

       If none of the options are selected, chage operates in an interactive
       fashion, prompting the user with the current values for all of the
       fields. Enter the new value to change the field, or leave the line
       blank to use the current value. The current value is displayed between
       a pair of [ ] marks.

NOTE
       The chage program requires a shadow password file to be available.

       The chage program will report only the information from the shadow
       password file. This implies that configuration from other sources (e.g.
       LDAP or empty password hash field from the passwd file) that affect the
       user's login will not be shown in the chage output.

       The chage program will also not report any inconsistency between the
       shadow and passwd files (e.g. missing x in the passwd file). The pwck
       can be used to check for this kind of inconsistencies.

       The chage command is restricted to the root user, except for the -l
       option, which may be used by an unprivileged user to determine when
       their password or account is due to expire.

CONFIGURATION
       The following configuration variables in /etc/login.defs change the
       behavior of this tool:

FILES
       /etc/passwd
           User account information.

       /etc/shadow
           Secure user account information.

EXIT VALUES
       The chage command exits with the following values:

       0
           success

       1
           permission denied

       2
           invalid command syntax

       15
           can't find the shadow password file

SEE ALSO
       passwd(5), shadow(5).



shadow-utils 4.6                  08/09/2019                          CHAGE(1)

III. 예제

다음 조건에 맞게 사용자 정보를 변경하려고 한다.

예제 1

  • 패스워드 변경 없이 사용가능한 날짜는 30일이고, 패스워드 변경 후에는 최소 3일 동안 사용해야 한다.
  • 해당 사용자는 2016년 12월 31일까지만 로그인이 되도록 설정하고, 패스워드 만기일이 지난 후 유예기간은 7일로 설정한다.
# chage -m 3 -M 30 -E 2016-12-31 -I 7

예제 2

  • idhuser의 사용자 패스워드 변경일을 2020년 9월 18일로 설정하고, 계정 만기일을 2020년 12월 31일로 설정한다.
# chage -d 18523 -E 2020-12-31 idhuser
728x90
그리드형(광고전용)
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖