5/10 사용자 및 그룹 관리
- -
저번주 가상머신 네트워크 :
NAT : 외부0, HOST X, GUEST X
VM1 ----- NAT AD-----> HOST ----->
VM2 ----- NAT AD----->|
VM3 ----- NAT AD----->|
NAT NETWORK : 외부0 HOST X, GUEST 0
VM1 ----- NAT AD-----> HOST ----->
VM2 -------|
VM3 -------|
BRIDGE : 외부 0, GUEST 0, HOST 0
HOST ------------공유기
VM1 ---------|
VM2 ---------|
VM3 ---------|
HOST-ONLY : 외부 X, GUEST 0, HOST 0
VM1 <--- --> HOST AD <-----> HOST
VM2 <--------->|
VM3 <--------->| FIND
명령어 다시 해야됨. sudo systemctl set-default multi-user.target dkagh1.
access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/
Product Documentation for Red Hat Enterprise Linux 7 - Red Hat Customer Portal
The Red Hat Customer Portal delivers the knowledge, expertise, and guidance available through your Red Hat subscription.
access.redhat.com
*사용자는 시스템에서 계정(UID)를 할당 받아 로그인 가능
리눅스의 모든 파일 및 디렉토리는 특정사용자에 의해 소유됨
모든 프로세스는 특정사용자에 의해서 실행됨
*사용자 확인 명령어
ps au 프로세스를 사용중인 사용자 확인 가능
ls -l 파일 및 디렉토리의 소유자 확인 가능
id
사용자 정보는 /etc/passwd/에 저장
*그룹이란?
사용자와 마찬가지로 이름과 번호(GID)가 있음. /etc/group/파일에 정보저장
- 기본그룹
사용자는 무조건 하나의 기본그룹을 소유하고있음(사용자 생성시 자동생성)
기본그룹은 /etc/passwd 파일의 네번째 필드 GID로 식별
사용자가 파일을 생성하면 해당파일의 소유그룹이 됨
*보조그룹
반드시 속해있지않아도 ㄱㅊ
사용자 파일에 대한 권한을 확인하는데 사용됨
/etc/group/ 파일의 마지막 필드에 보조그룹 구성원 표시(쉽표로 구분)
슈퍼유저 엑세스 권한 취득
*root사용자
UID가 0인 사용자
시스템에대한 모든 권한 소유
파일 및 디렉토리에 대한 소유자의 권한 수정할수있음
모든권한 가지고 있어서 패스워드 유출시 위험
*su로 사용자 전환
su [user]
[user]로 사용자 전환
[user]가 지정되지 않으면 root로 전환
*su - 로 사용자 전환
su - [user]
해당사용자의 환경설정까지 전환
사용자전환시 pwd는 홈 디렉토리
*sudo를 시용하여 root로 실행
sudo [command]
윈도우의 관리자 권한 실행과 같음
사용자 해당계정의 패스워드만 필요
su를 사용하여 root전환시 root의 패스워드 필요
wheel그룹의 구성원만 sudo명령어 사용할수있음
/var/log/secure/ 에 명령어 사용흔적이 기록됨
로컬 사용자 계정 관리
userdel [option] [username] 사용자 제거
ㄴ -r : 사용자를 제거할때 사용자의 홈 디렉토리까지 같이 제거
.......
*/etc/passwd
ex) ntp:x:38:48: : /etc/ntp:/sbin/nologin
ntp: 사용자이름
x: 안쓰는 기능은 비워서 x로 표시한것
38: UID값
48: GID값(Group ID)
etc: 설명(비워있어도 ㄱㅊ)
/ntp:/sbin/nologin : user의 home dir
/sbin/nologin : user가 사용하는 쉘(ex) bin/bash/), 로그인이 안되는 계정이라는 의미(계정인데 쉘이 없음)
*/etc/group
ex) root:x:0:
ㄴ x: 비밀번호 (안쓰니까 x)
0: GID
wheel:x:10:user01
ㄴ wheel: 그룹이름
user01: 보조그룹
FIND 명령어 다시 해야됨.
sudo systemctl set-default multi-user.target
dkagh1.
host only
nat???
nmcli con up enp0s8
ifconfig
enp0s8 주소 확인
ubuntu 터미널 -> ssh user@<vm의 enp0s8 주소>
sudo apt-get install -y qemu-kvm libvirt-daemon-system virtinst bridge-utils cpu-checker
sudo adduser student kvm
sudo kvm-ok
sudo apt-get install virt-manager
reboot
centos7.kcow2
user/user
root/toor
[user@localhost ~]$ su - user
Password:
Last login: Mon May 10 13:35:36 KST 2021 on pts/0
[user@localhost ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/user/.local/bin:/home/user/bin
?????
ls -> $PATH 에 존재하는지 확인
-------------------------------------
[user@localhost ~]$ useradd cccr1
useradd: Permission denied.
useradd: cannot lock /etc/passwd; try again later.
[user@localhost ~]$ su -
Password:
Last login: Mon May 10 13:21:52 KST 2021 on pts/0
[root@localhost ~]# useradd cccr1
[root@localhost ~]# tail /etc/passwd
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
chrony:x:998:996::/var/lib/chrony:/sbin/nologin
user:x:1000:1000:user:/home/user:/bin/bash
cccr1:x:1001:1001::/home/cccr1:/bin/bash
[root@localhost ~]# tail -1 /etc/passwd
cccr1:x:1001:1001::/home/cccr1:/bin/bash
[root@localhost ~]# su cccr1
[cccr1@localhost root]$ ls
ls: cannot open directory .: Permission denied
[cccr1@localhost root]$ cd ~
[cccr1@localhost ~]$ pwd
/home/cccr1
[cccr1@localhost ~]$ su -
Password:
Last login: Mon May 10 13:42:40 KST 2021 on pts/0
[root@localhost ~]# su - cccr1
Last login: Mon May 10 13:44:39 KST 2021 on pts/0
[cccr1@localhost ~]$ su --help
Usage:
su [options] [-] [USER [arg]...]
Change the effective user id and group id to that of USER.
A mere - implies -l. If USER not given, assume root.
Options:
-m, -p, --preserve-environment do not reset environment variables
-g, --group <group> specify the primary group
-G, --supp-group <group> specify a supplemental group
-, -l, --login make the shell a login shell
-c, --command <command> pass a single command to the shell with -c
--session-command <command> pass a single command to the shell with -c
and do not create a new session
-f, --fast pass -f to the shell (for csh or tcsh)
-s, --shell <shell> run shell if /etc/shells allows it
-h, --help display this help and exit
-V, --version output version information and exit
[cccr1@localhost ~]$ id
uid=1001(cccr1) gid=1001(cccr1) groups=1001(cccr1) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[cccr1@localhost ~]$ pwd
/home/cccr1
[cccr1@localhost ~]$ echo $HOME
/home/cccr1
[cccr1@localhost ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/cccr1/.local/bin:/home/cccr1/bin
[cccr1@localhost ~]$ exit
logout
[root@localhost ~]# su -
Last login: Mon May 10 13:45:23 KST 2021 on pts/0
[root@localhost ~]# su cccr1
[cccr1@localhost root]$ id
uid=1001(cccr1) gid=1001(cccr1) groups=1001(cccr1) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[cccr1@localhost root]$ pwd
/root
[cccr1@localhost root]$ echo $HOME
/home/cccr1
[cccr1@localhost root]$ echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[cccr1@localhost root]$ sudo tail /var/log/messages
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for cccr1:
sudo: 1 incorrect password attempt
[cccr1@localhost root]$ su -
Password:
Last login: Mon May 10 13:47:49 KST 2021 on pts/0
Last failed login: Mon May 10 13:49:51 KST 2021 on pts/0
There was 1 failed login attempt since the last successful login.
[root@localhost ~]# tail /var/log/messages
May 10 13:28:21 localhost nm-dispatcher: req:1 'dhcp4-change' [eth0]: start running ordered scripts...
May 10 13:35:36 localhost su: (to user) user on pts/0
May 10 13:36:36 localhost su: (to user) user on pts/0
May 10 13:42:40 localhost su: (to root) user on pts/0
May 10 13:44:39 localhost su: (to cccr1) user on pts/0
May 10 13:45:23 localhost su: (to root) user on pts/0
May 10 13:45:30 localhost su: (to cccr1) user on pts/0
May 10 13:47:49 localhost su: (to root) user on pts/0
May 10 13:47:55 localhost su: (to cccr1) user on pts/0
May 10 13:49:51 localhost su: FAILED SU (to root) user on pts/0
May 10 13:49:54 localhost dhclient[799]: DHCPREQUEST on eth0 to 192.168.122.1 port 67 (xid=0x208ba53e)
May 10 13:49:55 localhost su: (to root) user on pts/0
useradd 계정생성
su -> 이전 사용자의 $PATH 를 상속받음
su - -> login 사용자의 $PATH를 사용한다.
로그인 내역은 /var/log/messages 에 저장된다.
useradd --help
userdel
cccr3 계정을 생성하시오. 홈디렉토리는 /home/guest 쉘은 /bin/sh 로 로그인되게 생성하시오.
su - cccr3 $HOME -> /home/guest
[root@localhost user]# su - cccr3
su: user cccr3 does not exist
[root@localhost user]# useradd -d /home/guest -s /bin/sh cccr3
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Creating mailbox file: File exists
[root@localhost user]# su - cccr3
-sh-4.2$ exit
logout
[root@localhost user]# usermod --help
Usage: usermod [options] LOGIN
Options:
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-a, --append append the user to the supplemental GROUPS
mentioned by the -G option without removing
the user from other groups
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-L, --lock lock the user account
-m, --move-home move contents of the home directory to the
new location (use only with -d)
-o, --non-unique allow using duplicate (non-unique) UID
-p, --password PASSWORD use encrypted password for the new password
-R, --root CHROOT_DIR directory to chroot into
-P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files
-s, --shell SHELL new login shell for the user account
-u, --uid UID new UID for the user account
-U, --unlock unlock the user account
-v, --add-subuids FIRST-LAST add range of subordinate uids
-V, --del-subuids FIRST-LAST remove range of subordinate uids
-w, --add-subgids FIRST-LAST add range of subordinate gids
-W, --del-subgids FIRST-LAST remove range of subordinate gids
-Z, --selinux-user SEUSER new SELinux user mapping for the user account
[root@localhost user]#
cccr3 의 계정을 uid 2010,보조그룹에 wheel을 추가해보세요.
[root@localhost user]# usermod --help
Usage: usermod [options] LOGIN
Options:
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-a, --append append the user to the supplemental GROUPS
mentioned by the -G option without removing
the user from other groups
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-L, --lock lock the user account
-m, --move-home move contents of the home directory to the
new location (use only with -d)
-o, --non-unique allow using duplicate (non-unique) UID
-p, --password PASSWORD use encrypted password for the new password
-R, --root CHROOT_DIR directory to chroot into
-P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files
-s, --shell SHELL new login shell for the user account
-u, --uid UID new UID for the user account
-U, --unlock unlock the user account
-v, --add-subuids FIRST-LAST add range of subordinate uids
-V, --del-subuids FIRST-LAST remove range of subordinate uids
-w, --add-subgids FIRST-LAST add range of subordinate gids
-W, --del-subgids FIRST-LAST remove range of subordinate gids
-Z, --selinux-user SEUSER new SELinux user mapping for the user account
[root@localhost user]# usermod -aG wheel cccr3
[root@localhost user]# id cccr3
uid=1003(cccr3) gid=1003(cccr3) groups=1003(cccr3),10(wheel)
[root@localhost user]# usermod --help
Usage: usermod [options] LOGIN
Options:
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-a, --append append the user to the supplemental GROUPS
mentioned by the -G option without removing
the user from other groups
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-L, --lock lock the user account
-m, --move-home move contents of the home directory to the
new location (use only with -d)
-o, --non-unique allow using duplicate (non-unique) UID
-p, --password PASSWORD use encrypted password for the new password
-R, --root CHROOT_DIR directory to chroot into
-P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files
-s, --shell SHELL new login shell for the user account
-u, --uid UID new UID for the user account
-U, --unlock unlock the user account
-v, --add-subuids FIRST-LAST add range of subordinate uids
-V, --del-subuids FIRST-LAST remove range of subordinate uids
-w, --add-subgids FIRST-LAST add range of subordinate gids
-W, --del-subgids FIRST-LAST remove range of subordinate gids
-Z, --selinux-user SEUSER new SELinux user mapping for the user account
[root@localhost user]# usermod -u 2010 cccr3
sudo : super user 의 권한대행
userdel : r 옵션의 유무에 따른 차이점 존재
10 userdel -r cccr1
/etc/shadow 파일
- passwd 를 저장해 두는곳
user:$6$TnOJrvVXvEokzqJs$1oSBnlfaE2loyMdU9akf08cJIv.wAfOrCHsr8UBlPUUFGmTycGlbnd1zfm/wWkWqrKbLewvo28.JiaOkb3a8S.::0:99999:7:::
$6$ : SHA-256 으로 암호화
$1$ : MD 5 방식으로 암호화
TnOJrvVXvEokzqJs$ : salt 임의로 선택되는값
$1oSBnlfaE2loyMdU9akf08cJIv.wAfOrCHsr8UBlPUUFGmTycGlbnd1zfm/wWkWqrKbLewvo28.JiaOkb3a8S
: 암호화된 passwd
사용자 passwd 지정 -> salt + <사용자 지정 pw> -> 암호화 ->
charg -d 0 <계정명>
[root@localhost ~]# vi ~/.bash_logout
rm -rf .~~ 삭제
-----------------------------------------------------------
no login
9 usermod -s /sbin/nologin test_passwd
10 cat /etc/passwd
--------------------------------
특수권한
파일 디렉토리
set uid 소유자 권한으로 실행??? XXXX chmod u+s
set gid 소유 그룹의 권한으로 실행 ??????? chmod g+s
sticky bit x 해당 디렉토리에서 파일 삭제시 본인 소유의 파일 삭제가능 chmod o+t
user -> passwd(user) -> (root)패스워드 변경 -> /etc/shadow update
SetUid
- 바이너리 또는 스크립트 파일에 적용한다.
- 실행한 사용자가 아닌 파일소유자의 권한으로 실행된다.
- 실행 권한이 x대신 s로 표시 된다.
----------------------------------------------------------
예제
/usr/bin/passwd 파일 의 setuid 확인
chmod u-s 와 u+s 의 차이점 확인
예제2
[root@localhost ~]# cat /tmp/test.sh
#!/bin/bash
echo "hello world"
파일생성후 기타사용자 소유자 등의 실행권한 부여에 따른 차이점 확인
SetGid
- 일반적으로 디렉토리에 설정하고 사용하는 경우가 많다.
- 주로 데몬프로세스가 사용하는 그룹의 권한을 공유하기 위해 사용한다.
/run/log/journal
에서 root 사용자로 파일 생성 -> 소유 그룹의 권한은??
chmod g-s /run/log/journal
에서 root 사용자로 파일 생성 -> 소유 그룹의 권한은??
Sticky bit
- 디렉토리에 기타사용자 권한이 RWX인 경우 모든 사용자가 해당디렉토리에서 파일을 생성 및 삭제 가능
- 파일 생성 및 read는 문제 없지만 삭제는 문제가 발생함
- sticky bit 설정시 파일 생성 가능 but 다른사용자의 파일은 삭제 불가능
/tmp or /var/tmp 는 sticky bit 부여된 디렉토리
user01 생성후 /tmp/fileA생성 ->
user 은 /tmp/fileA 삭제 가능????
chmod o-t /tmp/ 이후 user 은 /tmp/fileA 삭제 가능????
==========================================
'Linux' 카테고리의 다른 글
5/11 스케줄링(crontab ..) (0) | 2021.05.11 |
---|---|
5/11 접근제어리스트(ACL) 설정 관리 (0) | 2021.05.11 |
5/6 리눅스 기초 3 (0) | 2021.05.06 |
5/6 Umask (0) | 2021.05.06 |
5/4 리눅스 기초 실습 (0) | 2021.05.04 |
소중한 공감 감사합니다