리눅스 / chown, chmod / 파일 또는 디렉토리 소유자, 소유그룹, 권한 설정

chown과 chmod는 파일 및 디렉토리의 권한과 소유자를 관리하는 데 사용되는 Linux 명령어입니다.

정보 확인

  • ls 명령어에 -l 옵션을 붙여서 파일 또는 디렉토리의 권한과 소유자(그룹)을 확인할 수 있습니다.
  • 제일 앞에 있는 문자는 디렉토리인지 파일인지는 나타냅니다. d는 디렉토리라는 뜻이고, -는 파일이라는 뜻입니다.
  • 그 다음 3개의 문자열은 소유자의 권한을, 그 다음 3개의 문자열은 소유그룹의 권한을, 그 다음 3개의 문자열은 소유자(그룹) 이외의 권한을 나타냅니다.
  • 처음 나오는 jb는 소유자, 그 다음 나오는 jb는 소유그룹입니다.
# ls -l
drwxrwxr-x 2 jb jb 4096 Feb 16 22:28 test_directory
-rw-rw-r-- 1 jb jb    4 Feb 16 22:34 test_file

chown

chown은 파일 또는 디렉토리의 소유자와 소유그룹을 정하는 명령어입니다.

  • test_file의 소유자를 jb, 소유그룹을 hs로 정합니다.
# chown jb:hs test_file
  • 소유그룹은 그대로 둔 채 소유자만 jb로 변경합니다.
# chown jb test_file
  • 소유자는 그대로 둔 채 소유그룹만 hs로 변경합니다.
# chown :hs test_file
  • data라는 디렉토리가 있을 때 다음과 같이 명령하면, data 디렉토리와 그 안에 있는 파일 또는 디렉토리의 소유자를 jb, 소유 그룹을 hs로 만듭니다.
chown -R jb:hs data

chmod

chmod은 파일이나 디렉토리의 접근 권한을 변경하는 명령어입니다.

  • r은 읽기(read) 권한, w는 쓰기(write) 권한, x는 실행(excute) 권한입니다.
  • 다음을 해석하면, test_file의 소유자는 jb, 소유그룹은 jb이고, 소유자는 읽고 쓰기 가능, 소유그룹은 읽고 쓰기 가능, 나머지는 읽기 가능입니다.
-rw-rw-r-- 1 jb jb 4 Feb 16 22:34 test_file
  • r은 4, w는 2, x는 1입니다. 따라서 7은 rwx, 6은 rw-, 5는 r-x, 4는 r--을 뜻합니다.
  • 따라서 다음은 소유자, 소유그룹, 다른 사용자 모두에게 읽기, 쓰기, 실행 권한을 주는 것입니다.
chmod 777 test_file
  • 다음은 rwxr-x---로 만드는 것입니다.
chmod 750 test_file
  • u는 소유자, g는 소유그룹, o는 다른 사용자이고, +는 추가, -는 제거를 뜻합니다.
  • 따라서 다음은 소유자에게 실행 권한을 추가하는 것입니다.
chmod u+x test_file
  • 다음은 소유그룹에서 쓰기 권한을 제거하는 것입니다.
chmod g-w test_file
  • a는 전체를 뜻하므로, 다음은 소유자, 소유그룹, 다른 사용자의 읽기 권한을 제거하는 것입니다.
chmod a-r test_file
  • data라는 디렉토리가 있을 때 다음과 같이 명령하면, data 디렉토리와 그 안에 있는 파일 또는 디렉토리의 권한을 777로 만듭니다.
# chmod -R 777 data
같은 카테고리의 다른 글
Ubuntu 22.04 Server / NGINX / 설치와 설정

Ubuntu 22.04 Server / NGINX / 설치와 설정

Nginx는 높은 성능과 안정성을 제공하는 웹 서버 소프트웨어로, 웹 서버 외에도 리버스 프록시, 로드 밸런서, 메일 프록시 등의 기능을 수행할 수 있다. Igor Sysoev가 2004년에 처음 개발했으며, 현재는 오픈 소스 소프트웨어로 널리 사용되고 있다. 가정 Ubuntu 22.04 Server의 IP는 192.168.3.242이고, 내 컴퓨터에서 IP로 접근 가능하다. 내 컴퓨터의 OS는 Windows이다. 설치 nginx 패키지 설치 다음과 같이 명령하여 ...

리눅스 / 명령어 / rdate / 타임서버의 시간과 동기화해주는 명령어

rdate는 서버의 시간과 타임서버의 시간을 동기화해주는 명령어이다. rdate는 설치되어있지 않는 경우가 많으므로, 필요하다면 설치를 해야 한다. CentOS라면 # yum install rdate Ubuntu라면 # apt install rdate 와 같이 명령하여 설치할 수 있습니다. 타임서버의 시간을 확인할 때는 -p 옵션을 사용합니다. 현재 서버의 시간을 변경하지 않는다. # rdate -p time.bora.net 현재 서버의 시간을 타임서버의 시간으로 맞출 때에는 -s 옵션을 ...

