UNIX/Redhat

Linux 관리자 단기집중과정 -중급 2일차

99iberty 2018. 7. 13. 09:35


8장

system-config-authentication : RHEL 4,5,6

authconfig                             : RHEL 7 (CLI/TLI)

authconfig-gtk                       : RHEL 7 (GLI) / 기본설치가 아니라 yum으로 설치 필요

# yum -y install authconfig-gtk


8장 먼저 하려나봐...


# authconfig-gtk

로 Authentication configuration 창 소환

  LDAP설정1.png / LDAP설정2.png



[root@station7 ~]# getent passwd dsuser11
dsuser11:*:2011:2011:dsuser11:/export/home/dsuser11:/bin/bash
   ---> 이렇게 잘 뜨면 LDAP 인증 / 정보 잘 가져와진다는 의미.


[root@station7 ~]# ssh dsuser11@localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is 45:c9:f4:fb:6c:03:b6:d3:e9:67:c5:3f:37:57:9a:8a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
dsuser11@localhost's password:
Last failed login: Thu Jul 12 19:18:08 MDT 2018 from localhost on ssh:notty
There was 1 failed login attempt since the last successful login.
Could not chdir to home directory /export/home/dsuser11: No such file or directory
-bash-4.2$ id
uid=2011(dsuser11) gid=2011(dsuser11) groups=2011(dsuser11) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
-bash-4.2$ pwd
/
-bash-4.2$





6장 Control access to files with linux file system permissions


1. File and Directory Permissions

lrwxrwxrwx. 1 root root           4 Jul 12 18:21 rtc -> rtc0  ---> 심볼릭 링크
crw-------. 1 root root    253,   0 Jul 12 18:21 rtc0        ----> 캐릭터 디바이스 (버퍼를 사용하지 않음, 터미널등)
brw-rw----. 1 root disk      8,   0 Jul 12 18:21 sda          ---> 블럭 디바이스 (버퍼를 사용해서 입출력 빠르게 하기 위해 사용하는 장치들)

srwxrwxrwx. 1 root root           0 Jul 12 18:21 gpmctl   ----> 소켓

p xxxxx                                                                                   ----> 파이프


drwxr-xr-x. 2 root root    6 Jul 12 03:30 Desktop       --- > 기본적으로 부모랑 나 자신이 연결되어 있기 때문에 디렉토리 연결개수 2개.

                                                                                                     여기 개수에서 2개 빼면 하위 디렉토리 개수 계산 가능.


- 파일에 w권한        : 파일의 컨텐츠를 write 가능. 파일을 삭제할 수 있냐 없냐는 해당 파일이 들어가 있는 상위 디렉토리에 대해 w권한이 있을때 가능.

- 디렉토리에 w권한 : 해당 디렉토리에 파일을 생성/삭제할 수 있는 권한.

- 디렉토리에 r 권한  : 디렉토리 내 파일 리스팅 가능.

- 디렉토리에 x 권한 : 파일이나 파일메타데이터(타임스탬프, 퍼미션등)에 액세스 가능. also, allows a directory to be the current working directory.


2. 특수퍼미션

- SUID          :  해당 프로그램의 소유자 권한으로 실행된다.

- SGID          : 해당 소유그룹의 구성원이 아니어도, 구성원인것처럼 동작해서 권한을 받고 처리한다.

                         디렉토리에도 SGID를 설정할 수 있는데, 파일일때랑 의미가 달라진다. 목적이 공유목적으로 쓰인다.

- Sticky bit    :


[root@station7 ~]# ll /usr/bin/passwd
-rwsr-xr-x. 1 root root 27832 Jun 10  2014 /usr/bin/passwd    ----> set  UID


[root@station7 ~]# ll /usr/bin/write
-rwxr-sr-x. 1 root tty 19536 Apr 13  2017 /usr/bin/write         ---> SET GID


