[42SEOUL] Born2beroot

말차·2022년 9월 19일
0

42SEOUL

목록 보기
2/3
post-thumbnail

📌 MANDATORY

.vdi file

  • disk image (디스크 이미지) : 다른 운영 체제에서 컴퓨터를 부팅하기 위한 부팅 디스크 또는 드라이브의 전체 내용을 다른 시스템으로 복사하기 위한 방법으로 가상 시스템 구현을 위한 가상 하드 드라이브를 만드는 데 사용된다.
  • VDI(virtual disk image) : image of a virtual hard disk or the logical disk associated with a virtual machine.(It is used in virtualization environments to create a replica of the disk space/drive assigned to one or more virtual machines.) Deleting a virtual machine from VirtualBox will free up any storage space that was taken up by that VM and associated OS, including the associated VDI, VMDK, VHD or HDD files.

shasum and checksum

  • checksum : A checksum (also sometimes referred to as a hash) is an alphanumeric value that uniquely represents the contents of a file. Checksums are often used to verify the integrity of files downloaded from an external source, such as an installation file.
    -> 한 마디로 파일의 무결성을 확인할 수 있다.
  • shasum : The command computes the SHA-1 message digest of a file. 그리고, shasum 파일은 원본 파일과 정확히 동일한 파일인지 확인할때 체크되는 파일이다. 체크섬(checksum)정보가 포함되어있다.

VM(Virtual Machine)

가상 머신은 물리적 컴퓨터와 동일한 기능을 제공하는 소프트웨어 컴퓨터이다.

Debian VS CentOS

데비안과 센트스 모두 리눅스 배포판이다. 리눅스 배포판은 리눅스 커널 + 자유소프트웨어로 구성된 유닉스 계열의 운영체제를 말한다.

리눅스 커널 : 운영체제 내부에 위치하며 컴퓨터 하드웨어와 프로세스를 잇는 핵심 인터페이스를 말한다. 주요 기능으로는 ❶ 메모리관리 , ❷ 프로세스 관리 ❸ 장치 드라이버 관리 ❹ 시스템 호출 및 보안 등이 있다.

따라서 데비안과 센토스의 차이점은 자유 소프트웨어 부분인데, 패키지 포맷, 패키지 관리 툴 등이 차이점에 해당된다.

  • Debian :
    ❶ 패키지 포맷 : DEB 패키지 (deb라는 확장자를 가지며, 컴파일이 완료된 바이너리 파일 + 파일 정보를 의미한다.)
    ❷ 패키지 관리 툴 : apt, dpkg, aptitude
  • CentOS
    ❶ 패키지 포맷 : RPM
    ❷ 패키지 관리 툴 : YUM/DNF

Apt, Aptitude, AppArmor

  • Apt : 온라인 저장소에서 패키지를 다운받아 설치하며 자동으로 의존성처리를 해준다. 설치, 제거, 업데이트는 Apt단독으로 처리한다.
  • Aptitude : 패키지 작업 과정이 Apt보다 더 자동화 되어있다. (더 상위 수준의 툴이다.) 대화형 인터페이스, 비 대화형(command line interface)을 모두 제공한다.
  • AppArmor : 리눅스 보안 시스템이다. 접근통제 MAC을 기반으로 프로그램에 접근할 수 있는 파일을 규정하는 규칙집합에 따라 프로그램을 통제

    접근제어: 운영체제에서 dir, file, network socket에 에세스할 수 있는 사용자나 그룹을 통제하는 것을 의미한다.
    1) DAC(임의적 통제 방법) : 시스템 객체에 대한 접근을 사용자 또는 그룹의 신분을 기준으로 제한한다. 해당 객체의 소유자라면, 주체에 대한 접근 권한을 설정할 수 있다. 자신의 판단에 의해 권한을 줄 수 있기 때문에 임의적 통제 방법이라고 함.
    2) MAC(강제적 통제 방법) : 미리 정해진 정책과 보안 등급에 의거하여 접근을 통제한다. 관리자만이 객체의 보안레벨, 주체의 보안을 수정할 수 잇으며, 객체의 소유자라고 해도 정책에 어긋나면 객체에 접근할 수 없음. 높은 수준의 접근통제