Ubuntu 20.04 Server / hostname 확인하는 방법, 변경하는 방법

Ubuntu 20.04 Server / hostname 확인하는 방법, 변경하는 방법

hostname 확인하는 방법 방법 1 - 명령어로 확인하기 다음과 같이 명령하면 hostname을 출력한다. hostname 방법 2 - 설정 파일 열어서 확인하기 /etc/hostname 파일에 hostname이 있다. cat /etc/hostname hostname 변경하는 방법 방법 1 - 명령어로 변경하기 다음과 같이 명령하면 hostname이 abc로 바뀐다. hostnamectl set-hostname abc 방법 2 - 설정 파일 열어서 변경하기 텍스트 에디터로 /etc/hostname 파일을 열어서 내용을 abc로 바꾸면 hostname이 abc로 바뀐다. 재부팅 재부팅을 하면 변경사항이 ...

리눅스 / 스왑 메모리(Swap Memory) 만드는 방법

리눅스 시스템이 메모리를 다 사용하면 프로그램이 멈추는 등 문제가 발생한다. 이때 스왑 메모리(Swap Memory) 늘려서 메모리 부족 문제를 해결할 수 있다. 스왑 파일 만들기 적당한 디렉토리에 적당한 이름의 파일을 적당한 크기로 만든다. 예를 들어 다음과 같이 하면, 루트 디렉토리에 jb-swap이라는 파일을 2G의 크기로 만든다. # fallocate -l 2G /jb-swap root만 읽고 쓸 수 있게 권한 ...

리눅스 / chown, chmod / 파일 또는 디렉토리 소유자, 소유그룹, 권한 설정

chown과 chmod는 파일 및 디렉토리의 권한과 소유자를 관리하는 데 사용되는 Linux 명령어입니다. 정보 확인 ls 명령어에 -l 옵션을 붙여서 파일 또는 디렉토리의 권한과 소유자(그룹)을 확인할 수 있습니다. 제일 앞에 있는 문자는 디렉토리인지 파일인지는 나타냅니다. d는 디렉토리라는 뜻이고, -는 파일이라는 뜻입니다. 그 다음 3개의 문자열은 소유자의 권한을, 그 다음 3개의 문자열은 소유그룹의 권한을, 그 다음 ...

CentOS 7 / rsyslog / 로그 서버 구축하는 방법

CentOS 7 / rsyslog / 로그 서버 구축하는 방법

CentOS을 설치하면 로그 기록을 위한 rsyslog 패키지가 설치되고 실행됩니다. 로그는 로컬 컴퓨터에 저장되는데, 관리하는 컴퓨터가 여러 대인 경우 각각의 로그를 따로 모니터링하는 것이 불편할 수 있습니다. 그런 경우 하나의 컴퓨터를 로그를 수집하는 서버로 만들어서 그 서버에 로그가 쌓이게 하면, 좀 더 수월하게 로그를 관리할 수 있습니다. rsyslog는 간단한 설정 변경으로 로그 ...

Ubuntu 22.04 Server / ZIP 압축 파일 푸는 방법

ZIP 파일을 압축 해제하기 위해서는 unzip 패키지가 필요하다. # apt install unzip xxx.zip 파일을 압축 해제하려면 다음과 같이 명령한다. # unzip xxx.zip 다음과 같이 명령하여 도움말을 볼 수 있다. # unzip -h 결과는 다음과 같다. UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP. Usage: unzip Default ...

리눅스 / 배포판 / 페도라(Fedora) - 역사, 특징, 장점

페도라의 역사 페도라(Fedora)는 2003년 11월 6일에 첫 번째 버전이 출시되었습니다. 페도라는 레드햇(Red Hat)의 커뮤니티 주도 프로젝트로 시작되었으며, 레드햇 엔터프라이즈 리눅스(RHEL)의 기반이 됩니다. 페도라는 최신 기술과 소프트웨어를 빠르게 채택하고 배포하는 것을 목표로 하며, 개발자와 파워 유저들에게 인기가 많습니다. 레드햇과의 관계 페도라는 레드햇의 후원을 받으며, 페도라 프로젝트는 레드햇이 주도하지만, 커뮤니티가 중요한 역할을 합니다. 레드햇은 페도라에서 ...

리눅스 / 명령어 / which, whereis, locate / 명령어 위치 찾기

