sudo
권한·소유
쓰는 꼴
sudo [cmd]명령 하나를 다른 사용자, 보통 root로 실행합니다. sudo cmd > file의 > 는 내 셸에서 열리므로 root 소유 파일에는 실패하고, 그때는 tee를 씁니다.
자주 쓰는 옵션
| 옵션 | 뜻 |
|---|---|
| -u | Run as another user instead of root |
| -i | Start a login shell with that user environment |
| -s | Start a shell but keep your own environment |
| -E | Keep your environment variables, if the policy allows it |
| -k | Forget the cached password right now |
| -l | List what you are allowed to run |
| -v | Refresh the timestamp without running anything |
예시
sudo -u postgres psqlRuns the client as the postgres user.
sudo -iA root login shell, with root PATH and environment.
echo text | sudo tee -a /etc/hostsRedirection needs tee, because > runs as you.
숫자 모드와 문자 모드가 같은 것을 가리킵니다. 755와 u=rwx,go=rx는 같은 뜻입니다.
읽는 방법
- 대괄호 [ ]는 넣어도 되고 안 넣어도 되는 자리입니다.
- 점 셋 …은 여러 개를 이어 쓸 수 있다는 뜻입니다.
- 옵션은 대소문자를 가립니다 — -r과 -R이 다른 명령도 있습니다.
자주 묻는 것
Q. sudo은 무엇을 하나요?
명령 하나를 다른 사용자, 보통 root로 실행합니다. sudo cmd > file의 > 는 내 셸에서 열리므로 root 소유 파일에는 실패하고, 그때는 tee를 씁니다.
Q. 어떻게 치나요?
sudo [cmd] — 대괄호는 생략할 수 있는 자리입니다.
Q. 옵션은 몇 개나 자주 쓰나요?
여기 정리한 것은 7개입니다. 전체 목록은 man sudo에 있습니다. 이 명령은 권한·소유 갈래입니다.
같이 보는 명령
man 페이지: man sudo