시도하고 시도 2022. 6. 22. 17:27

사용자 전체 목록 확인

cat /etc/passwd

계정이 엄청나게 많이 나올건데, root 계정, 시스템 계정, 그리고 사용자가 추가한 계정 세 가지가 있다고 한다.

대표적인 생김새는 다음과 같다.

$ cat /etc/passwd
계정명:password(x):UID:GID:설명:홈디렉토리:로그인 쉘
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
...
ict-526:x:1000:1000:ict-526,,,:/home/ict-526:/bin/bash

What's the difference between a normal user and a system user?

 

What's the difference between a normal user and a system user?

Some documentation I'm going through has a boolean switch on whether or not a user is a 'system' user or a 'normal' user (defaulting to 'normal'). What is the difference between these two modes of ...

unix.stackexchange.com

라는 질문이 있어 번역을 해보면, 사용 목적에 따라 자동으로 생성된 시스템 계정과 사용자 계정으로 나눠놓고 있으며, 두 범주는 UID에서도 그 범위를 통해 구분을 하고 있다고 말하고 있다.

System users will be created with no aging information in /etc/shadow, and their numeric identifiers are chosen in the SYS_UID_MINSYS_UID_MAX range, defined in /etc/login.defs, instead of UID_MINUID_MAX (and their GID counterparts for the creation of groups).

#
UID_MIN                  1000
UID_MAX                 60000
# System accounts
SYS_UID_MIN               100
SYS_UID_MAX               499

#
GID_MIN                  1000
GID_MAX                 60000
# System accounts
SYS_GID_MIN               100
SYS_GID_MAX               499

사용자 이름만 표시

cut -f1 -d: /etc/passwd

여기서 cut 명령어는 파일에서 필드를 뽑아내는 명령어이다. 원시적인 엑셀을 보는 거 같기도 하다.

더보기

cut

사용법

cut [option] [file]

 

옵션

-c 문자위치 :잘라낼 곳의 글자 위치를 지정한다. 콤마나 하이픈을 사용하여 범위를 정할 수도 있으며, 이런 표현들을 혼합하여 사용할 수도 있다.

-f 필드 : 잘라낼 필드를 정한다.

-d 구분자 : 필드를 구분하는 문자를 지정한다. 디폴트는 탭 문자다.

-s : 필드 구분자를 포함할 수 없다면 그 행은 하지 않는다.

여기에서 알 수 있는 것은, /etc/passwd는 그냥 파일이며, 이 안에 데이터가 엑셀처럼 정해진 필드에 빈틈없이 정보들이 규칙적으로 담겨있다는 점이다.

cut -f1 -d: /etc/passwd 로 첫번째 필드(열)을 뽑아오는데, 필드 구분자는 탭명령어가 아닌 ":" 이고, 이 파일의 위치는 /etc/passwd 에서 찾아봐라 라고 알려주며 명령을 실행시킨 거다.

 

출처: https://bbolmin.tistory.com/32 [bbolmin:티스토리]

 

USERADD 를 통해 등록된 계정만 보기

grep /bin/bash /etc/passwd
grep /bin/bash /etc/passwd | cut -f1 -d:

 

출처: https://overcode.tistory.com/entry/%EB%A6%AC%EB%88%85%EC%8A%A4-%EC%82%AC%EC%9A%A9%EC%9E%90-%EB%AA%A9%EB%A1%9D-%ED%99%95%EC%9D%B8-Linux-User-List

 

리눅스 사용자 목록 확인 (Linux User List)

전체 목록 확인 cat /etc/passwd 전체를 다 확인 할 수 있다. cut -f1 -d: /etc/passwd 아이디만 짤라서 보여준다. USERADD 를 통해 등록된 계정만 보기 grep /bin/bash /etc/passwd grep /bin/bash /etc/passwd..

overcode.tistory.com