UFW

🤷🏻‍♀️ UFW가 뭔뎅?
Uncomplicated Firewall is a program for managing a netfilter firewall designed to be easy to use.
A network security device that monitors and filters incoming and outgoing network traffic based on an organization's previously established security policies. At its most basic, a firewall is essentially the barrier that sits between a private internal network and the public Internet.
A firewall is a network security device that monitors traffic to or from your network. It allows or blocks traffic based on a defined set of security rules.

✅ 명령어 (더 많은 정보는 해당 블로그 확인!)

❶ UFW 활성화

sudo ufw enable

❷ UFW 비활성화

sudo ufw disable

❸ UFW 상태 확인

sudo ufw status verbose

❹ UFW 기본 정책 차단 혹은 허용

sudo ufw default deny/allow

❺ UFW 22번 포트 허용

sudo ufw allow 22

SSH

🤷🏻‍♀️ SSH가 뭔뎅?
SSH or Secure Shell is a network communication protocol that enables two computers to communicate (c.f http or hypertext transfer protocol, which is the protocol used to transfer hypertext such as web pages) and share data.

✅ 명령어 (해당 블로그 를 확인하길 권고함)
Debian에서 SSH서버는 openssh-server이라는 패캐지로 제공된다. 따라서 해당 패캐지가 설치되어 있지 않다면 아래 명령어를 통해 설치한다.

apt install openssh-server

❶ 서버 상태 확인

systemctl status ssh

❷ 원격에서 SSH 접속하기
원격에서 SSH서버에 접속하고자 한다면 해당 서버가 동작중인 컴퓨터의 ip를 알아야 한다. 이후 아래의 명령어를 통해 접속할 수 있다.

ssh 사용자이름@호스트이름 또는 ip주소

사용자 및 그룹 관리

해당 명령어들 다 옵션을 통해 자세하게 사용자와 그룹을 관리할 수 있다. /etc/passwd파일에는 user ID, group ID, home directory, shell 등등의 정보가 들어있다.

✅ 명령어 (더 자세한 정보는 link1, link2, link3)

❶ 그룹조회

cat /etc/group

❷ 그룹 추가

groupadd <그룹이름>

❸ 그룹에 사용자 추가

gpasswd -a <유저이름> <그룹이름>

❹ 그룹에서 사용자 삭제

gpasswd -d <유저이름> <그룹이름>

❺ 그룹 이름 변경

groupmod -n <그룹이름> <새그룹이름>

❶ 사용자 추가

useradd <사용자이름>
useradd -g <그룹이름> <사용자이름> #어느 그룹에 소속하는 사용자를 생성
useradd -g <그룹이름> -d <홈디렉토리> <사용자이름> #어느 그룹에 속하고 어느 위치를 홈 디렉토리로 가지오 있는 사용자 생성

패스워드 정책 관련(libpam-pwquality)

새 계정 설정에 대한 기본 값을 설정할 수 있는 파일은 login.defs이고, 암호의 강도를 조절하는 모듈은 libpam-pwquality이다.
❶ libpam-pwquality 설치

sudo apt install libpam-pwquality

❷ 패스워드 주어진 규칙에 맞춰 설정

sudo vi /etc/pam.d/common-password
  • retry=3 : 암호 입력 가능 횟수
  • minlen=10 : 암호 최소 길이
  • difok=7 : 기존 암호와 달라야 하는 문자 수
  • ucredit=-1 : 대문자 1개 이상 포함
  • lcredit = -1 : 소문자 1개 이상 포함
  • dcredit=-1 : 숫자 1개 이상 포함
  • reject_username : username 정방향/역방향 일치 시 거부
  • enforce_for_root : root 암호의 동일한 암호 정책 적용 여부
    *암호정책은 설정 후 생성된 계정에만 적용됨

