Github avatar

GyeongSu Han's Github Pages

리눅스 사용자 계정 추가

Sep 05, 2015 · Server

리눅스에서 사용자 계정을 추가하는 명령은 adduseruseradd명령이 있다.

두 명령의 차이점은 adduser의 경우 모든 설정을 자동으로 할 수 있는 반면, useradd의 경우는 모든 설정을 수동으로 해주어야 한다.

그럼 useradd로 계정을 추가해 보도록 하겠다.

root@ubuntu:~# useradd test2

계정을 추가할때 패스워드를 설정하지 않는다.

root@ubuntu:~# ls -al /home/test2
ls: cannot access /home/test2: No such file or directory

또한 계정폴더가 생성되지 않는다.

adduser로 test라는 사용자를 추가하였다.

root@ubuntu:~# adduser test
Adding user `test' ...
Adding new group `test' (1010) ...
Adding new user `test' (1004) with group `test' ...
Creating home directory `/home/test' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for test
Enter the new value, or press ENTER for the default
    Full Name []:
    Room Number []:
    Work Phone []:
    Home Phone []:
    Other []:
Is the information correct? [Y/n] y

여기서 보아야 할 점은 Copying files from '/etc/skel' ... 이다.

root@ubuntu:~# cd /etc/skel/
root@ubuntu:/etc/skel# ls -al
total 20
drwxr-xr-x  2 root root 4096 May  9 10:14 .
drwxr-xr-x 92 root root 4096 Sep  5 14:58 ..
-rw-r--r--  1 root root  220 Apr  9  2014 .bash_logout
-rw-r--r--  1 root root 3637 Apr  9  2014 .bashrc
-rw-r--r--  1 root root  675 Apr  9  2014 .profile

해당 폴더에 가보게 되면 이렇게 기본적인 설정 파일이 있다. 이 파일들을 새로 생성한 계정폴더에 복사하게 되는 것 이다.

root@ubuntu:~# ls -al /home/test/
total 20
drwxr-xr-x 2 test test 4096 Sep  5 14:58 .
drwxr-x--x 6 root root 4096 Sep  5 14:58 ..
-rw-r--r-- 1 test test  220 Sep  5 14:58 .bash_logout
-rw-r--r-- 1 test test 3637 Sep  5 14:58 .bashrc
-rw-r--r-- 1 test test  675 Sep  5 14:58 .profile

이렇게 추가된 계정은 자동으로 폴더가 추가되고, 설정파일도 생성되게 된다.

Ubuntu의 경우에는 /etc/adduser.conf가 있고,

CentOS의 경우 /etc/default/useradd가 있다.

이 파일들을 설정하여 adduser를 설정할 수 있다.