🛠️ToolsShed

Chmod 계산기

Unix 파일 권한을 계산합니다. 8진수와 기호(rwx) 표기 간 변환.

읽기 (r)쓰기 (w)실행 (x)8진수기호 표기
소유자6rw-
그룹4r--
기타4r--

8진수

644

기호 표기

rw-r--r--

chmod 명령어

chmod 644 filename

Chmod 계산기는 Unix/Linux 파일 권한 설정을 이해하고 생성하는 데 도움을 줍니다. Unix 기반 시스템에서 모든 파일과 디렉토리에는 소유자, 그룹, 다른 사용자들이 읽기, 쓰기 또는 실행할 수 있는지 제어하는 권한 비트 세트가 있습니다. `chmod` 명령은 기호 표기법(rwx) 또는 8진수(예: 755)로 권한을 설정합니다.

소유자, 그룹, 기타 열의 읽기, 쓰기, 실행 확인란을 토글하면 도구가 자동으로 동등한 8진수 값과 기호 문자열을 계산합니다. 반대로 644 같은 8진수 값을 입력하면 각 사용자 클래스에 대해 어떤 권한이 활성화되는지 보여줍니다.

일반적인 권한 패턴으로는 755(소유자는 모든 것 가능; 그룹과 다른 사람들은 읽기와 실행만 가능 — 디렉토리와 실행 파일에 전형적), 644(소유자는 읽기와 쓰기; 다른 사람들은 읽기만 가능 — 웹 파일에 전형적), 600(소유자만 읽기와 쓰기 가능 — SSH 개인 키에 전형적) 등이 있습니다.

자주 묻는 질문

코드 구현

import os
import stat

# Set permissions using octal notation
os.chmod('script.sh', 0o755)   # rwxr-xr-x (owner: rwx, group: r-x, others: r-x)
os.chmod('data.txt', 0o644)    # rw-r--r-- (owner: rw-, group: r--, others: r--)
os.chmod('private.key', 0o600) # rw------- (owner: rw-, no access for others)

# Read current permissions
file_stat = os.stat('script.sh')
mode = file_stat.st_mode
print(oct(stat.S_IMODE(mode)))  # e.g. '0o755'

# Check specific permissions using stat constants
is_owner_executable = bool(mode & stat.S_IXUSR)
is_group_readable   = bool(mode & stat.S_IRGRP)
is_others_writable  = bool(mode & stat.S_IWOTH)
print(f"Owner executable: {is_owner_executable}")

# Build permissions programmatically
perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH  # 644
os.chmod('config.ini', perms)

# Recursively set permissions on a directory tree
import pathlib
for path in pathlib.Path('/var/www/html').rglob('*'):
    if path.is_dir():
        os.chmod(path, 0o755)
    else:
        os.chmod(path, 0o644)

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.