❸ 기존 계정의 변경된 암호정책 적용 방법
사용자의 비밀번호를 만료시켜 다음 로그인때 비밀번호는 변경하도록 한다.

passwd -e <사용자명>

hostname

host : A host is any hardware device that has the capability of permitting access to a network via a user interface, specialized software, network address, protocol stack, or any other means.

🤷🏻‍♀️ hostname은 뭔데? IP랑 다른건가?
A host name is a combination of the name of your machine and a domain name (e.g. machinename.domain.com). The purpose of a host name is readability - it's much easier to remember than an IP address. All hostnames resolve to IP addresses, so in many instances they are talked about like they are interchangeable.
Just wanted to add that a host name resolves to an IP address by DNS

✅ 명령어 (더 자세한 설명은 해당 블로그 참조)

❶ 현재 호스트네임의 상태에 대한 display

hostnamectl 

❷ static hostname 바꾸기

hostnamectl set-hostname <호스트이름> –static

Partitions

Partition과 LVM의 차이
첫 번째 사진은 partition을, 두 번째 사진은 LVM을 간단하게 잘 표현하고 있다. 파티션은 한 드라이브내에서 부서(?)를 만들어주고, 디스크는 가지고 있는 전체 디스크를 자유자재로 나눠서 부서로 만들어주고 있다.

파티션과 LVM을 만드는 법은 해당 블로그를 참조하면 된다.

✅ 명령어 (더 자세한건 해당 블로그 참조)

❶ 스토리지 디바이스 정보 출력

lsblk

❷ 시스템 전체에 마운트된 디스크의 여유 용량 확인

df

❸ 디스크 사용량 확인

du

sudo

  • sudo : The sudo (superuser do) command is a command-line utility that allows a user to execute commands as the root or a different user.
  • sudoers file : The sudoers file is a file Linux and Unix administrators use to allocate system rights to system users. This allows the administrator to control who does what. When you want to run a command that requires root rights, Linux checks your username against the sudoers file.

위 sudoers을 수정할때 꼭 visudo라는 명령어를 사용해야지 그냥 해당 파일을 vi를 통해 열면 안된다. (이유 : if you use a plain editor, mess up the syntax, and save... sudo will (probably) stop working, and, since /etc/sudoers is only modifiable by root , you're stuck (unless you have another way of gaining root))

✅ sudoers 파일 수정하기 ❶ env_reset : HOME, LOGNAME, PATH, SHELL, TERM, USER을 제외한 모든 환경 변수를 reset시킨다.
❷ mail_badpass : 잘못된 패스워드로 sudo를 실행했을 시, 지정된 메일로 보고한다
❸ secure_path : sudo 명령을 실행할 때 현재 계정의 쉘이 아닌 새로운 쉘을 생성하고 그 안에서 명령을 실행하는데, 이 때 명령을 찾을 경로를 나열한 환경변수인 PATH값이 바로 이 secure_path가 됩니다. 즉, sudo 명령을 통해 실행하는 명령은 현재 계정의 쉘 환경도, 대신 실행하는 계정의 쉘 환경도 아닌 특별히 정의된 제 3의 쉘 환경에서 샌드박스 형태로 실행됩니다.
❹ passwd_tries : sudo 명령을 실행할 때, 패스워드 오류 가능 횟수를 지정한다.
❺ badpass_message : 잘못된 패스워드가 입력되었을 시, custom message를 출력한다.
❻ log_input, log_output, iolog_dir : sudo 를 통해 실행된 명령들, Input과 output에 대한 log 파일을 iolog_dir에 저장한다.
❼ requiretty : tty환경에서만 sudo 명령이 실행될 수 있도록 한다.
(When requiretty is set, sudo must be run from a logged-in terminal session (a tty). This prevents sudo from being used from daemons or other detached processes like cronjobs or webserver plugins. It also means you can't run it directly from an ssh call without setting up a terminal session.)

(평가할 때 일반 사용자로 로그인하여 sudo 명령어 아무거나 입력하고 다시 /var/log/sudo 파일에 들어갔을 때 명령어가 잘 들어갔는지 확인한다.)

Scrpit Monitoring

The sysstat package contains various utilities, common to many commercial Unixes, to monitor system performance and usage activity: 1) iostat reports CPU statistics and input/output statistics for block devices and partitions. 2) mpstat reports individual or combined processor related statistics.