명령어의 위치를 찾을 때 사용할 수 있는 명령어에는 which, whereis, locate가 있다. 명령어의 위치만 찾을 때는 which를 사용하고, 관련된 파일들의 위치까지 찾을 때는 whereis나 locate를 사용한다. which 명령어로 find 명령어를 찾는다. # which find /usr/bin/find whereis 명령어로 find 명령어를 찾는다. # whereis find find: /usr/bin/find /usr/share/man/man1/find.1.gz locate 명령어로 find 명령어를 찾는다. # locate find /usr/bin/find /usr/bin/find2perl /usr/bin/findmnt /usr/bin/nl-link-ifindex2name /usr/bin/nl-link-name2ifindex /usr/bin/oldfind /usr/lib64/python2.7/modulefinder.py /usr/lib64/python2.7/modulefinder.pyc /usr/lib64/python2.7/modulefinder.pyo /usr/sbin/btrfs-find-root /usr/sbin/findfs /usr/share/bash-completion/completions/findmnt /usr/share/doc/findutils-4.5.11 /usr/share/doc/findutils-4.5.11/AUTHORS /usr/share/doc/findutils-4.5.11/COPYING /usr/share/doc/findutils-4.5.11/ChangeLog /usr/share/doc/findutils-4.5.11/NEWS /usr/share/doc/findutils-4.5.11/README /usr/share/doc/findutils-4.5.11/THANKS /usr/share/doc/findutils-4.5.11/TODO /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_find.py /usr/share/doc/wpa_supplicant-2.6/examples/p2p/p2p_stop_find.py /usr/share/info/find-maint.info.gz /usr/share/info/find.info.gz /usr/share/locale/be/LC_MESSAGES/findutils.mo /usr/share/locale/bg/LC_MESSAGES/findutils.mo /usr/share/locale/ca/LC_MESSAGES/findutils.mo /usr/share/locale/cs/LC_MESSAGES/findutils.mo /usr/share/locale/da/LC_MESSAGES/findutils.mo /usr/share/locale/de/LC_MESSAGES/findutils.mo /usr/share/locale/el/LC_MESSAGES/findutils.mo /usr/share/locale/eo/LC_MESSAGES/findutils.mo /usr/share/locale/es/LC_MESSAGES/findutils.mo /usr/share/locale/et/LC_MESSAGES/findutils.mo /usr/share/locale/fi/LC_MESSAGES/findutils.mo /usr/share/locale/fr/LC_MESSAGES/findutils.mo /usr/share/locale/ga/LC_MESSAGES/findutils.mo /usr/share/locale/gl/LC_MESSAGES/findutils.mo /usr/share/locale/hr/LC_MESSAGES/findutils.mo /usr/share/locale/hu/LC_MESSAGES/findutils.mo /usr/share/locale/id/LC_MESSAGES/findutils.mo /usr/share/locale/it/LC_MESSAGES/findutils.mo /usr/share/locale/ja/LC_MESSAGES/findutils.mo /usr/share/locale/ko/LC_MESSAGES/findutils.mo /usr/share/locale/lg/LC_MESSAGES/findutils.mo /usr/share/locale/lt/LC_MESSAGES/findutils.mo /usr/share/locale/ms/LC_MESSAGES/findutils.mo /usr/share/locale/nl/LC_MESSAGES/findutils.mo /usr/share/locale/pl/LC_MESSAGES/findutils.mo /usr/share/locale/pt/LC_MESSAGES/findutils.mo /usr/share/locale/pt_BR/LC_MESSAGES/findutils.mo /usr/share/locale/ro/LC_MESSAGES/findutils.mo /usr/share/locale/ru/LC_MESSAGES/findutils.mo /usr/share/locale/rw/LC_MESSAGES/findutils.mo /usr/share/locale/sk/LC_MESSAGES/findutils.mo /usr/share/locale/sl/LC_MESSAGES/findutils.mo /usr/share/locale/sr/LC_MESSAGES/findutils.mo /usr/share/locale/sv/LC_MESSAGES/findutils.mo /usr/share/locale/tr/LC_MESSAGES/findutils.mo /usr/share/locale/uk/LC_MESSAGES/findutils.mo /usr/share/locale/vi/LC_MESSAGES/findutils.mo /usr/share/locale/zh_CN/LC_MESSAGES/findutils.mo /usr/share/locale/zh_TW/LC_MESSAGES/findutils.mo /usr/share/man/man1/find.1.gz /usr/share/man/man1/find2perl.1.gz /usr/share/man/man1/oldfind.1.gz /usr/share/man/man8/btrfs-find-root.8.gz /usr/share/man/man8/findfs.8.gz /usr/share/man/man8/findmnt.8.gz locate 명령어는 -n 옵션으로 출력 ...

Ubuntu 22.04 Server / Apache, PHP, MariaDB 설치하는 방법

Ubuntu 22.04 Server / Apache, PHP, MariaDB 설치하는 방법

Ubuntu Server에 웹서버 Apache, 웹프로그래밍 언어 PHP, 데이터베이스 MariaDB를 설치하는 방법입니다. 웹서버 운영을 위한 최소한의 설치로, 실제로 서비스할 때는 더 많은 패키지가 필요할 수 있습니다. 설치 Apache, PHP, MariaDB를 설치합니다. php-mysql은 PHP와 MariaDB 연동을 위한 패키지입니다. # apt install apache2 mariadb-server php php-mysql MariaDB 설정 다음과 같이 명령하여 몇 가지 설정을 합니다. # mysql_secure_installation MariaDB의 root 계정 ...