반응형

1. profile 설정

1) /etc/profile 수정

[root@localhost ~]# vi /etc/profile

# Command Log
function history_to_syslog {
declare command
remoteaddr="`who am i`"
pwd="`pwd`"
command=$(fc -ln -0)
if [ "$command" != "$old_command" ]; then
logger -p local2.notice -t bash -i ? "$USER : $remoteaddr" "Command : $command  Directory : $pwd"
fi
old_command=$command
}
trap history_to_syslog DEBUG

 

2) /etc/profile 적용

[root@localhost ~]# source /etc/profile

 

2. rsyslog 설정

1) rsyslog.conf 수정

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

# Command Log
local2.notice                                           /var/log/cmd.log

 

2) rsyslog 재시작
[root@localhost ~]# systemctl restart rsyslog

 

3) 로그 기록 확인
[root@localhost ~]# tail -f /var/log/cmd.log

Jul  2 14:56:08 localhost bash[5932]: ? root : root     pts/0        2021-07-02 14:55 (192.168.0.10) Command : #011 ps ax  Directory : /root
Jul  2 14:56:13 localhost bash[5941]: ? root : root     pts/0        2021-07-02 14:55 (192.168.0.10) Command : #011 netstat -natp  Directory : /root
Jul  2 14:56:46 localhost bash[5975]: ? root : root     pts/0        2021-07-02 14:55 (192.168.0.10) Command : #011 vi /var/log/cmd.log   Directory : /root
Jul  2 14:57:09 localhost bash[6037]: ? root : root     pts/1        2021-07-02 14:57 (192.168.0.10) Command : #011 exit  Directory : /root
Jul  2 14:57:22 localhost bash[6061]: ? root : root     pts/1        2021-07-02 14:57 (192.168.0.10) Command : #011 vim toast  Directory : /root
Jul  2 14:57:35 localhost bash[6082]: ? root : root     pts/1        2021-07-02 14:57 (192.168.0.10) Command : #011 vi toast  Directory : /root
Jul  2 14:57:58 localhost bash[6110]: ? root : root     pts/0        2021-07-02 14:55 (192.168.0.10) Command : #011 tail -f /var/log/cmd.log   Directory : /root

 

반응형

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

[CentOS] SFTP Log 설정  (0) 2021.03.26
[CentOS] Core 파일  (0) 2021.02.03
[CentOS] Google OTP를 활용한 SSH 추가 인증  (1) 2021.01.13
[CentOS] is not in the sudoers file  (0) 2021.01.11
[CentOS] 로그인 실패시 계정 잠금  (0) 2021.01.07
반응형

1. /etc/ssh/sshd_config 수정

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

# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server -f local2 -l INFO

 

2. sshd 재시작

[root@localhost ~]# systemctl restart sshd

 

3. /etc/rsyslog.conf 수정

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

#sftp log
local2
.*                                                /var/log/sftp.log

 

4. rsyslog 재시작

[root@localhost ~]# systemctl restart rsyslog

 

5. sftp.log 파일 생성 및 로그 확인

[root@localhost ~]#touch /var/log/sftp.log

[root@localhost ~]#tail -f /var/log/sftp.log

Mar 26 11:47:28 is sftp-server[18171]: session opened for local user root from [192.168.0.100]
Mar 26 11:47:28 is sftp-server[18171]: opendir "/root"
Mar 26 11:47:29 is sftp-server[18171]: closedir "/root"

 

반응형

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

[CentOS] 명령어 기록하기  (0) 2021.07.02
[CentOS] Core 파일  (0) 2021.02.03
[CentOS] Google OTP를 활용한 SSH 추가 인증  (1) 2021.01.13
[CentOS] is not in the sudoers file  (0) 2021.01.11
[CentOS] 로그인 실패시 계정 잠금  (0) 2021.01.07
반응형

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. 이더넷 이름 확인

root@latch:~# ifconfig -a

docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:d8ff:fe17:c88a  prefixlen 64  scopeid 0x20<link>
        ether 02:42:d8:17:c8:8a  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5  bytes 446 (446.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.100  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::250:56ff:feb8:8d2  prefixlen 64  scopeid 0x20<link>
        ether 00:50:56:b8:08:d2  txqueuelen 1000  (Ethernet)
        RX packets 3284  bytes 301412 (301.4 KB)
        RX errors 0  dropped 3  overruns 0  frame 0
        TX packets 1815  bytes 352978 (352.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ifconfig -a 명령어를 통해 이더넷 이름을 확인합니다.

 

root@latch:~# cd /etc/netplan

기존(/etc/network의 interfaces 파일 수정) 네트워크 설정이 /etc/netplan(17버전 이상)으로 변경되었습니다.

 

2. 00-installer-config.yaml 수정

root@latch:~# vi 00-installer-config.yaml

# This is the network config written by 'subiquity'
network:
  ethernets:
        ens160:
                dhcp6: no
                addresses: [192.168.0.100/24]
                gateway4: 192.168.0.1
                nameservers:
                        addresses: [168.126.63.1, 168.126.63.2]

  version: 2

3. netplan 적용 및 확인

root@latch:/etc/netplan# sudo netplan apply
root@latch:/etc/netplan# hostname -I
192.168.0.100

 

반응형
반응형

해당 유저가 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

 

반응형

+ Recent posts