[root@station7 ~]# ll -d /tmp
drwxrwxrwt. 16 root root 4096 Jul 13 11:04 /tmp              ----> Sticky bit



[root@station7 ~]# ps -ef | grep sleep
guru      8780  8741  0 11:15 pts/0    00:00:00 sleep 300
root      8787  5581  0 11:16 pts/1    00:00:00 grep --color=auto sleep
[root@station7 ~]#
[root@station7 ~]# ps -ef | grep passwd
root      8804  8741  0 11:16 pts/0    00:00:00 passwd   ---> guru가 passwd 실행하면 guru가 아니라 root가 실행한것처럼 뜬다.
root      8807  5581  0 11:16 pts/1    00:00:00 grep --color=auto passwd


[root@station7 ~]# umask
0022         ---> 첫번째 0 : 특수퍼미션

                          두번째 0 : 소유자를 위한 마스크

                          세번째 2 : 그룹을 위한 마스크 (2를 제외)

                          네번째 2 : other를 위한 마스크 (2를 제외)

디렉토리는 기본값이 777 , 파일의 기본값은 666




7장 Monitor and manage linux processes


1. init 이제 없어짐, systemd 가 예전의 init (RHEL 7~)

[root@station7 ~]# pstree
systemd─┬─NetworkManager─┬─dhclient
        │                                                   └─2*[{NetworkManager}]
        ├─2*[abrt-watch-log]
        ├─abrtd
        ├─accounts-daemon───2*[{accounts-daemon}]
        ├─acpid
        ├─at-spi-bus-laun─┬─dbus-daemon───{dbus-daemon}
        │                 └─3*[{at-spi-bus-laun}]
        ├─at-spi2-registr───2*[{at-spi2-registr}]
        ├─atd
        ├─auditd─┬─audispd─┬─sedispatch
        │        │         └─{audispd}
        │        └─{auditd}
        ├─automount───4*[{automount}]
        ├─avahi-daemon───avahi-daemon
        ├─caribou───2*[{caribou}]
        ├─chronyd
        ├─colord───2*[{colord}]
        ├─crond
        ├─cupsd
        ├─3*[dbus-daemon───{dbus-daemon}]
        ├─2*[dbus-launch]
        ├─dconf-service───2*[{dconf-service}]
        ├─evolution-calen───5*[{evolution-calen}]
        ├─evolution-sourc───2*[{evolution-sourc}]
        ├─gconfd-2
        ├─gdm─┬─Xorg───3*[{Xorg}]
        │     ├─gdm-session-wor─┬─gnome-session─┬─abrt-applet───2*[{abrt-applet}]
        │     │                 │               ├─gnome-settings-───4*[{gnome-settings-}]
        │     │                 │               ├─gnome-shell─┬─firefox─┬─Web Content───25*[{Web Content}]
        │     │                 │               │             │         └─51*[{firefox}]
        │     │                 │               │             ├─ibus-daemon─┬─ibus-dconf───3*[{ibus-dconf}]
        │     │                 │               │             │             ├─ibus-engine-han───2*[{ibus-engine-han}]
        │     │                 │               │             │             ├─ibus-engine-sim───2*[{ibus-engine-sim}]
        │     │                 │               │             │             └─2*[{ibus-daemon}]
        │     │                 │               │             └─5*[{gnome-shell}]
        │     │                 │               ├─gnome-software───3*[{gnome-software}]
        │     │                 │               ├─nautilus───3*[{nautilus}]
        │     │                 │               ├─seapplet
        │     │                 │               ├─ssh-agent
        │     │                 │               ├─tracker-extract───13*[{tracker-extract}]
        │     │                 │               ├─tracker-miner-a───2*[{tracker-miner-a}]
        │     │                 │               ├─tracker-miner-f───3*[{tracker-miner-f}]
        │     │                 │               ├─tracker-miner-u───2*[{tracker-miner-u}]
        │     │                 │               └─3*[{gnome-session}]
        │     │                 └─2*[{gdm-session-wor}]
        │     └─3*[{gdm}]
        ├─geoclue───2*[{geoclue}]
        ├─gnome-keyring-d───4*[{gnome-keyring-d}]
        ├─gnome-shell-cal───5*[{gnome-shell-cal}]
        ├─gnome-terminal-─┬─bash───su───bash
        │                 ├─bash───pstree
        │                 ├─gnome-pty-helpe
        │                 └─3*[{gnome-terminal-}]
        ├─goa-daemon───3*[{goa-daemon}]
        ├─goa-identity-se───3*[{goa-identity-se}]
        ├─gpm
        ├─gsd-printer───2*[{gsd-printer}]
        ├─gssproxy───5*[{gssproxy}]
        ├─gvfs-afc-volume───3*[{gvfs-afc-volume}]
        ├─gvfs-goa-volume───2*[{gvfs-goa-volume}]
        ├─gvfs-gphoto2-vo───2*[{gvfs-gphoto2-vo}]
        ├─gvfs-mtp-volume───2*[{gvfs-mtp-volume}]
        ├─gvfs-udisks2-vo───2*[{gvfs-udisks2-vo}]
        ├─gvfsd───2*[{gvfsd}]
        ├─gvfsd-fuse───5*[{gvfsd-fuse}]
        ├─gvfsd-metadata───2*[{gvfsd-metadata}]
        ├─gvfsd-trash───2*[{gvfsd-trash}]
        ├─ibus-x11───2*[{ibus-x11}]
        ├─irqbalance
        ├─lsmd
        ├─lvmetad
        ├─master─┬─pickup
        │        └─qmgr
        ├─mcelog
        ├─mission-control───3*[{mission-control}]
        ├─packagekitd───2*[{packagekitd}]
        ├─polkitd───5*[{polkitd}]
        ├─rngd
        ├─rsyslogd───2*[{rsyslogd}]
        ├─rtkit-daemon───2*[{rtkit-daemon}]
        ├─smartd
        ├─sshd
        ├─sssd─┬─sssd_autofs
        │      ├─sssd_be
        │      ├─sssd_nss
        │      └─sssd_pam
        ├─systemd-journal
        ├─systemd-logind
        ├─systemd-udevd
        ├─tracker-store───7*[{tracker-store}]
        ├─tuned───4*[{tuned}]
        ├─udisksd───4*[{udisksd}]
        ├─upowerd───2*[{upowerd}]
        ├─wpa_supplicant
        └─xinetd



