갈루아의 반서재

리눅스 사용가능한 사용자 계정 조회 A command to list all users and how to add, delete, modify users


사용가능한 로컬 유저 목록 보기

1
2
3
4
5
6
7
8
9
10
11
 
postgres@localhost:~$ cut -d: -f1 /etc/passwd
root
daemon
bin
sys
sync
postgres
test1
postgres@localhost:~$
 
cs

getent를 이용해서도 사용자 목록을 볼 수 있다. 다만 getent가 /etc/passwd 또는 LDAP 등 사용자 db 백엔드에 구성된 모든 사용자를 반환한다는 점에서 위와 방식과 차이가 있다.

1
2
3
4
5
6
7
8
9
10
11
 
postgres@localhost:~$ getent passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
postgres:x:121:130:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
test1:x:1002:1003:,,,:/home/test1:/bin/bash
postgres@localhost:~$
 
cs


사용자 추가하기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
root@localhost:~# sudo adduser test2
'test2' 사용자를 추가 중...
새 그룹 'test2' (1004) 추가 ...
새 사용자 'test2' (1003) 을(를) 그룹 'test2' (으)로 추가 ...
'/home/test2' 홈 디렉터리를 생성하는 중...
'/etc/skel'에서 파일들을 복사하는 중...
새 UNIX 암호 입력:
새 UNIX 암호 재입력:
passwd: password updated successfully
Changing the user information for test2
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
정보가 올바릅니까? [Y/n] y
root@localhost:~# cut -d: -f1 /etc/passwd
test1
test2
 
cs

What is the difference between adduser and useradd?


사용자 삭제하기

1
2
3
4
5
6
root@localhost:~# sudo userdel test2
root@localhost:~# cut -d: -f1 /etc/passwd
test1
root@localhost:~# cd /home/test2
root@localhost:/home/test2#
 
cs


삭제한 사용자 계정의 홈 디렉토리 제거하기

1
2
3
4
root@localhost:/home/test2# sudo rm -r /home/test2
root@localhost:/# cd /home/test2
-sucd/home/test2: 그런 파일이나 디렉터리가 없습니다
 
cs


사용자 이름 변경

1
2
3
4
5
root@localhost:/# usermod -l test30 test3
root@localhost:/# cut -d: -f1 /etc/passwd
 
test1
test30
cs


사용자 암호 변경

1
2
3
4
5
6
 
root@localhost:/# sudo passwd test30
새 UNIX 암호 입력:
새 UNIX 암호 재입력:
passwd: password updated successfully
 
cs


사용자 상세 정보 변경하기

1
2
3
4
5
6
7
8
9
root@localhost:/# sudo chfn test30
Changing the user information for test30
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
root@localhost:/#
cs