[카테고리:] 미분류

  • CMake Quick Guide

    1. 개요

    CMake는 C/C++ 등 여러 프로그래밍 언어로 작성된 프로젝트의 빌드 자동화 도구입니다. GNU Make나 Ninja 같은 하위 빌드 시스템의 설정 파일을 생성하는 메타 빌드 시스템(Meta Build System) 이라고 할 수 있습니다.

    2. CMake의 핵심 개념

    2.1. CMakeLists.txt

    • CMake 프로젝트는 이 파일을 중심으로 구성됩니다.
    • 빌드 설정, 소스 코드 목록, 컴파일 옵션 등을 명시합니다.

    2.2. 빌드 디렉토리 분리 (Out-of-source build)

    • 소스 코드와 빌드 결과물을 분리하여 관리 가능
    • 예:
    Bash
    mkdir build
    cd build
    cmake ..
    make
    Bash

    2.3. 다양한 플랫폼 지원

    • Windows, macOS, Linux 등에서 동일한 CMakeLists.txt로 빌드 구성 가능
    • Visual Studio, Makefile, Ninja 등 다양한 빌드 시스템을 지원

    3. 주요 명령어

    명령어설명
    cmake .현재 디렉토리의 CMakeLists.txt를 바탕으로 빌드 설정 생성
    cmake ..상위 디렉토리의 CMakeLists.txt를 사용해 빌드 설정 생성
    make생성된 Makefile로 실제 빌드 수행
    cmake --build .플랫폼 독립적 빌드 명령

    4. 주요 기능

    • install, test, configure_file 등 다양한 프로젝트 관리 기능 내장
    • find_package로 외부 라이브러리 탐색
    • target_link_libraries로 라이브러리 연결
    • option, if 등을 활용한 조건부 설정

    5. 예시 프로젝트 구조

    Bash
    MyProject/
    ├── CMakeLists.txt
    ├── main.cpp
    ├── utils.cpp
    └── build/      # 빌드 파일 생성 위치 (Out-of-source build)
    Bash

    6. CMake의 장점

    • 다양한 옵션 제공: 테스트, 설치, 패키징 등 통합 관리
    • 유지보수 용이: 큰 프로젝트에서도 구성 관리가 쉬움
    • 크로스 플랫폼: 다양한 OS 및 빌드 도구에 대응
    • 모듈화: 서브 디렉토리 단위 구성 가능
  • Linux – Service and Daemons

    1. SysVinit서비스

    • /etc/init.d : SysVinit(Unix System Five Init) 기반의 Linux 시스템에서 시스템 서비스(데몬)를 관리하는 스크립트들이 위치하는 디렉터리
    • 서비스(daemon)의 시작(start), 정지(stop), 재시작(restart) 등을 제어하기 위한 실행 스크립트 모음이 저장된 디렉토리
    • 스크립트는 start, stop, restart, status 등의 서브 커맨드를 지원
    • 대부분의 최신 Linux 배포판(Ubuntu 16.04+, Debian Jessie+, CentOS 7+)에서는 /etc/init.d 대신 **systemd**가 사용

    2. systemctl

    • /etc/systemd/system 디렉토리에 명세파일이 존재
    • systemd라는 시스템 및 서비스 관리자를 기반으로 작동
    • 현재 대부분의 리눅스 배포판(Ubuntu, CentOS, Debian, Fedora 등)에서 systemd가 기본 init 시스템으로 사용

    example – vsftpd’s status:

    Bash
    # systemctl status vsftpd
     vsftpd.service - vsftpd FTP server
         Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
         Active: active (running) since Mon 2025-04-28 07:30:24 UTC; 1 week 2 days ago
       Main PID: 928 (vsftpd)
          Tasks: 1 (limit: 76878)
         Memory: 14.2M
            CPU: 1min 48.897s
         CGroup: /system.slice/vsftpd.service
                 └─928 /usr/sbin/vsftpd /etc/vsftpd.conf
    
    Apr 28 07:30:24 centricone systemd[1]: Starting vsftpd FTP server...
    Apr 28 07:30:24 centricone systemd[1]: Started vsftpd FTP server.
    root@centricone:~# 
    Bash

    예시 데몬:

    • *d: httpd, sshd, ftpd, vsftpd, proftpd, mariadbd, mysqld

    3. systemctl 명령

    • systemctlsystemd 데몬을 제어하는 명령줄 도구
    • 주로 서비스 시작/중지, 부팅 시 자동 실행 설정, 상태 확인, 로그 조회 등을 관리합니다.
    • init.dservice 명령의 대체 명령(init.d의 service 명령은 구식)

    4. systemctl 서비스 제어 명령

    명령어설명
    systemctl start [서비스명]서비스 시작
    systemctl stop [서비스명]서비스 중지
    systemctl restart [서비스명]서비스 재시작
    systemctl reload [서비스명]설정만 다시 읽기 (재시작 없이)
    systemctl status [서비스명]서비스 상태 확인
    systemctl enable [서비스명]부팅 시 자동 시작 설정
    systemctl disable [서비스명]자동 시작 비활성화
    systemctl is-enabled [서비스명]현재 자동 시작 여부 확인
    systemctl mask [서비스명]서비스 실행 완전 차단 (시작 불가)
    systemctl unmask [서비스명]mask 해제 (다시 실행 가능하게)

    5. systemctl 전체 시스템 관리 명령

    명령어설명
    systemctl list-units --type=service실행 중인 서비스 목록
    systemctl list-unit-files설치된 서비스 목록과 활성화 상태
    systemctl reboot시스템 재부팅
    systemctl poweroff시스템 종료
    systemctl suspend시스템 절전 모드
    systemctl halt시스템 정지 (전원은 켜짐)
    systemctl isolate [타겟명]런레벨(타겟) 전환 (예: multi-user → graphical)

    6. 서비스 예시

    Bash
    systemctl start nginx          # nginx 서버 시작
    systemctl status sshd         # SSH 서비스 상태 확인
    systemctl enable apache2      # 부팅 시 아파치 자동 시작
    systemctl stop firewalld      # 방화벽 서비스 중지
    systemctl restart NetworkManager
    Bash

  • Linux – Network-related Commands

    1. 네트워크 정보 확인

    • ip, ifconfig, arp, nslookup
    Bash
    ip addr            # IP 주소 및 인터페이스 정보 확인
    ip link	           # 인터페이스 상태 및 MAC 주소 확인
    ifconfig           # 예전방식의 IP 주소 및 인터페이스 정보 확인
    arp -a             # ARP (Address Resolution Protocol) 캐시 테이블 조회
    ip neigh           # ARP (Address Resolution Protocol) 캐시 테이블 조회
    nslookup           # dns 정보 조회
    ifconfig          # 인터페이스별 IP, MAC, 상태 확인
    ifconfig eth0 up  # 인터페이스 활성화
    ifconfig eth0 down # 인터페이스 비활성화
    Bash


     
     


     
     
     
     
     
     

    2. 네트워크 확인 및 진단

    Bash
    ping	        # ICMP 패킷을 통해 호스트와 연결 여부 확인
    traceroute	  # 패킷의 경로(라우터 hop)를 추적
    tracepath	    # 유사한 기능, 비root 환경에서 사용 가능
    Bash

    2.1. 연결상태 진단

    • ss : socket statistics
    Bash
    ss -tuln            # 열려 있는 TCP/UDP 포트 확인
    ss -pant            # 포트 + 프로세스 정보
    Bash
    • netstat
    Bash
    netstat -anp
    Bash


     
     

    2.1. 웹페이지 또는 웹애플리케이션 진단

    • wget, curl
    Bash
    curl	        # HTTP 요청 테스트	curl -I http://example.com
    wget	        # 파일 다운로드 및 HTTP 상태 확인	wget http://example.com
    curl http://example.com
    wget http://example.com
    Bash
    • 웹 요청 전송 및 응답 확인 (HTTP 테스트)
    • curl -I : 헤더만 보기


     
     


     
     


     
     

    3. 방화벽

    • UFW (Uncomplicated Firewall)
    Bash
    sudo ufw enable                # 방화벽 활성화
    sudo ufw status                # 현재 상태 확인
    sudo ufw allow 22              # SSH 허용
    sudo ufw deny 80               # HTTP 차단
    sudo ufw delete allow 22       # 규칙 삭제
    sudo ufw default deny incoming # 기본 정책 설정
    Bash
    • ssh 서버로만 incoming 접속을 허용하는 방화벽 설정
    Bash
    sudo ufw default deny incoming
    sudo ufw default allow outgoing
    sudo ufw allow 22/tcp
    sudo ufw enable
    Bash
    • 주의! : 간편하지만 위험
    Bash
    sudo ufw disable
    Bash

    4. 네트워크 관련 파일

    • /etc/hosts : 로컬 파일에 저장된 호스트 이름
    • /etc/hostname : 해당 서버의 호스트 이름
    • /etc/services : 포트별 서비스 이름
      • 포트 번호와 서비스 이름의 매핑 정보 제공
    • /etc/resolv.conf
      • DNS 서버 주소를 지정하는 파일 (이름 해석용)

    5. netcat을 이용한 서버/클라이언트 시험

    Bash
    netcat -lvvp 8080        # 서버 실행
    telnet ipaddr 8080       # 접속
    (웹브라우저로 접속)
    Bash

  • Linux – Shell Scripting


     
     


     
     


     
     


     
     

    1. 쉘(Shell)이란?

    • 쉘(Shell)은 사용자와 커널 사이의 인터페이스로, 명령어를 입력하면 커널이 수행할 수 있도록 해주는 프로그램
    • 리눅스에서 가장 많이 사용되는 쉘은 bash (Bourne Again SHell)


     
     
     
     


     
     


     
     


     
     

    2. 쉘 스크립트란?

    • 쉘 스크립트(Shell Script)는 쉘 명령어들을 모아 놓은 텍스트 파일
    • 즉, 사람이 매번 입력하는 명령어들을 자동으로 순서대로 실행할 수 있도록 작성한 자동화 프로그램
    • 확장자는 .sh가 일반적이지만 필수는 아님


     
     


     
     


     
     
     
     
     
     
     
     

    3. 기본 예제

    Bash
    #!/bin/bash
    # 위의 줄은 shebang, 스크립트를 bash로 실행한다는 의미
    
    echo "Hello, World!"
    Bash
    • #!/bin/bash: bash 쉘로 실행하도록 지정
    • echo: 문자열 출력


     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    3.1. 실행 방법

    Bash
    chmod +x script.sh     # 실행 권한 부여
    ./script.sh            # 실행
    Bash


     
     
     
     
     
     
     
     
     
     


     
     


     
     

    4. 주요 문법

    4.1. 변수 선언

    Bash
    NAME="Danny"
    echo "Hello, $NAME"
    Bash
    • 변수명은 공백 없이 =로 할당
    • $변수명으로 접근

    4.2. 명령 실행 파라미터

    Bash
    ./myscript.sh arg1 arg2 arg3
    Bash
    표현의미
    $0스크립트 이름 (myscript.sh)
    $1, $2첫 번째, 두 번째 인자
    $#인자의 개수
    $@인자 전체 목록 (각각 독립적으로 처리됨)
    $*인자 전체 목록 (하나의 문자열로 처리됨)


     
     
     
     
     
     
     
     


     
     

    4.3. 조건문 (if)

    Bash
    #!/bin/bash
    
    AGE=10
    
    if [ $AGE -ge 18 ]; then
        echo "Adult"
    else
        echo "Minor"
    fi
    Bash
    • [ 조건식 ] 또는 [[ 조건식 ]]
    • 숫자 비교 연산자: -eq, -ne, -lt, -le, -gt, -ge
    • 문자열 비교: =, !=
    Bash
    #!/bin/bash
    
    STRING1=abcde
    
    if [ "$STR1"="abcde" ]; then
      echo "is 'abcde'"
    else
      echo "not 'abcde'"
    fi
    Bash


     
     
     
     

    4.4. 반복문 (for, while)

    for문 예시:

    Bash
    #!/bin/bash
    
    for FILE in *.txt
    do
        echo "Processing $FILE"
    done
    Bash

    실행 결과:

    Bash
    $ ls -l
    run.sh         a.txt        b.txt        c.txt 
    $ bash run.sh
    Processing a.txt
    Processing b.txt
    Processing c.txt
    $
    Bash


     
     


     
     

    while문 예시:

    Bash
    COUNT=1
    while [ $COUNT -le 5 ]
    do
        echo "Count: $COUNT"
        COUNT=$((COUNT+1))
    done
    Bash


     
     
     
     
     
     
     
     


     
     


     
     
     
     
     
     


     
     

    4.5. 사용자 입력 받기

    Bash
    read -p "Enter your name: " USERNAME
    echo "Welcome, $USERNAME"
    Bash


     
     
     
     
     
     
     
     


     
     


     
     


     
     


     
     

    5. 변수, 환경변수

    5.1. Common Bash Environment Variables

    VariablePurpose
    PATHList of directories for finding executables
    HOMECurrent user’s home directory
    USERCurrent logged-in user
    PWDPresent working directory
    SHELLPath to the current shell
    LANGLanguage and locale
    EDITORDefault text editor (e.g., vim, nano)
    TERMTerminal type (e.g., xterm-256color)


     
     
     
     

    5.2. 변수 값 출력하기

    Bash
    echo $HOME
    Bash


     
     
     
     

    5.3. 변수 생성하기

    Bash
    MY_NAME="Danny"
    Bash


     
     
     
     

    5.4. 변수를 환경변수로 만들기

    Bash
    export MY_NAME
    Bash
    • 자식 프로세스에게도 환경변수가 전달됨


     
     
     
     


     
     

    6. 함수 정의

    • 자주 사용하는 코드를 함수로 정의하여 사용
    Bash
    function fname() {
      echo $1
    }
    
    fname "1"
    fname "2"
    fname "3"
    Bash
    • $1, $2 …은 함수 인자

    Bash
    $ bash run.sh
    1
    2
    3 
    Bash

    6.1. 함수 내 로컬 변수

    • 함수 내에서만 존재하고 실행 후에는 사라지는 변수
    Bash
    #!/bin/bash
    
    function fname() {
      local a=100
      echo $a
    }
    
    fname 
    echo $a
    fname
    fname
    Bash

    Bash
    $ bash run.sh
    100
    
    100
    100
    $ 
    Bash

    6.3. $? : exit status

    • command’s return value
    Bash
    $ ls /aaa
    ls: cannot access '/aaa': No such file or directory
    $ echo $?
    2
    
    $ ls /etc/passwd
    /etc/passwd
    $ echo $?
    0
    
    $ cat run.sh
    exit 100
    $ bash run.sh
    $ echo $?
    100
    Bash
    • function’s return value
    Bash
    #!/bin/bash
    
    function isBiggerThan100() {
      if [ $1 -gt 100 ]; then
        return 1
      else
        return 0
      fi
    }
    
    isBiggerThan100 99
    echo $?
    isBiggerThan100 101
    echo $?
    Bash

    실행결과:

    Bash
    $ bash f.sh
    0
    1
    Bash


     
     

    7. Linux Shell Command Operators

    • > / >> (Output Redirection)
    • 2>2>&1&>, etc. (Error redirection) 
    • < (Input Redirection)
    • && (AND)
    • || (OR)
    • & (Background)
    • ; (Sequential execution)
    • () (Subshell)
    • {} (Command group in current shell)
    • | (Pipe)


     
     


     
     

    8. 실용 예제



     
     

    8.1. 프로세스 자동 재시작

    Bash
    #!/bin/bash
    if ! pgrep nginx > /dev/null
    then
        echo "Nginx is not running. Restarting..."
        systemctl start nginx
    fi
    Bash


     
     
     
     
     
     
     
     
     
     
     
     

  • Linux – commands & options

    1. 기본 개념: 옵션(Options)이란?

    옵션은 명령어의 동작 방식을 조정하는 부가적인 설정값

    2. Short Options (-x 형식)

    항목설명
    형식- + 한 글자 (-a, -l 등)
    특징짧고 간단하며 하나의 문자만 허용
    조합 가능 여부여러 개를 하나로 묶을 수 있음 (-al)

    예시:

    Bash
    ls -l      # long listing format
    ls -a      # show hidden files
    ls -la     # 두 옵션을 함께
    Bash

    이건 ls -l -a 와 동일함


    3. Long Options (--option 형식)

    항목설명
    형식-- + 전체 이름 (--help, --version)
    특징가독성이 좋고 의미가 명확
    조합 가능 여부묶을 수 없음. 각 옵션은 개별적으로 지정해야 함

    long option 예시:

    Bash
    ls --all           # 숨긴 파일도 보여줌
    ls --format=long   # 출력 포맷 설정
    rm --recursive     # 디렉토리도 재귀적으로 삭제
    Bash

    short/long 비교 예:

    Bash
    grep -i "text" file.txt       # -i = ignore case
    grep --ignore-case "text" file.txt  # 동일한 기능, long option 사용
    Bash

    4. 어떻게 구현되는가?

    각 명령어 도구에서 내부적으로:

    • getopt() 또는 getopt_long() (GNU 확장) 함수로 처리
    • ls, grep, cp, rm 등 GNU coreutils는 대부분 short + long 옵션 둘 다 지원

    5. 옵션 사용 도움말 보기

    Bash
    ls --help
    grep --help
    Bash

    또는:

    Bash
    man ls
    man grep
    Bash


    6. 요약

    구분Short OptionLong Option
    형식-x--option
    가독성낮음높음
    조합 가능여러 개 묶기 가능 (-al)묶을 수 없음 (--a --b)
    사용 목적빠르고 간결한 입력명확한 의미 전달

    find

    Bash
    find . -name "*.c" -exec ls -l {} \;
    Bash

    (단, 이건 한 번만 실행되는 게 아니라, .c 파일 하나하나마다 ls -l이 실행됨)

    확장된 예시

    🔁 모든 .c 파일을 한 번에 전달하고 싶을 때

    Bash
    find . -name "*.c" -exec ls -l {} +
    Bash
    Bash
    find . -name "*.c" | xargs ls -l
    Bash

    +는 여러 개의 결과를 한 번의 명령으로 전달

    즉, 아래처럼 실행됨:

    Bash
    ls -l file1.c file2.c file3.c ...
    Bash

    성능면에서 훨씬 효율적 (프로세스를 여러 번 만들지 않음)

    하나 더 개선:

    Bash
    find . -name "*.c" -exec ls -l {} + 2> /dev/null
    Bash

    에러 출력을 버림

    Bash
    find . -name "*.c" | xargs ls -l
    Bash
    • xargsfind의 출력값을 인수로 변환해 ls -l에 전달
    • 단, 파일명이 공백/특수문자를 포함할 경우 오류 발생 가능

    → 해결책: 공백 처리하려면 -print0xargs -0 조합 사용:

    Bash
    find . -name "*.c" -print0 | xargs -0 ls -l
    Bash

    Linux Package Managers

    • yum
    • apt : ubuntu
      • sudo apt update
      • sudo apt-get install
      • sudo apt-get remove
      • apt-cache search keyword
      • apt-cache show aptitude
    • apk : alpine

  • Useful vscode extensions

    0. Introduction

    There are so many extensions in vs code.

    In this document, let me introduce some useful vscode extensions

    1. Prettier – Code formatter

    2. Markdown PDF

    • Markdown 문서를 Ctrl+Shift+p 단축키 후 PDF변환 실행

    3. Paste Image

    • Markdown 문서에 Ctrl+Alt+v단축키로 이미지 첨부

    4. REST Client

    • POST 요청 등을 처리

    5. Thunder Client

    • POST 요청 등을 처리 (GUI)

  • Linux – Process

    1. 프로세스란?

    • 실행중인 프로그램을 프로세스라고 부름
    • 하나의 프로그램에서 여러개의 프로세스 실행이 가능
    • 리눅스 커널은 프로세스를 process id로 구분


     
     
     
     
     
     
     
     
     
     
     
     


     
     

    2. 부모-자식 프로세스 관계

    • 모든 프로세스는 부모 프로세스로부터 파생
    • init 또는 systemd가 대부분의 프로세스의 최상위 부모
    • 자식은 부모 종료 시 init이 대신 관리
    • 부모 PID: PPID : parent pid
    Bash
    ps -eax -o pid,ppid,cmd
    Bash


     
     
     
     
     
     
     
     
     
     
     
     
     

    3. 프로세스 관련 명령

    • ps : process status
    Bash
    ps
    ps aux          # 모든 사용자의 프로세스 보기
    ps -ef          # 전체 포맷 출력
    Bash
    Bash
    $ ps -eaf
    UID          PID    PPID  C STIME TTY          TIME CMD
    root           1       0  0 Apr28 ?        00:00:59 /sbin/init
    root           2       0  0 Apr28 ?        00:00:00 [kthreadd]
    root           3       2  0 Apr28 ?        00:00:00 [rcu_gp]
    root           4       2  0 Apr28 ?        00:00:00 [rcu_par_gp]
    root           5       2  0 Apr28 ?        00:00:00 [slub_flushwq]
    
    root         928       1  0 Apr28 ?        00:00:00 /usr/sbin/vsftpd /etc/vsftpd.conf
    Bash
    • pstree
    Bash
    pstree
    pstree -p
    Bash
    Bash
    $ pstree -p
    systemd(1)─┬─ModemManager(973)─┬─{ModemManager}(1013)
                                  └─{ModemManager}(1034)
               ├─agetty(974)
               ├─containerd-shim(2237)─┬─sh(2307)───npm run 
               
    ......
               
               ├─systemd(286541)───(sd-pam)(286542)
               ├─systemd-journal(518)
               ├─systemd-logind(908)
               ├─systemd-network(864)
               ├─systemd-resolve(866)
               ├─systemd-timesyn(812)───{systemd-timesyn}(820)
               ├─systemd-udevd(564)
               ├─thermald(913)───{thermald}(983)
               ├─udisksd(914)─┬─{udisksd}(950)
                             ├─{udisksd}(954)
                             ├─{udisksd}(1029)
                             └─{udisksd}(1107)
               ├─unattended-upgr(1000)───{unattended-upgr}(1075)
               ├─upowerd(9078)─┬─{upowerd}(9080)
                              └─{upowerd}(9081)
               └─vsftpd(928)
    Bash
    • kill : 프로세스로 시그널 보내기
    Bash
    kill -9 pid
    Bash
    • top : 프로세스 목록을 실시간 모니터링
    Bash
    top
    Bash
    • pidof : 프로세스이름으로 PID찾기
    Bash
    pidof nginx               # nginx 프로세스 PID 찾기
    ps -eaf | grep nginx      # nginx 프로세스를 문자열로 필터
    Bash
    • 터미널에서 단축키 사용
      • Ctrl + z,
      • jobs
      • bg : switch to background
      • fg : switch to foreground


     
     


     
     


     
     


     
     


     
     


     
     

    4. 프로세스 권한

    • 리눅스에서 각 프로세스는 User와 Group속성을 가짐
    • 이러한 정보는 커널이 다음을 판단하는 데 사용:
      • 어떤 자원(파일, 디바이스, 포트 등)에 접근 가능한가
      • 어떤 프로세스를 제어(kill, attach 등)할 수 있는가
    • root 계정의 쉘 프롬프트는 #
    • 일반 계정의 쉘 프롬프트는 $


     
     


     
     
     
     
     
     
     
     
     
     

    5. 프로세스 권한 관련 명령

    • ps로 권한정보 조회
    Bash
    ps -o pid,user,uid,euid,egid,cmd -p PID
    Bash
    • id, whoami
    Bash
    id
    whoami
    Bash


     
     


     
     

    6. su, sudo

    • su : run a command with substitute user and group ID
    Bash
    su - danny
    su -l
    Bash
    • sudo : execute a command as another user
    Bash
    sudo vi /etc/shadow
    sudo su -
    Bash

  • Linux – File and Directory

    1. 리눅스의 주요 디렉토리

    • ubuntu 리눅스를 기준으로 한 디렉토리 구성
    디렉토리설명
    /루트 디렉토리. 모든 파일과 디렉토리의 최상위 경로
    /bin필수 실행 파일(binary). 부팅과 기본 명령어(ls, cp, mv, cat 등)가 들어있음
    /sbin시스템 관리자용 시스템 바이너리 (fsck, reboot, mount 등)
    /boot커널 및 부팅 관련 파일 (vmlinuz, initrd, grub 등)
    /dev디바이스 파일. 하드웨어 장치를 파일처럼 다룸 (/dev/sda, /dev/tty 등)
    /etc설정 파일(설정 디렉토리). 시스템 전반의 설정 (passwd, fstab, network/, systemd/)
    /home일반 사용자들의 개인 홈 디렉토리 (/home/user)
    /lib, /lib64커널과 기본 명령어에 필요한 공유 라이브러리 파일 (.so)
    /mediaUSB, CD-ROM 등 자동 마운트 장치의 마운트 위치
    /mnt임시 마운트 지점. 수동으로 외부 장치를 마운트할 때 사용
    /opt추가 소프트웨어 패키지 설치 경로 (예: Google Chrome, VMware 등 외부 앱)
    /proc커널과 프로세스 정보 제공하는 가상 파일 시스템 (/proc/cpuinfo, /proc/meminfo)
    /root루트(root) 사용자의 홈 디렉토리 (/home/root가 아님)
    /run시스템 런타임 정보 저장. 부팅 중에 임시로 사용되는 데이터
    /srv웹 서버, FTP 등의 서비스용 데이터 디렉토리 (/srv/www, /srv/ftp)
    /sys커널과 하드웨어 정보를 보여주는 가상 파일 시스템. /proc과 유사
    /tmp임시 파일 저장소. 재부팅하면 삭제됨
    /usr사용자 애플리케이션과 파일이 위치함. 시스템과 사용자 공용 리소스
    /var로그, 캐시, 메일 큐, 프린트 스풀 등 가변 데이터 저장 (/var/log, /var/tmp)


     
     


     
     


     
     


     
     


     
     


     
     


     
     

    2. 파일 퍼미션 (File Permission)

    리눅스에서는 각 파일과 디렉토리에 대해 세 가지 사용자 그룹에게 권한을 설정합니다:

    1. 소유자(User) – 파일을 만든 사용자
    2. 그룹(Group) – 파일이 속한 그룹
    3. 기타(Others) – 위 둘을 제외한 나머지 모든 사용자

    각 사용자 그룹에 대해 설정할 수 있는 권한은 다음과 같습니다:

    기호의미설명
    rRead읽기
    wWrite쓰기
    xExecute실행


     
     


     
     


     
     


     
     

    3. 디렉토리 퍼미션

    권한의미
    r디렉토리 내용 목록 보기 (ls)
    w디렉토리에 파일 생성/삭제
    x디렉토리에 진입 가능 (cd)

    예를 들어 r-x만 있다면 디렉토리에 들어가서 내용을 볼 수는 있지만, 파일을 생성하거나 삭제는 불가


     
     


     
     


     
     


     
     


     
     


     
     


     
     

    4. 파일 및 디렉토리 관련 명령

    • ls: 파일 및 디렉토리 조회
    Bash
    ls
    ls -l
    ls -al
    ls -alR
    Bash
    • df: 파일 용량 조회
    Bash
    df
    df -h
    Bash
    • du: 디스크 용량 조회
    Bash
    du
    du -skm
    Bash
    • chmod: 파일, 디렉토리 퍼미션 변경
    Bash
    chmod 777 file
    chmod 755 directory
    chmod +x run.sh
    chmod u-x file
    chmod o-x directory
    Bash
    • chown: 파일, 디렉토 소유자 변경
    Bash
    chown root:root file
    chown www:www directory
    Bash
    • tar, gzip, zip: 파일 압축
    Bash
    tar cvzf compressed.tar.gz aa bb cc     # 압축 파일 생성
    tar tvzf compressed.tar.gz              # 압축된 파일 목록 출력
    tar xvzf compressed.tar.gz              # 압축 해제 
    Bash
    • cd, pwd : 디렉토리 이동, 현재 디렉토리 정보
    • mkdir, rmdir : 디렉토리 생성, 삭제
    • cp, mv : 파일/디렉토리 복사/이동
    • cat, more, less : 파일 내용 보기
    • which : 명령어 경로 조회
    Bash
    which ls
    which git
    Bash
    • find : 파일 찾기
      • 생각 이상으로 유용하고 자주 사용되는 명령
    Bash
    find . -name "*.png" -exec ls -l {} \;
    Bash

  • Linux Distributions

    0.


     
     
     
     
     
     
     
     

    1. 리눅스 배포판이란?

    A collection of software based on the Linux kernel

    • 리눅스 커널을 기반으로 다양한 소프트웨어를 조합하여 만든 완전한 운영체제
    • 리눅스 커널은 시스템의 핵심(Core)일 뿐이기 때문에, 배포판에는 실제 사용을 위한 다양한 프로그램들이 함께 포함


     
     
     
     
     
     
     
     
     
     
     
     

    2. 리눅스 배포판의 구성 요소

    일반적인 리눅스 배포판에는 다음과 같은 구성 요소가 포함됩니다:

    • 리눅스 커널 – 하드웨어 자원을 관리하는 운영체제의 핵심.
    • GNU 유틸리티 – 기본적인 시스템 명령어 및 도구 (bash, cp, ls 등).
    • 패키지 관리자 – 프로그램 설치 및 업데이트 도구 (apt, yum, dnf, pacman 등).
    • 그래픽 사용자 인터페이스(GUI) – GNOME, KDE, XFCE 등의 데스크탑 환경 (선택사항).
    • 사용자 애플리케이션 – 웹 브라우저, 파일 관리자, 오피스 프로그램 등.


     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    2. 대표적인 리눅스 배포판 예시

    배포판마다 특징과 대상 사용자가 다릅니다.

    배포판설명
    Ubuntu사용자가 많고 친숙하며 초보자에게 추천.
    Debian안정성이 높고, 다른 배포판의 기반이 됨 (예: Ubuntu).
    Fedora최신 기술 적용이 빠르고 Red Hat이 후원.
    CentOS / AlmaLinux / Rocky Linux서버용으로 안정적이며 기업 환경에 적합.
    Arch Linux최소한의 시스템, 고급 사용자에게 적합.
    Alpine Linux초경량 배포판, 보안 최적화, 도커 컨테이너에서 자주 사용
    Kali Linux보안 테스트용, 해킹 및 침투 테스트에 특화됨.
    • Alpine Linux: 초소형, 보안 중심의 Linux 배포판
      • BusyBox는 Linux/Unix 환경에서 매우 널리 사용되는 초경량 유틸리티 도구 모음
      • 하나의 실행 파일로 수많은 셸 명령어들을 구현
      • 임베디드 시스템이나 도커(Docker) 기반 컨테이너 이미지에서 핵심 구성 요소로 사용
      • 패키지 설치에 apk(Alpine Package Keeper) 사용


     


     
     


     
     


     
     


     
     


     
     
     
     
     
     
     
     
     
     
     
     


     
     

    3. 어떤 배포판을 선택할까?

    사용 목적에 따라 적합한 배포판이 달라집니다:

    • 리눅스 입문자: Ubuntu, Linux Mint
    • 서버 운영: Debian, CentOS, AlmaLinux
    • 보안/해킹: Kali Linux, Parrot OS
    • 직접 커스터마이징하고 싶은 경우: Arch Linux, Gentoo


     
     
     
     
     
     
     
     
     
     


     

     
     
     
     
     
     
     
      

    Tip. 배포판 정보 조회

    Bash
    cat /etc/os-release
    cat /etc/issue
    cat /etc/issue.net
    uname -a
    Bash


     
      
     
      
     
      
     
      
     
      
     
      

  • Training

     
     

     
     

     
     

     
     

     
     

     
     

     
     


    1. 개요

    Improving job performance is very important.

      
     

      
     

      
     

     
      
      
      
      
      
     


     

    2. Linux Operating System


     
     

    2.1. LInux Distributions


     
     
     

    2.2. File and Directory


     
     
     
     

    2.3. Process


     
     
     
     

    2.4. Shell Scripting


     
     


     
     
     
     

    2.5. Commands & Options


     
     


     
     


     
     

    2.6. Linux – Network Commands


     
     
     
     

    2.7. Linux – Service and Daemons


     
     


     
     

    2.8. Linux – misc.

    • editor: vim, nano


     
     
     
     

    3. Docker

    3.1. 도커 소개

    3.2. 실습환경 구축

    • docker desktop 설치

    3.3. 실습1: Hello world 실행

    Bash
    docker container run --rm hello-world
    Bash

    3.4. 실습2: Interactive Shell 실행

    Bash
    docker container run --interactive --tty ubuntu
    Bash

    3.5. 실습3: container run – env

    3.6. docker-compose – down과 stop의 차이

    3.7. 실습: Dockerfile로 디렉터리 볼륨 마운트하기

    • volume의 개념: 컨테이너와 스토리지의 life cycle을 분리
    • VOLUME 인스트럭션을 이용
      • docker volume ls
      • docker volume create volume_name
      • docker container run -v volume_name:$target

    3.8. 실습: bind mount 이용

    Bash
    docker container run --mount type=bind,source=$source,target=$target -d
    Bash

    3.9. 실습: docker를 이용해 user권한의 python webserver를 구동하기

    파일구조는 다음과 같다.

    Bash
    python-webserver/
    ├── Dockerfile
    └── app/
         └── server.py
    Bash

    3.9.1. Dockerfile

    Dockerfile
    # Dockerfile
    FROM python:3.10-slim
    
    # 시스템 사용자 및 그룹 생성
    RUN groupadd -r appuser && useradd -r -g appuser -d /app appuser
    
    # 앱 디렉토리 생성 및 복사
    WORKDIR /app
    COPY app/ /app/
    
    # 권한 부여
    RUN chown -R appuser:appuser /app
    
    # 비루트 사용자로 실행
    USER appuser
    
    # 서버 실행
    CMD ["python", "server.py"]
    Dockerfile


     
     

    3.9.2. server.py

    Python
    # app/server.py
    from http.server import HTTPServer, SimpleHTTPRequestHandler
    
    PORT = 8000
    print(f"Serving on port {PORT}")
    httpd = HTTPServer(("0.0.0.0", PORT), SimpleHTTPRequestHandler)
    httpd.serve_forever()
    Python


     
     

    3.9.3. 빌드 & 실행

    Bash
    # 빌드
    docker build -t python-webserver .
    
    # 실행 (포트 8000 바인딩)
    docker run -p 8000:8000 python-webserver
    Bash

    3.9.4. 개선 – detach

    Bash
    # 빌드
    docker build -t python-webserver .
    
    # 실행 (포트 8000 바인딩)
    docker run --rm --detach -p 8000:8000 python-webserver
    Bash