본문 바로가기

CentOS/Study

[사용자계정관리]su

반응형

<su>

시스템에 로그인되어 있는 상태에서 다른 사용자의 권한으로 셸을 실행 할 수 있도록 전환

원격 접속시에 다른 사용자로 로그인하기 위해 로그아웃하면 접속이 종료가 되는데 접속이 종료 되지 않은 상태에서 

다른 사용자로 로그인하고자 할 때 사용한다.
한명의 관리자가 여러 계정을 사용하는 경우 유용하다.
일반 사용자가 다른 사용자가 되는 것을 권한이 높아지는 것이기 때문에 전환(Switching) 되는 사용자의 암호를

맞추어야만 전환이 가능하고, root 사용자가 다른사용자로 전환하는 경우에는 권한이 낮아지는 것이기 때문에

암호입력 없이 전환이 가능하다.

su 명령어 다음에 전환하고 싶은 사용자 이름이 없는 경우 root 사용자로 전환된다. 
그리고 su 명령어에 '-' 기호 없이 다른 사용자로 전환하는 경우 지정된 사용자로 전환이 되지만 이전 사용자가 쓰고

있던 export 변수들의 설정이 그대로 따라온다.

su 명령어에 '-' 기호를 붙이고 다른 사용자로 전환하는 경우 지정된 사용자로 새로 로그인한 것 처럼 동작을 시켜서

사용자 환경변수로 모두 변경한다.

 

[root@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

For more details see su(1).

 

1. su 사용자 전환

[root@localhost ~]# cd /etc
[root@localhost etc]# pwd
/etc
[root@localhost etc]# su user01
[user01@localhost etc]$ id
uid=1001(user01) gid=1001(user01) groups=1001(user01) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[user01@localhost etc]$ pwd
/etc

 

2. su - 사용장 전환

[root@localhost ~]# cd /etc
[root@localhost etc]# pwd
/etc
[root@localhost etc]# su - user01
Last login: Sun Mar 13 14:17:41 KST 2022 on pts/0
[user01@localhost ~]$ id
uid=1001(user01) gid=1001(user01) groups=1001(user01) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[user01@localhost ~]$ pwd
/home/user01

 

3. 권한 테스트

[root@localhost etc]# cat /etc/shadow
root:$6$FR.3aQKfK.X1B54b$twsZIZknZj9NNixQ.ogWaaPm.MFzwmAPtZOwTL6foh8UJh/c9PXVno5Y3IKSSiX2UZW4CBaWQYD0hIzdwAuOa.:18840:0:99999:7:::
bin:*:16231:0:99999:7:::
daemon:*:16231:0:99999:7:::
adm:*:16231:0:99999:7:::
lp:*:16231:0:99999:7:::
sync:*:16231:0:99999:7:::
shutdown:*:16231:0:99999:7:::
halt:*:16231:0:99999:7:::
mail:*:16231:0:99999:7:::
operator:*:16231:0:99999:7:::
games:*:16231:0:99999:7:::
ftp:*:16231:0:99999:7:::
nobody:*:16231:0:99999:7:::
dbus:!!:18840::::::
polkitd:!!:18840::::::
abrt:!!:18840::::::
usbmuxd:!!:18840::::::
unbound:!!:18840::::::
colord:!!:18840::::::
ntp:!!:18840::::::
avahi:!!:18840::::::
avahi-autoipd:!!:18840::::::
saslauth:!!:18840::::::
qemu:!!:18840::::::
libstoragemgmt:!!:18840::::::
rpc:!!:18840:0:99999:7:::
rpcuser:!!:18840::::::
nfsnobody:!!:18840::::::
rtkit:!!:18840::::::
radvd:!!:18840::::::
chrony:!!:18840::::::
pulse:!!:18840::::::
gdm:!!:18840::::::
gnome-initial-setup:!!:18840::::::
postfix:!!:18840::::::
sshd:!!:18840::::::
tcpdump:!!:18840::::::
ankiwoong:$6$llTOrv1Ci$5fr/XsWNJDuE29x8Z./TQAM.58uTB1VMvivRfvmKg/iMBIHCDnpsqfsEij1G9xq6BqovlxHBtsNkf6gbQbZie0:18840:0:99999:7:::
user01:$6$/lUgEgM8$ry9QnzIuP8RozhNx039GuK/GMy90UBkjhUVZT7.iq9X7gQTruzC8EneKH3h0FjR17TlbS0yTFK0fKaH1T04AY0:19064:0:99999:7:::
[root@localhost etc]# su - user01
Last login: Sun Mar 13 14:19:39 KST 2022 on pts/0
[user01@localhost ~]$ cat /etc/shadow
cat: /etc/shadow: Permission denied

 

4. 사용자를 전환하지 않고 root의 권한으로 shadow 파일 확인

[user01@localhost ~]$ su root -c "cat /etc/shadow"
Password:
root:$6$FR.3aQKfK.X1B54b$twsZIZknZj9NNixQ.ogWaaPm.MFzwmAPtZOwTL6foh8UJh/c9PXVno5Y3IKSSiX2UZW4CBaWQYD0hIzdwAuOa.:18840:0:99999:7:::
bin:*:16231:0:99999:7:::
daemon:*:16231:0:99999:7:::
adm:*:16231:0:99999:7:::
lp:*:16231:0:99999:7:::
sync:*:16231:0:99999:7:::
shutdown:*:16231:0:99999:7:::
halt:*:16231:0:99999:7:::
mail:*:16231:0:99999:7:::
operator:*:16231:0:99999:7:::
games:*:16231:0:99999:7:::
ftp:*:16231:0:99999:7:::
nobody:*:16231:0:99999:7:::
dbus:!!:18840::::::
polkitd:!!:18840::::::
abrt:!!:18840::::::
usbmuxd:!!:18840::::::
unbound:!!:18840::::::
colord:!!:18840::::::
ntp:!!:18840::::::
avahi:!!:18840::::::
avahi-autoipd:!!:18840::::::
saslauth:!!:18840::::::
qemu:!!:18840::::::
libstoragemgmt:!!:18840::::::
rpc:!!:18840:0:99999:7:::
rpcuser:!!:18840::::::
nfsnobody:!!:18840::::::
rtkit:!!:18840::::::
radvd:!!:18840::::::
chrony:!!:18840::::::
pulse:!!:18840::::::
gdm:!!:18840::::::
gnome-initial-setup:!!:18840::::::
postfix:!!:18840::::::
sshd:!!:18840::::::
tcpdump:!!:18840::::::
ankiwoong:$6$llTOrv1Ci$5fr/XsWNJDuE29x8Z./TQAM.58uTB1VMvivRfvmKg/iMBIHCDnpsqfsEij1G9xq6BqovlxHBtsNkf6gbQbZie0:18840:0:99999:7:::
user01:$6$/lUgEgM8$ry9QnzIuP8RozhNx039GuK/GMy90UBkjhUVZT7.iq9X7gQTruzC8EneKH3h0FjR17TlbS0yTFK0fKaH1T04AY0:19064:0:99999:7:::
반응형

'CentOS > Study' 카테고리의 다른 글

[사용자관련파일]/etc/passwd  (0) 2022.03.14
[사용자관련파일]/etc/shadow  (0) 2022.03.14
[사용자계정관리]passwd  (0) 2022.03.13
[사용자관련파일]skel  (0) 2022.03.13
[사용자계정관리]useradd  (0) 2022.03.13