본문 바로가기
개발참고/리눅스

리눅스 기본명령어 - 사용자 및 계정관련

by 헤헤헤~ 2022. 11. 1.
728x90

안녕하세요.

 

리눅스 기본명령어 중 사용자 및 계정관리 대해 알아보겠습니다.

 

※ 리눅스 계열에 따라 명령어가 달라지거나 실행되지 않을 수 있습니다.

 

1. 현재접속자 관리

users : 현재 로그인한 사용자 계정

[root@localhost ~]# users
root

 

who : 현재 로그인 되어 있는 사용자들을 로그인 정보와 같이 출력

// 현재접속자
[root@localhost ~]# who
root     pts/0        2022-10-30 22:58 (xxx.xxx.x.xxx)

// 타이틀과 같이 표시
[root@localhost ~]# who -H
NAME     LINE         TIME             COMMENT
root     pts/0        2022-10-30 22:58 (xxx.xxx.x.xxx)

// 로그인한 사용자 및 총수
[root@localhost ~]# who -q
root
# users=1

// 접속정보 상세표시
[root@localhost ~]# who -aH
NAME       LINE         TIME             IDLE          PID COMMENT  EXIT
           system boot  2022-04-08 09:15
           run-level 3  2022-04-08 09:15
LOGIN      tty1         2022-04-08 09:16              2639 id=1
LOGIN      tty2         2022-04-08 09:16              2641 id=2
LOGIN      tty3         2022-04-08 09:16              2643 id=3
LOGIN      tty4         2022-04-08 09:16              2645 id=4
LOGIN      tty5         2022-04-08 09:16              2647 id=5
LOGIN      tty6         2022-04-08 09:16              2649 id=6
root     + pts/0        2022-11-01 13:58   .         72097 (xxx.xxx.x.xxx)
           pts/1        2022-10-31 21:03             55012 id=ts/1  term=0 exit=0
           pts/2        2022-11-01 09:31             54413 id=ts/2  term=0 exit=0

 

w : 현재 접속자정보 및 접속자들의 작업정보 (WHAT)

[root@localhost ~]# w
 14:00:35 up 207 days,  4:44,  1 user,  load average: 0.18, 0.13, 0.09
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    xxx.xxx.x.xxx    22:58    0.00s  0.00s  0.00s w

 

skill -KILL 사용자아이디 or pts/number : 현재접속자 로그아웃

[root@localhost ~]# who
root pts/0        2022-11-01 14:54 (***.***.*.***)
tester1 pts/1        2022-11-01 14:54 (***.***.*.***)
tester2 pts/2        2022-11-01 14:54 (***.***.*.***)

[root@localhost ~]# skill -KILL pts/1

[root@localhost ~]# who
root pts/0        2022-11-01 14:54 (***.***.*.***)
tester2 pts/2        2022-11-01 14:54 (***.***.*.***)

[root@localhost ~]# skill -KILL tester2
root pts/0        2022-11-01 14:54 (***.***.*.***)

[root@localhost ~]# who
root pts/0        2022-11-01 14:54 (***.***.*.***)

 

last 사용자 : 사용자의 마지막 접속시간

[root@localhost ~]# last root
root pts/0        ***.***.*.***    Wed Nov  2 17:16   still logged in
root pts/0        ***.***.*.***    Wed Nov  2 10:45 - 10:52  (00:06)
root pts/0        ***.***.*.***    Tue Nov  1 14:54 - 15:09  (00:15)
root pts/0        ***.***.*.***    Tue Nov  1 14:09 - 14:12  (00:02)


// 전체
[root@localhost ~]# last
root pts/0        ***.***.*.***    Wed Nov  2 17:16   still logged in
root pts/0        ***.***.*.***    Wed Nov  2 10:45 - 10:52  (00:06)
root pts/0        ***.***.*.***    Tue Nov  1 14:54 - 15:09  (00:15)
root pts/0        ***.***.*.***    Tue Nov  1 14:09 - 14:12  (00:02)
tester pts/0        ***.***.*.***    Wed Nov  2 10:45 - 10:52  (00:06)
tester pts/0        ***.***.*.***    Tue Nov  1 14:54 - 15:09  (00:15)
tester pts/0        ***.***.*.***    Tue Nov  1 14:09 - 14:12  (00:02)


// 특정시간이전
[root@localhost ~]# last -t 20221025000000
root pts/0        ***.***.*.***    Wed Nov  2 17:16   still logged in
root pts/0        ***.***.*.***    Wed Nov  2 10:45 - 10:52  (00:06)
tester pts/0        ***.***.*.***    Tue Nov  1 14:09 - 14:12  (00:02)

 

2. 사용자 확인 및 관리

cat /etcpasswd : 사용자 목록

[root@localhost ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/cache/rpcbind:/sbin/nologin

// 아이디만 보기
[root@localhost ~]# cut -f1 -d: /etc/passwd
root
halt
mail
nobody
dbus
rpc

 

useradd 아이디 : 사용자추가

passwd 아이디 : 비밀번호 변경 (아이디 미입력시 로그인 사용자 비밀번호 변경)

[root@www home]# useradd tester
[root@www home]# passwd tester
tester 사용자의 비밀 번호 변경 중
새  암호:
새  암호 재입력:
passwd: 모든 인증 토큰이 성공적으로 업데이트 되었습니다.

 

userdel 아이디 : 사용자삭제

userdel 아이디 -r : 사용자삭제 (홈디렉토리 포함)

[root@www home]# userdel tester -r

 

반응형

댓글