반응형

1. Core 파일

프로그램의 비정상적인 종료가 발생하여 커널에서 메모리를 덤프시킨 파일입니다.

 

2. Core 파일 확인

core.[PID값] 으로 파일이 생성됩니다.

 

[root@localhost ~]# ls -al

total 46274300
-rw-------  1 root root  498569216 Oct 19 16:49 core.10035
-rw-------  1 root root 1589530624 Oct 21 03:52 core.10403
-rw-------  1 root root 1689006080 Aug 20 04:41 core.11611
-rw-------  1 root root 1806168064 Jan 12 01:46 core.12294
-rw-------  1 root root 1666433024 Sep 24 20:47 core.12620

 

3. Core 파일 size 확인 (기본값 : 0)

core file size가 0일 경우 core file을 생성하지 않습니다.

 

[root@localhost ~]# ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 32765
max locked memory       (kbytes, -l) 32
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 32765
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

 

4. Core 파일의 바이너리 확인

[root@localhost ~]# gdb -c core.29019

GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-23.el5_5.2)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
BFD: Warning: /var/domain/core.29019 is truncated: expected core file size >= 1898045440, found: 10928128.
[New Thread 29025]
[New Thread 29024]
[New Thread 29022]
[New Thread 29021]
[New Thread 29020]
[New Thread 29019]
Core was generated by `/usr/local/sbin/named'.
Program terminated with signal 6, Aborted.
#0  0x00554402 in __kernel_vsyscall ()

 

5. Core 파일로 gdb 디버깅

[root@localhost ~]# gdb -c core.29019 /usr/local/sbin/named

반응형
반응형

Google OTP(Google Authenticator)를 이용하여 CentOS에 2-Factor 인증을 구성할 수 있습니다. 기존 패스워드로만 로그인 되던 방식에 OTP를 추가 함으로써 보안을 강화할 수 있습니다.

 

1. 시간 동기화

[root@localhost ~]# rdate time.bora.net

[root@localhost ~]# date
Wed Jan 13 09:42:46 KST 2021

 

2. EPEL Repository 설치

구글 OTP 패키지(google-authenticator)를 위해 EPEL Repository를 설치해야 됩니다.

 

[root@localhost ~]# yum install epel-release -y

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
 * extras: mirror.kakao.com
 * updates: mirror.kakao.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================================================
 Package                                         Arch                                      Version                                 Repository                                 Size
===================================================================================================================================================================================
Installing:
 epel-release                                    noarch                                    7-11                                    extras                                     15 k

Transaction Summary
===================================================================================================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
epel-release-7-11.noarch.rpm                                                                                                                                |  15 kB  00:00:05     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                                                                                                                        1/1 
  Verifying  : epel-release-7-11.noarch                                                                                                                                        1/1 

Installed:
  epel-release.noarch 0:7-11                                                                                                                                                       

Complete!

 

3. Google-Authenticator 설치

[root@localhost ~]# yum install google-authenticator

Dependencies Resolved

===================================================================================================================================================================================
 Package                                              Arch                                   Version                                    Repository                            Size
===================================================================================================================================================================================
Installing:
 google-authenticator                                 x86_64                                 1.04-1.el7                                 epel                                  48 k

Transaction Summary
===================================================================================================================================================================================
Install  1 Package

Total download size: 48 k
Installed size: 97 k
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/epel/packages/google-authenticator-1.04-1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY]  16 kB/s |  32 kB  00:00:01 ETA 
Public key for google-authenticator-1.04-1.el7.x86_64.rpm is not installed
google-authenticator-1.04-1.el7.x86_64.rpm                                                                                                                  |  48 kB  00:00:02     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
 Userid     : "Fedora EPEL (7) <epel@fedoraproject.org>"
 Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 Package    : epel-release-7-11.noarch (@extras)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : google-authenticator-1.04-1.el7.x86_64                                                                                                                          1/1 
  Verifying  : google-authenticator-1.04-1.el7.x86_64                                                                                                                          1/1 

Installed:
  google-authenticator.x86_64 0:1.04-1.el7                                                                                                                                         

Complete!

 

4. PAM 모듈 설정

[root@localhost ~]# vi /etc/pam.d/sshd

#%PAM-1.0
auth       required     pam_sepermit.so
auth       substack     password-auth
auth       include      postlogin

### Google Authenticator(Google OTP) ###  ← 추가
auth       required     pam_google_authenticator.so    nullok  ← 추가

# Used with polkit to reauthorize users in remote sessions
-auth      optional     pam_reauthorize.so prepare
account    required     pam_nologin.so
account    include      password-auth
password   include      password-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open env_params
session    required     pam_namespace.so
session    optional     pam_keyinit.so force revoke
session    include      password-auth
session    include      postlogin
# Used with polkit to reauthorize users in remote sessions
-session   optional     pam_reauthorize.so prepare

nullok : 리눅스 내 모든 사용자 각각의 "Secret Key"를 생성합니다. 동일한 Secret Key를 사용이 필요한 경우 때 해당 옵션을 삭제하면 됩니다.

 

5. ssh config 파일 수정

[root@localhost ~]# vi /etc/ssh/sshd_config

옵션 설명
PermitEmptyPasswords no 비어 있는 사용자 암호 허용 여부
PasswordAuthentication no 패스워드 인증 사용 여부(OTP 인증시에는 사용X)
ChallengeResponseAuthentication yes 시도-응답 인증 방식을 사용 여부(2-Factor 인증을 위해 필요)
UsePAM yes 인증 PAM 모듈 사용 여부

위 표와 같이 수정을 합니다.

 

6. sshd 재시작

[root@localhost ~]# systemctl restart sshd


7. Google Authenticator 인증 파일 생성

[root@localhost ~]# google-authenticator

 

1) 인증 토근을 시간 기반(Time-Based)으로 선택

Do you want authentication tokens to be time-based (y/n) y

 

QR 코드가 생성되고 QR 코드 밑에 아래와 같이 Secret Key와 백업 코드가 출력됩니다.

Your new secret key is: IPUUHIOMJ4YVDZEKN7D62HSPO4
Your verification code is 092264
Your emergency scratch codes are:
  66905078
  21438147
  22384034
  77127198
  68711227

 

2) Secret Key 및 백업 코드 저장 file 위치 확인

Do you want me to update your "/root/.google_authenticator" file? (y/n) y

[root@localhost ~]# cat /root/.google_authenticator

IPUUHIOMJ4YVDZEKN7D62HSPO4 
" RATE_LIMIT 3 30 
" WINDOW_SIZE 17 
" DISALLOW_REUSE 
" TOTP_AUTH 
66905078 
21438147 
22384034 
77127198 
68711227 

해당 경로에 Secret Key 및 백업 코드가 저장된 것을 확인할 수 있습니다.

 

3) Man-in-the-middel Attack 사용 여부

Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y

 

4) 시간 오차 또는 왜곡 방지 사용 여부

By default, a new token is generated every 30 seconds by the mobile app.
In order to compensate for possible time-skew between the client and the server,
we allow an extra token before and after the current time. This allows for a
time skew of up to 30 seconds between authentication server and client. If you
experience problems with poor time synchronization, you can increase the window
from its default size of 3 permitted codes (one previous code, the current
code, the next code) to 17 permitted codes (the 8 previous codes, the current
code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
between client and server.
Do you want to do so? (y/n) y

 

5) 무차별 대입 공격 방지 사용 여부

If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting? (y/n) y

 

공격자가 30 초마다 3번 이상 로그인을 시도하지 못하도록 제한 옵션이며, 3회 이상 인증 실패시 일시적으로 로그인을 차단합니다.

 

8. 구글 OTP 앱에서 설정

1) Google Authentication 시작하기

시작하기 버튼을 클릭합니다.

 

2) QR 코드 확인

QR 코드 스캔 버튼을 클릭합니다. 위에서 생성된 QR 코드를 스캔합니다.(설정 키를 입력해도 됩니다.)

 

3) Verification code 입력 창

Google-Authentication이 설정되면 Secure CRT에서 패스워드를 입력 후에 위와 같이 Verfication code를 입력하는 창이 보여지게 됩니다.

 

4) 스마트폰 Google Authentication App에서 코드 확인

랜덤한 숫자가 발생되며, 오른쪽에 남은 시간이 표시됩니다.

 

5) Verification code 입력

Google Authentication 앱에서 생성된 코드를 입력하고 OK 버튼을 클릭합니다.

 

9. 일반 사용자 Google OTP 설정

1) 사용자 계정 생성 및 패스워드 지정

[root@localhost ~]# useradd latch
[root@localhost ~]# passwd latch
Changing password for user latch.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

 

2) 사용자 계정으로 로그인

[root@localhost ~]# su latch
[latch@localhost ~]# google-authenticator 

 

3) Goole Authenticator 설정(사용자 계정)

QR 코드가 생성되고 QR 코드 밑에 아래와 같이 Secret Key와 백업 코드가 출력됩니다. 

 

기타 설정은 root와 동일하기 때문에 여기에서는 생략합니다..

 

[latch@localhost ~]$ ls -al /home/latch/
total 24
drwx------  2 latch latch 4096 Jan 13 10:17 .
drwxr-xr-x. 3 root  root  4096 Jan 13 10:16 ..
-rw-r--r--  1 latch latch   18 Apr  1  2020 .bash_logout
-rw-r--r--  1 latch latch  193 Apr  1  2020 .bash_profile
-rw-r--r--  1 latch latch  231 Apr  1  2020 .bashrc
-r--------  1 latch latch  136 Jan 13 10:17 .google_authenticator

사용자 홈 디렉토리에 .google_authenticator가 존재하는 것을 확인할 수 있습니다.

 

[latch@localhost ~]$ cat .google_authenticator 
QPCIPAXXG56D5YNXPUE4BGNUHY
" RATE_LIMIT 3 30
" WINDOW_SIZE 17
" DISALLOW_REUSE
" TOTP_AUTH
39277376
47772753
74567860
94211848
21118315
위와 같이 각 계정 별로 .google_authenticator 파일이 생성됩니다.

 

일반 계정으로 로그인할 때 Verfication Code를 입력하라는 창이 보여지는 것을 확인할 수 있습니다.

반응형

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

[CentOS] SFTP Log 설정  (0) 2021.03.26
[CentOS] Core 파일  (0) 2021.02.03
[CentOS] is not in the sudoers file  (0) 2021.01.11
[CentOS] 로그인 실패시 계정 잠금  (0) 2021.01.07
[CentOS] su 명령어 특정 사용자만 허용  (0) 2021.01.07
반응형

1. 구 버전 Docker 삭제

[root@localhost ~]# sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
Loaded plugins: fastestmirror
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal
구 버전이 존재할 경우 구 버전을 삭제합니다.

 

2. 저장소 설치

1) 저장소 구성

[root@localhost ~]# sudo yum install -y yum-utils

Installed:
  yum-utils.noarch 0:1.1.31-54.el7_8                                                                                                                                               

Dependency Installed:
  libxml2-python.x86_64 0:2.9.1-6.el7.5   python-chardet.noarch 0:2.2.1-3.el7   python-kitchen.noarch 0:1.1.1-5.el7
  
Dendency Updated:
  libxml2.x86_64 0:2.9.1-6.el7.5 
  
Complete!

yum-utils 패키지를 설치합니다.

 

[root@localhost ~]# sudo yum-config-manager --add-repo download.docker.com/linux/centos/docker-ce.repo

https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo

저장소를 설정합니다.

 

3. Docker 엔진 설치

1) Docker 엔진 및 컨테이너 설치

[root@localhost ~]# sudo yum install docker-ce docker-ce-cli containerd.io

Total                                                                                                                                               38 MB/s | 102 MB  00:00:02     
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]:y

메시지에 표시되는 지문이 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35와 일치하는지 확인하고 일치하면 수락합니다.

 

2) Nightly, Test 저장소 사용(선택 사항)

(1) Nightly 활성화
[root@localhost ~]# sudo yum-config-manager --enable docker-ce-nightly

(2) Test 활성화
[root@localhost ~]# sudo yum-config-manager --enable docker-ce-test

(3) Nightly 비활성화
[root@localhost ~]# sudo yum-config-manager --disable docker-ce-nightly

 

3) 특정 버전 설치를 위한 저장소에서 버전 확인(선택 사항)

[root@localhost ~]# yum list docker-ce --showduplicates | sort -r

docker-ce.x86_64            18.06.3.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.2.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.1.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.0.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            18.03.0.ce-1.el7.centos            docker-ce-stable 

 

4) 특정 버전의 Docker 설치(선택 사항)

[root@localhost ~]# sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

 

4. Docker 실행

[root@localhost ~]# sudo systemctl start docker

 

5. Docker Container 실행

[root@localhost ~]# sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:1a523af650137b8accdaed439c17d684df61ee4d74feac151b5b337bd29e7eec
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

 

6. Docker 버전 확인

[root@localhost ~]# docker version

Client: Docker Engine - Community
 Version:           20.10.2
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        2291f61
 Built:             Mon Dec 28 16:17:48 2020
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.2
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       8891c58
  Built:            Mon Dec 28 16:16:13 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.3
  GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc:
  Version:          1.0.0-rc92
  GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

 

반응형

'Cloud > Docker' 카테고리의 다른 글

[Docker] Nginx 실행  (0) 2021.01.12
[Ubuntu] Docker 설치  (0) 2021.01.12
반응형

해당 유저가 sudo 명령어를 사용할 수 있는 권한을 가지고 있지 않기 때문에 발생하는 에러입니다.

 

1. sudo 명령어 관련 에러

[latch@latch etc]$ sudo yum search docker
[sudo] password for latch: 
latch is not in the sudoers file.  This incident will be reported.

 

2. sudoers 파일 권한 변경

[latch@localhost ~]$ su -
Password: 
Last login: Mon Jan 11 15:44:18 KST 2021 on pts/0
[root@localhost ~]# cd /etc
root로 로그인하여 /etc 디렉토리로 이동합니다.

[root@localhost etc]# chmod 777 sudoers
sudoers 파일의 수정을 위해 접근 권한을 변경합니다.

 

3. sudoers 설정 변경

[root@localhost etc]# vi sudoers
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
latch   ALL=(ALL)       ALL ← 추가
sudo 명령어의 사용이 필요한 사용자 계정명(latch)을 추가합니다.

 

4. sudoers 파일 권한 변경

[root@localhost etc]# chmod 440 sudoers
[root@localhost etc]# ls -al | grep sudoers
-r--r-----   1 root root     4348 Jan 11 15:52 sudoers
drwxr-x---.  2 root root        6 Oct  1 02:42 sudoers.d
ls -al 명령어를 통해 정상적으로 권한이 변경 되었는지 확인합니다.

 

5. 사용자 계정에서 sudo 명령어 확인

[latch@latch ~]$ sudo yum search docker
[sudo] password for latch: 
사용자의 패스워드를 입력하라고 묻는다면 정상적으로 설정된 것입니다.

반응형
반응형

1. password-auth 설정

[root@localhost ~]# vi /etc/pam.d/password-auth

#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_tally2.so file=/var/log/tallylog deny=3 even_deny_root unlock_time=1200 <- 추가
auth        required      pam_env.so
auth        required      pam_faildelay.so delay=2000000
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 1000 quiet_success
auth        required      pam_deny.so

account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
account     required      pam_permit.so
account     required      pam_tally2.so <- 추가

password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
-session     optional      pam_systemd.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unixso

 

접속 실패 3번을 초과하면 그 이후부터 접속이 제한 되며, 1200초 후에 제한이 풀리고 로그인이 성공되면 카운트가 리셋됩니다.

 

2. 계정 로그인 실패 횟수 확인

[root@localhost ~]# pam_tally2 -u latch
Login           Failures Latest failure     From
latch           3    01/05/21 09:56:29  192.168.0.20

 

3. 계정 잠금 해제

[root@localhost ~]# pam_tally2 -u latch -r
Login           Failures Latest failure     From
latch           3    01/05/21 09:56:29  192.168.0.20

 

4. 계정 잠금 해제 확인

[root@localhost ~]# pam_tally2 -u latch 
Login           Failures Latest failure     From
logintest           0  

 

 

 

반응형
반응형

su 명령어 특정 사용자만 허용

PAM에서는 특정 사용자만 특정한 그룹(wheel)에 속하도록 하여 그 그룹에 속한 사용자만 특정한 권한을 가지도록 하기 위해 pam_wheel.so라는 모듈을 제공합니다. 또한 리눅스에서는 기본적으로 wheel이라는 그룹이 생성되어 있으므로 이 두가지를 사용하면 됩니다.

 

1. wheel 그룹 확인

[root@localhost ~]# cat /etc/group | grep wheel 
wheel:x:10:

 

2. wheel 그룹에 사용자 추가

[root@localhost ~]# vi /etc/group 
wheel:x:10:root,latch


3. /etc/pam.d/su 수정

[root@localhost ~]# vi /etc/pam.d/su
#%PAM-1.0 
auth            sufficient      pam_rootok.so 
# Uncomment the following line to implicitly trust users in the "wheel" group. 
#auth           sufficient      pam_wheel.so trust use_uid 
# Uncomment the following line to require a user to be in the "wheel" group. 
auth           required        pam_wheelso use_uid ← 주석 해제 
auth            substack        system-auth 
auth            include         postlogin 
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet 
account         include         system-auth 
password        include         system-auth 
session         include         system-auth 
session         include         postlogin 
session         optional        pam_xauth.so

 

4. 허용되지 않은 계정에서 su 시도

[latch2@localhost root]$ su -
암호:
su: 권한 부여 거부

반응형

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

[CentOS] is not in the sudoers file  (0) 2021.01.11
[CentOS] 로그인 실패시 계정 잠금  (0) 2021.01.07
[CentOS] 패스워드 정책 설정  (0) 2020.12.29
[CentOS] 방화벽 설정  (0) 2020.12.29
[CentOS] 로그 관리  (0) 2020.12.29
반응형

1. 패스워드 정책 확인

[root@localhost ~]# chage -l root

Last password change                                    : never
Password expires                                        : never
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 99999
Number of days of warning before password expires       : 7

 

2. 패스워드 정책 변경

1) 패스워드 정책 확인

[root@localhost ~]# cat /etc/login.defs

PASS_MAX_DAYS 99999 // 패스워드 최대 사용 기간
PASS_MIN_DAYS 0 // 패스워드 최소 사용 기간
PASS_MIN_LEN 8 // 패스워드 최소 길이
PASS_WARN_AGE 7 // 패스워드 만료 7일 전부터 메시지 표시

# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512 // 패스워드 암호화 알고리즘(기본 : MD5)

 

2) 패스워드 암호화 방식 확인

[root@localhost ~]# cat /etc/shadow

root:$6$/dtCGY7yBvRQZdAF:0:99999:7:::

 

$1 - MD5
$2 - blowfish
$2a - eksblowfish
$5 - SHA-256
$6 - SHA-512

 

3) 기존 암호화 방식 확인

[root@localhost ~]# cat /etc/login.defs

# Use MD5 to encrypt password.
ENCRYPT_METHOD MD5

 

4) SHA-512 암호화 방식으로 변경

[root@localhost ~]# authconfig --passalgo=sha512 --update

 

5) 변경된 암호화 방식 확인

[root@localhost ~]# cat /etc/login.defs

# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512
MD5_CRYPT_ENAB no

 

위 설정 및 정책은 이미 생성된 계정에는 반영되지 않고 신규로 생성되는 계정에 대해서만 반영이 됩니다.

이미 생성된 계정은 chage 명령어를 통해 패스워드 정책을 반영하면 됩니다.

 

6) 패스워드 최소 사용 기간 변경

[root@localhost ~]# chage -m 7 root

 

7) 패스워드 최대 사용 기간 변경

[root@localhost ~]# chage -M 180 root

 

8) 패스워드 정책 변경 확인

[root@localhost ~]# chage -l root

Last password change                                    : Jan 04, 2021 
Password expires                                        : Jul 03, 2021 
Password inactive                                       : never 
Account expires                                         : never 
Minimum number of days between password change          : 7 
Maximum number of days between password change          : 180 
Number of days of warning before password expires       : 7

 

3. 패스워드 복잡도 설정

1) 패스워드 길이 변경

[root@localhost ~]# authconfig --passminlen=8 --update

 

2) 패스워드 복잡도 설정

[root@localhost ~]# vi /etc/security/pwquality.conf

# Configuration for systemwide password quality limits
# Defaults:
#
# Number of characters in the new password that must not be present in the
# old password.
# difok = 5 // 기존 패스워드와 비교, 기본값 10(50%)
#
# Minimum acceptable size for the new password (plus one if
# credits are not disabled which is the default). (See pam_cracklib manual.)
# Cannot be set to lower value than 6.
# minlen = 9 // 패스워드 최소 길이를 9자로 제한
#
# The maximum credit for having digits in the new password. If less than 0
# it is the minimum number of digits in the new password.
# dcredit = 1 // 패스워드에 적어도 1개의 숫자를 포함
#
# The maximum credit for having uppercase characters in the new password.
# If less than 0 it is the minimum number of uppercase characters in the new
# password.
# ucredit = 1 // 패스워드에 적어도 1개의 대문자 포함
#
# The maximum credit for having lowercase characters in the new password.
# If less than 0 it is the minimum number of lowercase characters in the new
# password.
# lcredit = 1 // 패스워드에 적어도 1개의 소문자 포함
#
# The maximum credit for having other characters in the new password.
# If less than 0 it is the minimum number of other characters in the new
# password.
# ocredit = 1 // 패스워드 적어도 1개의 특수문자 포함
#
# The minimum number of required classes of characters for the new
# password (digits, uppercase, lowercase, others).
# minclass = 0 // 숫자 대문자, 소문자, 특수문자 모두 사용
#
# The maximum number of allowed consecutive same characters in the new password.
# The check is disabled if the value is 0.
# maxrepeat = 0 // 연속된 문자 허용 길이
#
# The maximum number of allowed consecutive characters of the same class in the
# new password.
# The check is disabled if the value is 0.
# maxclassrepeat = 0
#
# Whether to check for the words from the passwd entry GECOS string of the user.
# The check is enabled if the value is not 0.
# gecoscheck = 0
#
# Path to the cracklib dictionaries. Default is to use the cracklib default.
# dictpath =
minlen = 9
minclass = 1
maxrepeat = 0
maxclassrepeat = 0
lcredit = 0
ucredit = 1
dcredit = 1
ocredit = 1

 

※ 주석을 제거하여 패스워드 복잡도를 설정합니다.

 

3) 패스워드 정책 적용

[root@localhost ~]# cat /etc/pam.d/passwd

#%PAM-1.0

auth         include     system-auth

account     include     system-auth

password   substack   system-auth

-password  optional   pam_gnome_keyring.so use_authtok

위 내용을 확인하면 현재 패스워드 관련 정책은 /etc/pam.d/system-auth의 설정을 따릅니다.

 

[root@localhost ~]# vi /etc/pam.d/system-auth

#password   requisite    pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=

password     requisite    pam_pwquality.so enforce_for_root ← 추가

 

[root@localhost ~]# passwd latch
latch 사용자의 비밀 번호 변경 중
새  암호:
잘못된 암호: 암호는 10 개의 문자 보다 짧습니다
passwd: 인증 토근 수정 오류

[root@localhost ~]# passwd latch
latch 사용자의 비밀 번호 변경 중
새  암호:
잘못된 암호: 암호는 사전 검사에 실패했습니다  - 너무 단순/체계적입니다  
passwd: 인증 토근 수정 오류

 

4. 이전 사용한 암호 기억

[root@localhost ~]# vi /etc/pam.d/system-auth

password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=5 ← remember=5 추가

반응형

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

[CentOS] is not in the sudoers file  (0) 2021.01.11
[CentOS] 로그인 실패시 계정 잠금  (0) 2021.01.07
[CentOS] su 명령어 특정 사용자만 허용  (0) 2021.01.07
[CentOS] 방화벽 설정  (0) 2020.12.29
[CentOS] 로그 관리  (0) 2020.12.29
반응형

1. 방화벽 실행 여부 확인

[root@localhost ~]# firewall-cmd --state

 

2. 포트 추가

[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=80/tcp​

[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=80-90/tcp (포트 대역 오픈)

[root@localhost ~]# firewall-cmd --reload

 

3. 포트 제거

[root@localhost ~]# firewall-cmd --permanent --zone=public --remove-port=80/tcp

[root@localhost ~]# firewall-cmd --reload​

 

4. 특정 서비스 삭제

[root@localhost ~]# firewall-cmd --permanent --zone=public --remove-service=ssh

[root@localhost ~]# firewall-cmd --reload​

 

5. 특정 IP에 대한 방화벽 허용

[root@localhost ~]# firewall-cmd --permanent --add-source=192.168.0.100
success

 

6. 특정 IP 대역에 대한 방화벽 허용

[root@localhost ~]# firewall-cmd --permanent --add-source=192.168.0.0/24
success​

 

7. 특정 IP에 대해 특정 Port 접근 허용

[root@localhost ~]# firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address=192.168.0.100 port port="22" protocol="tcp" accept'

 

8. 특정 IP에 대해 특정 Port 접근 허용 제거

[root@localhost ~]# firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address=192.168.0.100 port port="8000" protocol="tcp" accept'

 

9. 특정 IP 대역에 대해 특정 Port 접근 허용

[root@localhost ~]# firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address=192.168.0.0/24 port port="8000" protocol="tcp" accept'

 

10. 특정 IP 대역에 대해 특정 Port 접근 허용 제거

[root@localhost ~]# firewall-cmd --permanent --remove-rich-rule='rule family="ipv4" source address=192.168.0.0/24 port port="8000" protocol="tcp" accept'

 

11. 변경된 firewall 구성 적용

[root@localhost ~]# firewall-cmd --reload

 

12. 방화벽 리스트 확인

[root@localhost ~]# firewall-cmd --list-all

public (active)
  target: default
  icmp-block-inversion: no
  interfaces: enp2s0 wlp3s0
  sources: 192.168.0.100 192.168.0.0/24
  services: dhcpv6-client ssh
  ports: 3306/tcp 8080/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
        rule family="ipv4" source address="192.168.0.100" port port="22" protocol="tcp" accept
        rule family="ipv4" source address="192.168.0.0/24" port port="22" protocol="tcp" accept
        rule family="ipv4" source address="192.168.0.0/24" port port="3306" protocol="tcp" accept
        rule family="ipv4" source address="192.168.0.100" port port="3306" protocol="tcp" accept
        rule family="ipv4" source address="192.168.0.0/24" port port="8080" protocol="tcp" accept

 

반응형
반응형

1. 로그 파일의 종류

로그 로그 파일명 관련 데몬
콘솔 로그 /dev/console kernel
시스템 로그 /var/log/message syslogd
보안 로그 /var/log/secure xinetd
메일 로그 /var/log/maillog sendmail
크론 로그 /var/log/cron crond
부트 로그 /var/log/boot.log kernel
커널 부트 로그 /var/dmesg kernel
커널 로그 /var/log/wtmp kernel
커널 로그 /var/log/utmp kernel
FTP 로그 /var/log/xferlog ftpd
웹 로그 /var/log/httpd/access_log httpd
웹 로그 /var/log/httpd/error_log httpd
네임 서버 로그 /var/log/named.log named

 

2. 로그 파일 분석

1) 콘솔 로그(/dev/console)

① 커널에 관려된 내용을 시스템 콘솔에 보여주는 로그입니다.

② 시스템의 중요한 내용들을 로그에 남깁니다.

③ timestamp, 호스트명, 커널 메시지 내용 등이 기록됩니다.

 

2) 시스템 로그(/var/log/message)

① 접속시 인증에 관한 것과 메일에 관한 내용, 시스템에 관한 변경사항 등 시스템에 대한 전반적인 로그를 기록합니다.

timestamp, 호스트명, 커널 메시지 내용 등이 기록됩니다.

③ 서버의 문제가 발생할 경우 가장 먼저 확인해야 될 로그입니다.

 

[root@localhost ~]# dmesg

[    0.000000] microcode: microcode updated early to revision 0x411, date = 2019-04-23
[    0.000000] Initializing cgroup subsys cpuset
[    0.000000] Initializing cgroup subsys cpu
[    0.000000] Initializing cgroup subsys cpuacct
[    0.000000] Linux version 3.10.0-1160.11.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org)

 

3) 보안 로그(/var/log/secure)

① 모든 접속과 어느 시점에 어떤 서비스를 사용했는지 기록합니다.

② timestamp, 호스트명, 응용 프로그램(pid), 메시지 내용이 기록됩니다.

③ login, tcp_wrappers, xinetd 관련 로그들이 기록됩니다.

 

[root@localhost ~]# cat /var/log/secure

Dec 29 00:02:39 latch sshd[2317]: Accepted password for latch from 192.168.0.7 port 51741 ssh2
Dec 29 00:02:39 latch sshd[2317]: pam_limits(sshd:session): Too many logins (max 1) for latch
Dec 29 00:02:39 latch sshd[2317]: pam_unix(sshd:session): session opened for user latch by (uid=0)
Dec 29 00:02:39 latch sshd[2317]: error: PAM: pam_open_session(): Permission denied
Dec 29 00:02:51 latch sshd[2322]: Accepted password for latch from 192.168.0.7 port 51742 ssh2
Dec 29 00:02:51 latch sshd[2322]: pam_limits(sshd:session): Too many logins (max 1) for latch
Dec 29 00:02:51 latch sshd[2322]: pam_unix(sshd:session): session opened for user latch by (uid=0)
Dec 29 00:02:51 latch sshd[2322]: error: PAM: pam_open_session(): Permission denied

 

4) 메일 로그(/var/log/maillog)

① sendmail이나 pop 등의 실행에 관한 기록이됩니다.

② timestamp, 호스트명, 데몬명(pid), 메시지 내용 등이 기록됩니다.

 

[root@localhost ~]# cat /var/log/maillog

Dec  1 20:48:24 latch postfix/smtp[5508]: 4722EB302C: to=<latch@test.com>, relay=none, delay=389901, delays=389840/0.12/60/0, dsn=4.4.1, status=deferred 
Dec  1 20:48:25 latch postfix/smtp[5509]: connect to alt1.test-smtp-in.l.test.com[192.168.0.100]:25: Connection timed out
Dec  1 20:48:25 latch postfix/smtp[5509]: connect to alt1.test-smtp-in.l.test.com[2607:f8b0:4023:c03::1b]:25: Network is unreachable
Dec  1 20:48:55 latch postfix/smtp[5509]: connect to alt2.test-smtp-in.l.test.com[192.168.0.100]:25: Connection timed out
Dec  1 20:48:55 latch postfix/smtp[5509]: 3CE27B302D: to=<latch@test.com>, relay=none, delay=44332, delays=44241/0.11/90/0, dsn=4.4.1, status=deferred

 

5) 크론 로그(/var/log/cron)

① 시스템의 정기적인 작업에 대한 모든 내용을 기록합니다.

② 크론 데몬의 crond가 어느 시점에 작업을 했는지 확인이 가능합니다.

③ /etc/ 디렉토리 밑에 있는 cron.hourly, crondaily, cron.weekly, cron.monthly 파일들에 기록되어 있는 작업을 실행한 후에 cron 파일에 log를 기록합니다.

④ timestamp, 호스트명, 데몬(pid), 메시지 내용이 기록됩니다.

 

[root@localhost ~]# cat /var/log/cron

Dec 29 10:01:01 latch CROND[5375]: (root) CMD (run-parts /etc/cron.hourly)
Dec 29 10:01:01 latch run-parts(/etc/cron.hourly)[5375]: starting 0anacron
Dec 29 10:01:01 latch run-parts(/etc/cron.hourly)[5384]: finished 0anacron
Dec 29 10:10:01 latch CROND[5404]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Dec 29 10:20:01 latch CROND[5441]: (root) CMD (/usr/lib64/sa/sa1 1 1)

 

6) 부팅 로그(/var/log/boot.log)

① 시스템의 데몬들이 실행되거나 재시작되었을 때 기록되는 로그 파일입니다.

② timestamp, 호스트명, 데몬(PID), 메시지 내용이 기록됩니다.

 

7) 커널 부트 메시지 로그(/var/log/dmesg)

① 시스템이 부팅할 때 출력되었던 메시지를 로그에 기록합니다.

 

[root@localhost ~]# cat /var/log/dmesg

[    5.938844] device-mapper: ioctl: 4.37.1-ioctl (2018-04-03) initialised: dm-devel@redhat.com
[    5.953072] FAT-fs (sda1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
[    6.018611] random: crng init done
[    6.274167] EXT4-fs (sdb): mounted filesystem with ordered data mode. Opts: (null)
[    6.407216] type=1305 audit(1609196197.839:3): audit_pid=607 old=0 auid=4294967295 ses=4294967295 res=1

 

8) 커널 로그(/var/log/wtmp)

① 사용자들의 로그인, 로그아웃 정보들이 기록됩니다.

② 바이너리 형태로 저장되며, 지금까지의 사용자들의 로그인, 로그아웃 히스토리를 누적 형태로 저장합니다.

③ 시스템의 shutdown, history까지 기록됩니다.

 

[root@localhost ~]# last

root     pts/0        192.168.0.100     Sun Jul  5 21:52 - down   (00:41)    
root     pts/0        192.168.0.100     Sun Jul  5 18:59 - 18:59  (00:00)    
root     pts/1        192.168.0.100     Sun Jul  5 18:59 - 21:29  (02:30)    
root     pts/0        192.168.0.100     Sun Jul  5 18:58 - 18:59  (00:00)    
root     tty1                          Sun Jul  5 18:53 - 18:54  (00:01)

 

④ last 옵션

옵션 설명
last [계정명] 계정명을 입력하면 사용자별 로그 정보를 출력
last -R IP를 제외시킨 로그 정보를 출력
last -a 로그 정보를 출력할 때 IP를 뒤로 배치하여 출력
last -d 외부에서 접속한 정보와 reboot 정보만 출력

 

9) 커널로그(/var/log/utmp)

① 시스템에 현재 로그인한 사용자들에 대한 상태를 기록합니다.

② 사용자 이름, 터미널 장치 이름, 원격 로그인시 원격 호스트 이름, 로그인 시간 등을 기록합니다.

 

[root@localhost ~]# who

latch    pts/0        2020-12-29 09:04 (192.168.0.100)

 

[root@localhost ~]# w

 10:33:17 up  2:36,  1 user,  load average: 0.00, 0.02, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
latch    pts/0    192.168.0.100  09:04    5.00s  2.69s  0.30s sshd: latch [priv] 

 

10) last 로그(/var/log/lastlog)

① /etc/passwd 파일에 정의되어 있는 모든 계정의 최근 접속 정보를 기록합니다.

② 사용자의 최근 로그인 시간, 사용자 이름, 터미널, IP 주소, 마지막 로그인 시간이 기록됩니다.

 

[root@localhost ~]# lastlog

Username         Port     From             Latest
root             pts/0                     Tue Dec 29 09:04:33 +0900 2020
bin                                        **Never logged in**
daemon                                     **Never logged in**
adm                                        **Never logged in**
lp                                         **Never logged in**
sync                                       **Never logged in**
shutdown                                   **Never logged in**
halt                                       **Never logged in**
mail                                       **Never logged in**
operator                                   **Never logged in**
games                                      **Never logged in**
ftp                                        **Never logged in**
nobody                                     **Never logged in**
systemd-network                            **Never logged in**
dbus                                       **Never logged in**
polkitd                                    **Never logged in**
libstoragemgmt                             **Never logged in**
abrt                                       **Never logged in**
rpc                                        **Never logged in**
tss                                        **Never logged in**
sshd                                       **Never logged in**
postfix                                    **Never logged in**
chrony                                     **Never logged in**
ntp                                        **Never logged in**
tcpdump                                    **Never logged in**
mysql                                      **Never logged in**
latch            pts/0    192.168.0.100  Tue Dec 29 09:04:29 +0900 2020

 

11) FTP 로그(/var/log/xferlog)

① ftp나 ncftp 등의 접속이 이루어졌을 때 해당 로그 파일에 기록됩니다.

② ftp를 사용했을 때 로그 파일에 기록되고 업로드 파일과 다운로드 한 파일에 대한 자세한 정보가 기록됩니다.

 

12) 웹 로그(/var/log/httpd/access_log, /var/log/httpd/error_log)

① 웹 사이트에 접속하여 요청했던 내용을 기록합니다.

② 방문자의 IP, 파일 요청 시간, 처리 내용(Get, Put, Head, Post), 요청 파일 이름, 파일 크기, 처리 결과 등의 데이터가 기록됩니다.

③ Errorlog : 요청한 페이지가 없거나 오류 등이 기록됩니다.

 

13) btmp 로그(/var/log/btmp)

① 로그인 시도 5번 이상 실패한 내역을 기록합니다.

② 계정명, 접속 콘솔, IP, 시간 등을 기록합니다.

 

[root@localhost ~]# lastb

 

admin    ssh:notty    192.168.0.10    Tue Dec  1 16:01 - 16:01  (00:00)    
admin    ssh:notty    192.168.0.10    Tue Dec  1 16:01 - 16:01  (00:00)    
admin    ssh:notty    192.168.0.10    Tue Dec  1 16:01 - 16:01  (00:00)    
admin    ssh:notty    192.168.0.10    Tue Dec  1 16:01 - 16:01  (00:00)    
admin    ssh:notty    192.168.0.10    Tue Dec  1 16:01 - 16:01  (00:00)  

 

14) History(해당 계정의 home directory/.bash_history)

① 접속한 계정에서 사용했던 명령어를 기록합니다.

② root의 경우 ~/.bash_history에 사용한 명령어가 기록됩니다.

 

[root@localhost ~]# cat ~/.bash_history

ls
ll
du -sh *
ls
shutdown -h now

 

반응형

+ Recent posts