본문 바로가기

CentOS/Study

[사용자계정관리]usermod

반응형

<usermod>

사용자의셸, 홈디렉터리, 그룹, UID ,GID등을 변경하는 명령어로 사용자 관련하여 대부분의 정보를 변경가능

 

[root@localhost ~]# usermod
Usage: usermod [options] LOGIN

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
  -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
  -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

 

-d : 사용자의 홈 디렉터리를 변경
-m : 사용자의 홈 디렉터리 변경 시 기존에 사용하던 파일 및 디렉터리를 옮겨주는 옵션으로 -d 옵션과 함께 쓰임
-g : 사용자의 그룹을 변경
-s : 사용자의 셸을 변경
-u : 사용자의 UID값을 변경
-e : 계정의 만기일을 지정(YYYY-MM-DD)
-f : 패스워드만기일이지난후패스워드에LOCK을설정할유예기간을지정
-c : 사용자의 간단한 정보 입력, 변경
-G : 추가로 다른 그룹에 속하게 할 때 쓰이는 옵션
-p : /etc/shadow의 2번쨰 필드인 암호화된 패스워드 값을 변경할때 쓰임
-l : 사용자 아이디 변경
-L : 사용자의 패스워드에 LOCK을 걸어 로그인을 막음
-U : 사용자의 패스워드에 걸린 LOCK을 품

 

<예제>

1. UID 변경 하는 방법

[root@server1 ~]# grep user01 /etc/passwd
user01:x:1001:1001::/home/user01:/bin/bash
[root@server1 ~]# usermod -u 2000 user01
[root@server1 ~]# grep user01 /etc/passwd
user01:x:2000:1001::/home/user01:/bin/bash

 

2. 사용자의 셸을 변경

[root@server1 ~]# grep user01 /etc/passwd
user01:x:1001:1001::/home/user01:/bin/bash
[root@server1 ~]# yum -y install ksh
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.navercorp.com
 * extras: mirror.navercorp.com
 * updates: mirror.navercorp.com
Resolving Dependencies
--> Running transaction check
---> Package ksh.x86_64 0:20120801-143.el7_9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================
 Package              Arch                    Version                              Repository                Size
==================================================================================================================
Installing:
 ksh                  x86_64                  20120801-143.el7_9                   updates                  885 k

Transaction Summary
==================================================================================================================
Install  1 Package

Total download size: 885 k
Installed size: 3.1 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/updates/packages/ksh-20120801-143.el7_9.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for ksh-20120801-143.el7_9.x86_64.rpm is not installed
ksh-20120801-143.el7_9.x86_64.rpm                                                          | 885 kB  00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-0.1406.el7.centos.2.3.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : ksh-20120801-143.el7_9.x86_64                                                                  1/1
  Verifying  : ksh-20120801-143.el7_9.x86_64                                                                  1/1

Installed:
  ksh.x86_64 0:20120801-143.el7_9

Complete!
[root@server1 ~]# usermod -s /bin/ksh user01
[root@server1 ~]# grep user01 /etc/passwd
user01:x:2000:1001::/home/user01:/bin/ksh

 

 

반응형

'CentOS > Study' 카테고리의 다른 글

[패스워드관리]chage  (0) 2022.03.14
[사용자계정관리]userdel  (0) 2022.03.14
[사용자관리파일]/etc/login.defs  (0) 2022.03.14
[사용자관련파일]/etc/passwd  (0) 2022.03.14
[사용자관련파일]/etc/shadow  (0) 2022.03.14