[AIX 파헤치기] 유저와 그룹 관리 방법

반응형
[AIX 파헤치기] 유저와 그룹 관리 방법

안녕하세요, 우리노트 Benjamin 입니다.


오늘은 AIX 파헤치기 첫 시간으로 user 와 group에 대한 공부를 해보겠습니다.


AIX 에서 유저와 그룹에 대한 간단한 이해가 필요해서 회사로 빗대어 설명드리겠습니다. 아마 아래 설명은 oracle이나 linux등에도 비슷하게 적용 될테니 초심자 분들에게 도움이 되시리라 생각됩니다.


회사의 이름은 hostname 으로 확인이 가능합니다.

root@test:/> hostname

test


test라는 회사의 사장은 root 입니다.

test회사에는 system, bin, sys, security 등의 기본 부서가 있으며 추가로 생성 및 제거가 가능합니다.


mkgroup 라는 명령을 통해 부서를 더 생성하기도 하고

chgroup 라는 명령을 통해 부서를 개편하기도 하고

rmgroup 라는 명령을 통해 부서를 폐쇄하기도 합니다.


mkuser 라는 명령을 통해 신입사원을 뽑을 수 있으며

chuser 라는 명령을 통해 사원의 업무등을 변경 가능하고

rmuser 라는 명령을 통해 사원을 퇴사시킬 수 있습니다.


한사원은 적어도 하나의 부서에 속해야 하며 여러 부서에 속할 수도 있습니다.


이사회 부서(system)는 사장과 동등한 권한을 갖습니다.

이사회 부서는 mkgroup -a 로 생성이 가능합니다.


이사는 사장과 동등한 권한을 갖으며 mkuser -a 로 생성이 가능합니다.


각 사원은 개인 사무실을 갖습니다. (home directory)


각 사원과 부서는 고유 id를 부여 받습니다. (uid, gid)


동명의 사원과 동명의 부서는 생성이 불가능합니다.


초심자들을 위한 간단한 설명을 마치고 본론으로 들어가도록 하겠습니다. 만약 이해가 안되는 부분이 있으시면 댓글로 질문 남겨주시기 바랍니다.


현재 유저 정보 확인


root@test:/> whoami

root


현재 계정의 id 와 이름 및 그룹정보를 확인할 수 있습니다.

gid는 primary group 에 대한 정보이고 group는 그 외에 속한 그룹들의 정보입니다.

root@test:/> id

uid=0(root) gid=0(system) groups=2(bin),3(sys),7(security),8(cron),10(audit),11(lp),206(wheel)




특정 유저 정보 확인


우선 전체 유저의 정보를 확인하기 위해 ALL이라는 변수를 사용할 수 있습니다.

root@test:/> lsuser ALL

root id=0 pgrp=system groups=system,bin,sys,security,cron,audit,lp,wheel home=/ shell=/usr/bin/ksh auditclasses=files,SRC,kernel login=true su=true rlogin=false daemon=true admin=true sugroups=ALL admgroups=tes,KT,root,mysql,nastestg tpath=nosak ttys=ALL expires=0 auth1=SYSTEM auth2=NONE umask=22 registry=files SYSTEM=compat logintimes= loginretries=0 pwdwarntime=0 account_locked=false minage=0 maxage=0 maxexpired=-1 minalpha=0 minother=0 mindiff=0 maxrepeats=8 minlen=0 histexpire=0 histsize=0 pwdchecks= dictionlist= core_path=off time_last_login=1391408171 time_last_unsuccessful_login=1391395573 tty_last_login=ftp tty_last_unsuccessful_login=/dev/pts/1 host_last_login=::ffff:53.11.122.62 host_last_unsuccessful_login=192.26.3.55 unsuccessful_login_count=0 roles=

daemon id=1 pgrp=staff groups=staff home=/etc login=true su=true rlogin=true daemon=true admin=true sugroups=ALL admgroups= tpath=nosak ttys=ALL expires=0101000070 auth1=SYSTEM auth2=NONE umask=22 registry=files SYSTEM=compat logintimes= loginretries=0 pwdwarntime=0 account_locked=true minage=0 maxage=0 maxexpired=-1 minalpha=0 minother=0 mindiff=0 maxrepeats=8 minlen=0 histexpire=0 histsize=0 pwdchecks= dictionlist= core_path=off roles=