crontab

crontab is a UNIX command that creates a table or list of commands, each of which is to be executed by the operating system at a specified time. (자세한 설명은 해당 블로그)

📌 BONUS

  • link1, link2에 자세한 설명있음. 설명할 수 있을만큼만 대충 정리헀음
  • Set up a functional WordPress website with the following services: lighttpd, MariaDB, and PHP.

WordPress(워드프레스)

간단하게 웹 사이트 제작 도구이다. 오픈소스 CMS 중 하나로 쉽게 생각하면, 오픈소스 블로그 혹은 홈페이지 저작 소프트웨어라고 보면 된다.

CGI(common gateway interface)

CGI란 웹서버와 외부프로그램을 연결해주는 인터페이스이다. 이를 통해서 정적 페이지는 동적페이지가 될 수 있는 것이다.

PHP

PHP is a server side scripting language.
VM에 설치한 컴퓨터는 서버, 맥컴퓨터는 클라이언트로 lighttpd를 통해 서로 연결이 될텐데, 서버쪽인 VM쪽에서는 외부프로그램으로써도 작동되어야 한다.(위 그림처럼 동적페이지로 작동해야징 워드프레스 보여주고) 따라서 PHP를 다운받을 것이다.
✅ 명령어

sudo apt-get install php7.3-fpm

lighttpd

과제에서 말한 WordPress라는 사이트를 set up하기 위해 우선 HTTP, SSH와 같은 서버를 설정해주자.

✅ 명령어

sudo apt-get install lighttpd #설치
sudo systemctl stop lighttpd.service #서버 중지
sudo systemctl start lighttpd.service #서버 시작
sudo systemctl enable lighttpd.service #서버 부팅

이후 lighttpd와 PHP를 연결해야 한다.
The Lighttpd configuration file for PHP = /etc/lighttpd/conf-available/15-fastcgi-php.conf

vi /etc/lighttpd/conf-available/15-fastcgi-php.conf

에서 소켓을 수정한다.
이후 lighttpd를 재실행하고,

✅ 명령어

sudo lighttpd-enable-mod fastcgi 
sudo lighttpd-enable-mod fastcgi-php
service lighttpd force-reload 

lighttpd를 통해 오픈되는 페이지가 wordpress가 될 수 있도록 아래 페이지를 열고 document-root가 되는 파일의 내부에 wordpress를 다운받자

vi /etc/lighttpd/lighttpd.conf


✅ 명령어

sudo apt-get install wget
sudo wget -O /tmp/wordpress.tar.gz "http://wordpress.org/latest.tar.gz"
sudo tar -xvzf /tmp/wordpress.tar.gz -C /var/www/html

MariaDB

데이터베이스로써 MariaDB를 사용할 것이다.

✅ 명령어

sudo apt-get install mariadb-server mariadb-client #설치
sudo systemctl stop mysql.service #서비스 중지
sudo systemctl start mysql.service #서비스 시작
sudo systemctl enable mysql.service	#서비스 부팅
sudo mysql_secure_installation #보안 설정 진행
sudo systemctl restart mysql.service #재시작

그 다음에는 데이터를 실제로 안에 만들어 준다

sudo mysql -u root -p

위 명령어를 통해 MariaDB에서 데이터베이스를 만들고, 사용자 등을 추가한다.

이후 wordpress와 MariaDB를 연동한다.

0개의 댓글