IT 이야기/리눅스
우분투 계정 추가 / 관리 명령어(adduser, useradd, usermod)
미르호
2025. 4. 2. 17:53
우분투에서 계정을 추가하는 방법은 2가지가 있다.
1. adduser
$ adduser {user_name}
계정 생성 시 user 추가 뿐 아니라 홈 디렉토리, 비밀번호 설정 등의 전체 과정이 한 번에 진행됨
2. useradd
$ useradd {user_name}
adduser 와 동일해 보이나, {user_name} 으로 계정을 생성할 뿐, 나머지 작업에 대해서는 하나씩 다 진행해 줘야한다.
useradd 의 man page 나 help 명령어로 확인해보면 다음과 같은 옵션들이 있다.
$ useradd --help
Usage: useradd [options] LOGIN
useradd -D
useradd -D [options]
Options:
-b, --base-dir BASE_DIR base directory for the home directory of the
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
-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
account
-G, --groups GROUPS list of supplementary groups of the new
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
-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
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
--extrausers Use the extra users database
신규 서버의 사용자 계정을 생성해 달라는 요청을 받아 생성해 주었다.
$ useradd {user_name} -m -s /bin/bash -g users
-m : 계정의 홈 경로 생성, /home/{user_name} 경로가 생성됨
-s : 사용할 shell 지정, /bin/bash 를 사용하도록 설정함
-g : 1순위 그룹을 지정, 생성한 계정을 users 그룹에 넣음
-g 옵션은 1순위 그룹을 지정하는 것이고, -G 옵션은 차순위 그룹을 지정함
3. usermod
기존 계정을 수정할 때 사용함
useradd 에서 생성한 계정에 대해서 수정이 필요하여 아래처럼 수정해 주었다.
$ usermod -c {코멘트할 내용} -aG sudo {account_name}
계정 추가 시, 왜 추가했는지, 어떤 사용자인지 어떤 권한을 가지는지 등의 내용을 적어놓으면 관리하기 좋다.
OPTIONS
The options which apply to the usermod command are:
-a, --append
Add the user to the supplementary group(s). Use only with the -G option.
-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option.
If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list.
-a : 오직 -G 옵션하고만 사용가능, user를 group 에 넣을 때 사용함
-G : 계정을 그룹에 추가함