bin id=2 pgrp=bin groups=bin,sys,adm home=/bin shell=/bin/false login=true su=true rlogin=true daemon=true admin=true sugroups=ALL admgroups= tpath=nosak ttys=ALL expires=0101000070 auth1=SYSTEM auth2=NONE umask=22 registry=files SYSTEM=compat logintimes= loginretries=0 pwdwarntime=0 account_locked=true minage=0 maxage=0 maxexpired=-1 minalpha=0 minother=0 mindiff=0 maxrepeats=8 minlen=0 histexpire=0 histsize=0 pwdchecks= dictionlist= core_path=off roles=

생략..


특정 유저의 이름을 변수로하여 명령어를 입력하면 ALL에서 해당 유저의 정보만 나타나게 됩니다.

root@test:/> lsuser root

root id=0 pgrp=system groups=system,bin,sys,security,cron,audit,lp,wheel home=/ shell=/usr/bin/ksh auditclasses=files,SRC,kernel login=true su=true rlogin=false daemon=true admin=true sugroups=ALL admgroups=tes,KT,root,mysql,nastestg tpath=nosak ttys=ALL expires=0 auth1=SYSTEM auth2=NONE umask=22 registry=files SYSTEM=compat logintimes= loginretries=0 pwdwarntime=0 account_locked=false minage=0 maxage=0 maxexpired=-1 minalpha=0 minother=0 mindiff=0 maxrepeats=8 minlen=0 histexpire=0 histsize=0 pwdchecks= dictionlist= core_path=off time_last_login=1391408171 time_last_unsuccessful_login=1391395573 tty_last_login=ftp tty_last_unsuccessful_login=/dev/pts/1 host_last_login=::ffff:53.11.122.62 host_last_unsuccessful_login=192.26.3.55 unsuccessful_login_count=0 roles=


조금 더 보기 좋게 -f 옵션을 주어 보았습니다.

root@test:/> lsuser -f root

root:

id=0

pgrp=system

groups=system,bin,sys,security,cron,audit,lp,wheel

home=/

shell=/usr/bin/ksh

auditclasses=files,SRC,kernel

login=true

생략…


몇가지만 설명 드리자면 기본 그룹(pgrp), 원격접속 허용여부(rlogin), 패스워드 정책(minage,maxage,maxexpired…), 로그인 실패기록(host_last_unsuccessful_login), 파일생성시 권한설정(umask), admin 역할 수행여부(admin) 등의 다양한 설정값들을 확인 하실 수 있습니다. 


각 변수의 정확한 역할을 알기 원하시면 AIX에서 #man user 명령을 사용하시거나 IBM AXI information center 에서 user File 로 검색 해보시기 바랍니다.


그룹 정보 확인


그룹정보 확인 방법 역시 유저정보와 동일합니다.

root@test:/> lsgroup ALL

system id=0 admin=true users=root,esaadmin,testuser,pconsole,admin adms= registry=files

staff id=1 admin=false users=ipsec,esaadmin,oracle,dba,test1,test2,test3,backadm adms= registry=files

bin id=2 admin=true users=root,bin registry=files

sys id=3 admin=true users=root,bin,sys registry=files

adm id=4 admin=true users=bin,adm,tsim,sjsjsj registry=files

uucp id=5 admin=true users=nuucp,uucp registry=files

mail id=6 admin=true users= registry=files

생략...


root@test:/> lsgroup system

system id=0 admin=true users=root,esaadmin,testuser,pconsole,admin adms= registry=files


root@test:/> lsgroup bin

bin id=2 admin=true users=root,bin registry=files


그룹 생성


testgrp 그룹이 존재하지 않는 것을 확인 후 생성해 보았습니다.

root@test:/> lsgroup testgrp

Group "testgrp" does not exist.


root@test:/> mkgroup testgrp


id 213번으로 admin 권한이 없이 만들어 졌습니다.

root@test:/> lsgroup testgrp

testgrp id=213 admin=false users= registry=files


root@test:/> rmgroup testgrp


다시 생성해보면 앞에 group이 삭제되었지만 다음 번호인 214로 생성되는 것을 확인 할 수 있습니다.

root@test:/> mkgroup testgrp


root@test:/> lsgroup testgrp

testgrp id=214 admin=false users= registry=files


