# 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"
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 ()
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
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와 백업 코드가 출력됩니다.
기존(/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
해당 유저가 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: 사용자의 패스워드를 입력하라고 묻는다면 정상적으로 설정된 것입니다.
#%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
PAM에서는 특정 사용자만 특정한 그룹(wheel)에 속하도록 하여 그 그룹에 속한 사용자만 특정한 권한을 가지도록 하기 위해 pam_wheel.so라는 모듈을 제공합니다. 또한 리눅스에서는 기본적으로 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
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)
# 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
[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