2. top

- P      : CPU 사용량 순으로 소팅

- M     : 메모리 순으로 소팅

- ?       : 명령어 의미 확인


3. kill

[root@station7 ~]# kill -l
 1) SIGHUP     2) SIGINT (=CTrl+C)     3) SIGQUIT (=CTrl+X), (이 프로세스가 이상한거 같아, 디버깅하고 싶어. 종료를 하긴 하는데 메모리에서 실행되고 있는 상태파일을

저장하고 싶어. 그게 코어덤프 파일로 생성됨.)

 4) SIGILL     5) SIGTRAP
 6) SIGABRT     7) SIGBUS     8) SIGFPE     9) SIGKILL  (=15번 시그널보다 더 강력한 시그널)

10) SIGUSR1
11) SIGSEGV    12) SIGUSR2    13) SIGPIPE    14) SIGALRM    15) SIGTERM (=kill했을때 기본 시그널)ㅋ
16) SIGSTKFLT    17) SIGCHLD    18) SIGCONT (=일시정지 후 다시 시작할때)  

19) SIGSTOP (=CTRL+Z, 일시정지)   20) SIGTSTP (=일시정지, 19번이랑 미묘한 차이가 있대. 먼 차인진 말 안해줌ㅋㅋㅋ)
21) SIGTTIN    22) SIGTTOU    23) SIGURG    24) SIGXCPU    25) SIGXFSZ
26) SIGVTALRM    27) SIGPROF    28) SIGWINCH    29) SIGIO    30) SIGPWR
31) SIGSYS    34) SIGRTMIN    35) SIGRTMIN+1    36) SIGRTMIN+2    37) SIGRTMIN+3
38) SIGRTMIN+4    39) SIGRTMIN+5    40) SIGRTMIN+6    41) SIGRTMIN+7    42) SIGRTMIN+8
43) SIGRTMIN+9    44) SIGRTMIN+10    45) SIGRTMIN+11    46) SIGRTMIN+12    47) SIGRTMIN+13
48) SIGRTMIN+14    49) SIGRTMIN+15    50) SIGRTMAX-14    51) SIGRTMAX-13    52) SIGRTMAX-12
53) SIGRTMAX-11    54) SIGRTMAX-10    55) SIGRTMAX-9    56) SIGRTMAX-8    57) SIGRTMAX-7
58) SIGRTMAX-6    59) SIGRTMAX-5    60) SIGRTMAX-4    61) SIGRTMAX-3    62) SIGRTMAX-2
63) SIGRTMAX-1    64) SIGRTMAX   



