Skip to Content
문서운영시스템 관리사용자 및 권한

사용자 및 권한

Ubuntu은 다중 사용자 운영 체제이며 적절한 사용자 관리 및 권한 구성은 시스템 보안의 초석입니다. 이 문서에서는 Ubuntu 26.04에서 사용자를 생성 및 관리하고, 그룹을 구성하고, 파일 권한 시스템을 이해하는 방법을 설명합니다.

사용자 관리

사용자 생성

useradd을 사용하여 새 사용자를 만듭니다.

# Create a user with a home directory sudo useradd -m -s /bin/bash username # Set the password sudo passwd username

adduser 명령은 설정 과정을 안내하는 대화형 래퍼 스크립트이므로 선호됩니다.

sudo adduser username

사용자 속성 수정

기존 사용자 속성을 수정하려면 usermod을 사용하세요.

# Change the default shell sudo usermod -s /bin/zsh username # Change home directory (and move files) sudo usermod -d /home/newdir -m username # Lock a user account sudo usermod -L username # Unlock a user account sudo usermod -U username # Rename a user sudo usermod -l newname oldname

사용자 삭제

# Delete a user but keep the home directory sudo userdel username # Delete a user and their home directory sudo userdel -r username

사용자 정보 보기

# Check the current user whoami # View user ID and group information id username # List all users cat /etc/passwd # View currently logged-in users who w

그룹 관리

그룹 생성 및 관리

# Create a new group sudo groupadd developers # Add a user to a group (preserving existing groups) sudo usermod -aG developers username # Add a user to multiple groups sudo usermod -aG docker,sudo,developers username # View the groups a user belongs to groups username # View all members of a group getent group developers # Delete a group sudo groupdel developers

기본 그룹과 보조 그룹

각 사용자에게는 기본 그룹과 0개 이상의 보조 그룹이 있습니다.

# Change a user's primary group sudo usermod -g newgroup username # Modify supplementary groups (-a means append; without -a, all supplementary groups are replaced) sudo usermod -aG extragroup username

sudo 구성

Note

Ubuntu 26.04은 Rust 재작성인 sudo-rs를 기존 C sudo의 기본 대체품으로 제공합니다. 이는 대부분의 일반적인 sudoers 구문(사용자/그룹 규칙, NOPASSWD, ALL, /etc/sudoers.d/ 등)과 호환되므로 일상적인 사용법은 변경되지 않습니다. 그러나 일부 모호한 지시문과 타사 플러그인은 아직 구현되지 않았습니다. sudo 종속 스크립트에서 오류가 발생하거나 예기치 않게 작동하는 경우 먼저 sudo --version를 실행하여 현재 구현을 확인하고 필요한 경우 sudo apt install sudo을 사용하여 기존 버전을 임시로 설치하여 문제를 해결한 다음 문제가 해결되면 sudo-rs로 다시 전환하세요.

기본 사용법

# Execute a command with root privileges sudo apt update # Switch to the root user sudo -i # Execute a command as another user sudo -u www-data command

sudo 그룹에 사용자 추가

# In Ubuntu, members of the sudo group have administrator privileges sudo usermod -aG sudo username

sudoers 파일 편집

저장하기 전에 구문 검사를 수행하므로 항상 visudo을 사용하여 sudoers 구성을 편집하십시오.

sudo visudo

일반적인 구성 예:

# Allow a user to execute all commands without a password username ALL=(ALL) NOPASSWD: ALL # Allow a user to execute only specific commands username ALL=(ALL) /usr/bin/systemctl restart nginx, /usr/bin/systemctl status nginx # Allow group members to execute apt without a password %developers ALL=(ALL) NOPASSWD: /usr/bin/apt

/etc/sudoers.d/에서 독립형 구성 파일을 생성할 수도 있습니다.

sudo visudo -f /etc/sudoers.d/developers

파일 권한 기본 사항

권한 표기 이해

Linux 파일 권한은 소유자, 그룹, 기타의 세 가지 세트로 구성됩니다. 각 세트에는 읽기(r=4), 쓰기(w=2) 및 실행(x=1) 권한이 포함됩니다.

# View file permissions ls -la # Example output: # -rwxr-xr-- 1 user group 4096 Jan 1 12:00 script.sh # │├─┤├─┤├─┤ # │ │ │ └── Others: r-- (read only) # │ │ └── Group: r-x (read and execute) # │ └── Owner: rwx (read, write, execute) # └── File type: - regular file, d directory, l symlink

chmod - 권한 변경

# Numeric mode chmod 755 script.sh # rwxr-xr-x chmod 644 config.txt # rw-r--r-- chmod 600 secret.key # rw------- # Symbolic mode chmod u+x script.sh # Add execute permission for the owner chmod g+w file.txt # Add write permission for the group chmod o-r file.txt # Remove read permission for others chmod a+r file.txt # Add read permission for everyone # Recursively change directory permissions chmod -R 755 /var/www/html

chown - 소유권 변경

# Change the file owner sudo chown newuser file.txt # Change both owner and group sudo chown newuser:newgroup file.txt # Change only the group sudo chgrp newgroup file.txt # Recursively change directory ownership sudo chown -R www-data:www-data /var/www

특별 허가

# SUID - Execute as the file owner chmod u+s executable chmod 4755 executable # SGID - Execute as the file group / new files in directory inherit the group chmod g+s directory chmod 2755 directory # Sticky Bit - Only the file owner can delete files (commonly used on /tmp) chmod +t directory chmod 1777 directory

umask - 기본 권한 마스크

# View current umask umask # Set umask (new file default = 0666 - umask, new directory = 0777 - umask) umask 022 # New files 644, new directories 755 umask 077 # New files 600, new directories 700

umask를 영구적으로 변경하려면 ~/.bashrc 또는 /etc/login.defs을 편집하세요.

ACL 확장 권한

표준 권한이 충분히 유연하지 않은 경우 ACL(액세스 제어 목록)을 사용할 수 있습니다.

# Install ACL tools sudo apt install acl # Grant permissions to a specific user setfacl -m u:username:rwx /path/to/file # Grant permissions to a specific group setfacl -m g:groupname:rx /path/to/dir # View ACL settings getfacl /path/to/file # Recursively set ACL setfacl -R -m u:username:rwx /path/to/dir # Set default ACL (newly created files inherit automatically) setfacl -d -m u:username:rwx /path/to/dir # Remove ACL setfacl -x u:username /path/to/file

모범 사례

  1. 최소 권한의 원칙: 사용자에게 작업을 수행하는 데 필요한 최소한의 권한만 부여합니다.
  2. 루트를 직접 사용하지 마세요: 루트로 로그인한 상태를 유지하는 대신 sudo을 사용하여 관리 명령을 실행하세요.
  3. 그룹을 현명하게 사용: 그룹을 통해 권한을 관리하는 것이 각 사용자를 개별적으로 구성하는 것보다 더 효율적입니다.
  4. 정기적으로 감사: /etc/passwd 및 /etc/group을 주기적으로 검토하여 더 이상 필요하지 않은 사용자 및 그룹을 정리합니다.
  5. 민감한 파일 보호: /etc/shadow 및 SSH 키와 같은 파일에 올바른 권한(600 이상)이 있는지 확인하세요.