리눅스

useradd 명령어

변군이글루 2013. 8. 5. 13:14
반응형

useradd 명령어

useradd는 Linux와 Unix 기반 운영 체제에서 사용자 계정을 추가하는 명령어입니다. 이 명령어를 사용하여 새로운 사용자 계정을 생성할 수 있으며, 필요에 따라 사용자에게 홈 디렉토리를 생성하고 기본 설정을 구성할 수 있습니다.

명령어 구문

useradd [옵션] 사용자명

일반적인 옵션

  • -c: 사용자에 대한 설명을 추가합니다.
  • -d: 사용자의 홈 디렉토리 경로를 지정합니다.
  • -g: 사용자가 속할 기본 그룹을 지정합니다.
  • -m: 홈 디렉토리를 생성하고 기본 파일을 복사합니다.
  • -s: 사용자의 로그인 쉘을 지정합니다.
  • -u: 사용자의 UID(사용자 식별자)를 지정합니다.
  • -G: 사용자가 속할 보조 그룹을 지정합니다.

사용 예시

새로운 사용자 계정 추가 (홈 디렉토리 생성하지 않음)

sudo useradd john
  • 위 명령어는 "john"이라는 사용자 계정을 생성하며, 기본적으로는 홈 디렉토리가 생성되지 않습니다.

사용자 계정 추가와 홈 디렉토리 생성

sudo useradd -m jane
  • 위 명령어는 "jane"이라는 사용자 계정을 생성하고, 홈 디렉토리를 생성합니다.

설명과 UID 지정

sudo useradd -c "John Doe" -u 1001 johndoe
  • 위 명령어는 "johndoe"라는 사용자 계정을 생성하고, 사용자 설명을 "John Doe"로 지정하며, UID를 1001로 지정합니다.

로그인 쉘 지정

sudo useradd -s /bin/bash alice
  • 위 명령어는 "alice"라는 사용자 계정을 생성하고, 로그인 쉘을 "/bin/bash"로 지정합니다.

그룹 지정

sudo useradd -g developers -G sudo,bashusers dave
  • 위 명령어는 "dave"라는 사용자 계정을 생성하고, 기본 그룹을 "developers"로 지정하며, 보조 그룹으로 "sudo"와 "bashusers"를 추가합니다.

비밀번호 설정

  • useradd 명령어는 기본적으로 비밀번호를 설정하지 않으므로, 생성한 계정으로 로그인하려면 passwd 명령어를 사용하여 비밀번호를 설정해야 합니다.
sudo passwd johndoe

apache 계정 생성

useradd -c "Apache" -u 48 -s /sbin/nologin -m -d /home/www apache
vim /etc/passwd
apache:x:48:48:Apache:/home/www:/sbin/nologin

mysql 계정 생성

useradd -m -c "MySQL Server" -d /usr/local/mysql -s /bin/false -u 27 mysql

tomcat 계정 생성

groupadd tomcat
useradd -c "Tomcat Service" -m -d /apps/tomcat -s /usr/sbin/nologin -g tomcat tomcat

amen 그룹 및 계정 생성

groupadd -g 1001 amen
useradd -m -c "System Account" -d /home/amen -s /bin/bash -u 1001 -g 1001 amen
$ cat /etc/group
amen:x:1001:
$ cat /etc/passwd
amen:x:1001:1001:System Account:/home/amen:/bin/bash

사용법

$ useradd -h
Usage: useradd [options] LOGIN
       useradd -D
       useradd -D [options]

Options:
      --badnames                do not check for bad names
  -b, --base-dir BASE_DIR       base directory for the home directory of the
                                new account
      --btrfs-subvolume-home    use BTRFS subvolume for home directory
  -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
  -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
  -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

 

728x90
반응형