4. processinfo

# lscpu = cat /proc/cpuinfo

리눅스 cpu 정보


# iostat -xt 3 2   (3초 사이로 2번 보여줘라)

       -t     Print  the  time for each report displayed. The timestamp format
              may depend on the value of the S_TIME_FORMAT  environment  vari‐
              able (see below).

-x     Display extended statistics.


[root@station7 ~]# iostat -xt 3 2
Linux 3.10.0-514.26.1.el7.x86_64 (station7.example.com)     07/13/2018     _x86_64_    (4 CPU)

07/13/2018 02:52:58 PM
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.98    0.09    0.34    0.21    0.00   97.38

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.02     0.32    1.18    2.81    40.75   113.99    77.46     0.16   39.39   13.11   50.41   5.82   2.33
dm-0              0.00     0.00    0.90    2.31    31.51    45.18    47.71     0.17   51.63   16.79   65.26   4.43   1.42
dm-1              0.00     0.00    0.01    0.00     0.05     0.00    16.69     0.00    4.62    4.62    0.00   4.62   0.00
dm-2              0.00     0.00    0.01    0.07     0.24     0.58    21.94     0.00   55.56   12.93   59.31  53.11   0.40
dm-3              0.00     0.00    0.27    0.62     8.62    68.13   173.03     0.04   41.48    3.94   57.68   6.94   0.62

await : io의 평균 대기시간

svctm : service time. 디스크를 처리하는데 걸린 시간.


[root@station7 ~]# mpstat -P ALL 1 3
Linux 3.10.0-514.26.1.el7.x86_64 (station7.example.com)     07/13/2018     _x86_64_    (4 CPU)

03:01:03 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
03:01:04 PM  all    1.25    0.00    0.50    0.00    0.00    0.00    0.00    0.00    0.00   98.25
03:01:04 PM    0    1.01    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   98.99
03:01:04 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
03:01:04 PM    2    4.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   96.00
03:01:04 PM    3    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00


[root@station7 ~]# vmstat 3 2
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 3858860   1008 2606424    0    0    10    28  100  413  2  0 97  0  0
 0  0      0 3857356   1008 2606456    0    0     0   127  254  941  1  0 99  0  0


r : waiting 중에 있는 running 상태. 코어의 4배 넘게 있는 상태면 cpu의 부하가 많다라고 생각하면 됨.

b : ???



5. nice, renice

1) nice : 실행할때 실행 우선순위 바꿔서 실행.

2) renice : 실행중에 있는 프로세스의 우선순위 바꿈.

- 디폴트값은 0 . 음수일수록 실행속도 빨라짐, 양수일수록 속도 느려짐.

- 일반유저는 nice 값을 올리는 것만 가능함. (속도를 늦추는 것.)