-a 옵션으로 admin 권한을 주어 생성하면 id가 앞쪽으로 생성되어지는 것을 확인 할 수 있습니다. admin 역할의 그룹에게는 앞 번호를 주게 설정되어 있는 것 같습니다.

root@test:/> mkgroup -a testAgrp


root@test:/> lsgroup testAgrp

testAgrp id=15 admin=true users= registry=files


참고로 이름이 너무 길면 생성이 되지 않는군요

root@test:/> mkgroup -a testadmgrp

Error adding "testadmgrp" : Name is too long.


유저 생성


이번에는 유저를 생성해보도록 하겠습니다.

일반 유저와 admin 유저(-a) 를 각각 생성하였습니다.

root@test:/> mkuser ourtest1

root@test:/> mkuser -a ourtest2


역시 admin 계정은 id가 앞번호로 생성되며 group역시 자동으로 system 과 staff로 각각 생성되는 것을 볼 수 있습니다.

root@test:/> lsuser ourtest1

ourtest1 id=275 pgrp=staff groups=staff home=/home/ourtest1 shell=/usr/bin/ksh login=true su=true rlogin=true daemon=true admin=false sugroups=ALL admgroups= tpath=nosak ttys=ALL expires=0 auth1=SYSTEM auth2=NONE umask=22 registry=files SYSTEM=compat logintimes= loginretries=0 pwdwarntime=0 account_locked=false minage=0 maxage=0 maxexpired=-1 minalpha=0 minother=0 mindiff=0 maxrepeats=8 minlen=0 histexpire=0 histsize=0 pwdchecks= dictionlist= core_path=off roles=


root@test:/> lsuser ourtest2

ourtest2 id=33 pgrp=system groups=system home=/home/ourtest2 shell=/usr/bin/ksh login=true su=true rlogin=true daemon=true admin=true sugroups=ALL admgroups= tpath=nosak ttys=ALL expires=0 auth1=SYSTEM auth2=NONE umask=22 registry=files SYSTEM=compat logintimes= loginretries=0 pwdwarntime=0 account_locked=false minage=0 maxage=0 maxexpired=-1 minalpha=0 minother=0 mindiff=0 maxrepeats=8 minlen=0 histexpire=0 histsize=0 pwdchecks= dictionlist= core_path=off roles=


유저를 그룹에 할당


유저 ourtest1 은 그룹 staff 만 속해 있습니다.

root@test:/> lsuser ourtest1

ourtest1 id=275 pgrp=staff groups=staff home=/home/ourtest1 shell=/usr/bin/ksh login=true su=true rlogin=true daemon=true admin=false sugroups=ALL admgroups= tpath=nosak ttys=ALL expires=0 auth1=SYSTEM auth2=NONE umask=22 registry=files SYSTEM=compat logintimes= loginretries=0 pwdwarntime=0 account_locked=false minage=0 maxage=0 maxexpired=-1 minalpha=0 minother=0 mindiff=0 maxrepeats=8 minlen=0 histexpire=0 histsize=0 pwdchecks= dictionlist= core_path=off roles=


유저 ourtest1 이 그룹 system,staff,testgrp,testAgrp 에 속하도록 변경해보겠습니다.

root@test:/> chuser groups=system,staff,testgrp,testAgrp ourtest1


잘 변경된 것을 확인 할 수 있습니다. 나머지 값들에 대해서도 # chuser Value=변경할값 ourtest1 과 같은 방식으로 변경하시면 됩니다.

root@test:/> lsuser ourtest1

ourtest1 id=275 pgrp=staff groups=staff,system,testgrp,testAgrp home=/home/ourtest1 shell=/usr/bin/ksh login=true su=true rlgin=true daemon=true admin=false sugroups=ALL admgroups= tpath=nosak ttys=ALL expires=0 auth1=SYSTEM auth2=NONE umask=22 regstry=files SYSTEM=compat logintimes= loginretries=0 pwdwarntime=0 account_locked=false minage=0 maxage=0 maxexpired=-1 minalha=0 minother=0 mindiff=0 maxrepeats=8 minlen=0 histexpire=0 histsize=0 pwdchecks= dictionlist= core_path=off roles=


그룹에 유저를 할당


이번엔 역으로 그룹에서 유저를 할당해 보겠습니다.

root@test:/> lsgroup testAgrp