[john@station7 ~]$ ps -l
F S   UID   PID  PPID  C PRI        NI ADDR SZ WCHAN  TTY          TIME CMD
4 S  1201 11377 11376  0  80   0 - 29520 wait   pts/0    00:00:00 bash
0 S  1201 11416 11377  0  80   0 - 27485 hrtime pts/0    00:00:00 sleep
0 R  1201 11425 11377  0  80   0 - 37744 -      pts/0    00:00:00 ps


기본 nice값은 0.


[root@station7 ~]# nice -n -5 sleep 300 & (nice 마이너스값은 root만 가능)
[1] 11446
[root@station7 ~]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0  5581  5021  0  80   0 - 29551 wait   pts/1    00:00:00 bash
4 S     0 11446  5581  0  75  -5 - 27485 hrtime pts/1    00:00:00 sleep
0 R     0 11450  5581  0  80   0 - 37744 -      pts/1    00:00:00 ps


PRIORITY도 75로 높아짐.


[root@station7 ~]# renice -n 7 11446
11446 (process ID) old priority -5, new priority 7
[root@station7 ~]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0  5581  5021  0  80   0 - 29551 wait   pts/1    00:00:00 bash
4 S     0 11446  5581  0  87   7 - 27485 hrtime pts/1    00:00:00 sleep
0 R     0 11472  5581  0  80   0 - 37744 -      pts/1    00:00:00 ps



8장 Control services and daemons


1. init 이제 없어짐, systemd 가 예전의 init (RHEL 7~)

1) 서버프로세스, 서버서비스,  데몬 : 시스템 부팅부터 시작되는 프로세스

      ps -ef 했을때 터미널 부분이 ? 인 애들. 터미널 기반으로 시작되는 애가 아님.


2. init

1) 6버전까지는...

service 명령어 사용했음. /etc/init.d/스크립트 사용했음.

2) 7버전부턴... systemd가 하게 됨.


3. systemd

1) PID가 1번

2) 커널에 의해 실행됨.

[root@station7 ~]# ps -ef | more
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 09:21 ?        00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 21


4. Runlevel / Target

1) 스탠다드 linux runlevel

- # init 0 하면 컴터 꺼진다. 아직 init 명령어 먹힌다.

- 0 : halt

- 1 : 싱글유저

- 2 : 멀티유저, 네트워크 X

- 3 : CLI

- 4 : Custom or local; unused by default

- 5 : GUI

- 6 : 재부팅

2) 이제 7번부터는 runlevel 안 씀. target을 씀.

     init 단점이 순차적으로 진행됨. 부모자식간의 관계로...

     그러다 보니 문제가, 아무리 하드웨어가 좋아도 부팅 시간이 비슷함.

     target은 병렬적으로 처리됨.


runlevel

target

0

poweroff.target

1

rescure.target

2

multi-user.target

3

multi-user.target

4

multi-user.target

5

graphical.target

 6 reboot.target


3) # runlevel

    N 5

    -> 부팅하자마자 5였다. N은 이전 런레벨단계가 암것도 없었다는 걸 의미.


4) 7부터는 싱글유저모드가 어렵다. 시험 단골문제

    아래와 같이 싱글유저모드로 들어간다.

    그래픽 런레벨에서는 싱글유저모드가 안되어서, 런레벨 3으로 간 다음에 싱글유저모드로 들어가야 한다.

[root@station7 ~]# systemctl isolate multi-user.target
[root@station7 ~]# systemctl isolate rescure.target


이렇게 하면 암호로 입력해야한다.

만약 암호를 모른다면.... 부팅때 들어가야한다.


5) QUIZ. 루트 암호를 모르는 상태, 싱글모드로 들어가서 root 암호를 바꿔라

1. 부팅할때 커널 선택하는 부분에서 화살표 눌러서 e로 부트로더 파일 수정

2. linux16 /vmlinuz-xxxx........ 행 맨 뒤에 rd.break 추가

3. 그 뒤 Ctrl+x로 해당 부트로더로 부팅. 그러면 emergency mode , 읽기전용으로 연결됨. 쓰기 가능하게 바꿔줘야 함.

4. switch_root:/# mount -o remount,rw /sysroot          ----> /sysroot를 rw하게 리마운트하라.

5. switch_root:/# chroot /sysroot                                     -----> root를 /sysroot로 바꿔라.

6. 그러면 프롬프트가 sh-4.2# 로 바뀜.

7. sh-4.2# passwd

8. 바꾸고 나서 걍 재부팅하면 안 됨. 그럼 암호가 안 바뀐채로 부팅될 수 있음.

9. sh-4.2# touch /.autorelabel

10. .autorelabel 은 selinux 와 관련있는 파일로, 부팅할 때 selinux와 관련된 내용 확인하도록 함.

11. sh-4.2 # exit

12. switch_root:/# exit

13. 최종 재부팅됨. 바뀐 암호로 로그인되는지 확인.



6) 디폴트 부트 타겟 변경

# systemctl set-default multi-user.target

# systemctl get-default


5. systemd system and service manager

1) unit 파일 = 구 init scripts

2) /etc/init.d/서비스명 스크립티들이 있었다.


6. systemd

※ 뒤에 .service는 안 써도 된다.

1) starting and stopping a service

# systemctl start unit_name.service

# systemctl stop unit_name.service

# systemctl restart unit_name.service

2) enabling / disabling (부팅할때 자동실행/자동미실행 설정)

# systemctl enable unit_name.service

# systemctl disable unit_name.service

# systemctl mask unit_name.service    ----> mask 설정되어 있으면 수동으로 start/stop 을 할 수가 없음.

# systemctl unmask unit_name.service  ---> mask 설정 해제

3) listing services and their state

# systemctl status unit_name.service

# systemctl -a --type=service

# systemctl list-unit-files --type=service        ---> 현재 돌고 있는 서비스들 리스트 state까지 확인

# systemctl is-enabled 서비스명                       ---> 부팅될때 인에이블/디스에이블인지 확인


[root@station7 ~]# systemctl status sshd
sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2018-07-13 16:53:04 KST; 6min ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 1039 (sshd)
   CGroup: /system.slice/sshd.service
           └─1039 /usr/sbin/sshd -D

Jul 13 16:53:04 station7.example.com systemd[1]: Starting OpenSSH server dae....
Jul 13 16:53:04 station7.example.com sshd[1039]: Server listening on 0.0.0.0....
Jul 13 16:53:04 station7.example.com sshd[1039]: Server listening on :: port 22.
Jul 13 16:53:04 station7.example.com systemd[1]: Started OpenSSH server daemon.
Hint: Some lines were ellipsized, use -l to show in full.
[root@station7 ~]# systemctl stop sshd
[root@station7 ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Fri 2018-07-13 17:00:23 KST; 2s ago
     Docs: man:sshd(8)
           man:sshd_config(5)
  Process: 1039 ExecStart=/usr/sbin/sshd -D $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 1039 (code=exited, status=0/SUCCESS)

Jul 13 16:53:04 station7.example.com systemd[1]: Starting OpenSSH server dae....
Jul 13 16:53:04 station7.example.com sshd[1039]: Server listening on 0.0.0.0....
Jul 13 16:53:04 station7.example.com sshd[1039]: Server listening on :: port 22.
Jul 13 16:53:04 station7.example.com systemd[1]: Started OpenSSH server daemon.
Jul 13 17:00:23 station7.example.com sshd[1039]: Received signal 15; termina....
Jul 13 17:00:23 station7.example.com systemd[1]: Stopping OpenSSH server dae....
Jul 13 17:00:23 station7.example.com systemd[1]: Stopped OpenSSH server daemon.
Hint: Some lines were ellipsized, use -l to show in full.
[root@station7 ~]#