testAgrp id=15 admin=true users=ourtest1 registry=files


다음은 ourtest2를 testAgrp 에 소속시키려다가 실수로 ourtest1이 그룹에서 제외되버린 잘못된 예입니다.

꼭 기존의 유저정보들을 기입하고 추가시킬 유저이름을 함께 기입하셔야 합니다.

root@test:/> chgroup users=ourtest2 testAgrp


root@test:/> lsgroup testAgrp

testAgrp id=16 admin=true users=ourtest2 registry=files


다시 제대로 명령을 수행하면 다음과 같이 됩니다.

root@test:/> chgroup users=ourtest1,ourtest2 testAgrp


root@test:/> lsgroup testAgrp

testAgrp id=16 admin=true users=ourtest1,ourtest2 registry=files


그룹을 생성하면서 유저를 할당


위에서는 이미 생성된 유저와 그룹을 서로 매칭시키는 방법을 알아보았습니다. 이번에는 그룹이나 유저를 생성과 동시에 매칭시키는 방법을 알아보겠습니다. 명령어 형식이 chgroup 와 크게 다르지 않습니다.

root@test:/> mkgroup users=ourtest2 testgrp2


root@test:/> lsgroup testgrp2

testgrp2 id=215 admin=false users=ourtest2 registry=files


유저를 생성하면서 그룹에 할당


유저를 생성하면서 그룹에 할당시키는 것 역시 chuser 명령어와 크게 다르지 않습니다.

root@test:/> mkuser groups=testgrp ourtest3


root@test:/> lsuser ourtest3

ourtest3 id=276 pgrp=staff groups=staff,testgrp home=/home/ourtest3 shell=/usr/bin/ksh login=true su=true rlogin=true daemon=true admin=false sugroups=ALL admgroups= tpath=nosak ttys=ALL expires=0 auth1=SYSTEM auth2=NONE umask=22 registry=files SYSTEM=compat logintimes= loginretries=0 pwdwarntime=0 account_locked=false minage=0 maxage=0 maxexpired=-1 minalpha=0 minother=0 mindiff=0 maxrepeats=8 minlen=0 histexpire=0 histsize=0 pwdchecks= dictionlist= core_path=off roles=


유저 및 그룹 삭제


유저 삭제는 rmuser 명령을 사용합니다.

root@test:/> rmuser ourtest1


root@test:/> lsuser ourtest1

User "ourtest1" does not exist.


그룹 삭제는 rmgroup 명령을 사용합니다.

root@test:/> rmgroup testgrp


root@test:/> lsgroup testgrp

Group "testgrp" does not exist.


유저가 삭제되고 나면 그룹에서는 자동으로 제거 됩니다. 유저를 모두 삭제하고 나니 users= 부분이 공백으로 나오는 것을 확인 할 수 있습니다.

root@test:/> lsgroup testAgrp

testAgrp id=16 admin=true users= registry=files


root@test:/> rmgroup testAgrp


root@test:/> lsgroup testAgrp

Group "testAgrp" does not exist.


잘못된 이름으로 삭제 명령을 하였을 경우는 에러 메시지가 발생합니다.

root@test:/> rmgroup nomkgrp

Group "nomkgrp" does not exist.


root@test:/> rmuser nomkuser

User "nomkuser" does not exist.


없는 이름이라면 상관 없지만 실수로 존재하는 이름을 삭제하는 경우 묻지 않고 바로 삭제하기 때문에 주의하셔야 합니다.


홈디렉토리제거


참고로 유저 생성시 유저의 홈 디렉토리 정보는 자동 생성된뒤 삭제시 자동 삭제 되지 않으므로 직접 삭제 해주셔야 합니다.

root@test:/> cd home

root@test:/home> ls | grep our

ourtest1

ourtest2

ourtest3


삭제 명령은 rm 이며 아래와 같이 awk 문을 사용하면 한번에 여러 명령을 스크립트로 수행할 수 있습니다. Rm 명령어와 awk 명령어에 대해서는 다음 기회에 다루도록 하겠습니다.

root@test:/home> ls |grep our |awk '{print "rm -r "$1}' | sh



누군가에게 유용한 정보가 되었기를 기대하며 [AIX 파헤치기] 유저와 그룹 관리 방법에 대한 글을 마칩니다.


댓글

Designed by JB FACTORY