![sudo만 읽을 수 있는 파일을 만드는 방법은 무엇입니까?](https://linux55.com/image/136773/sudo%EB%A7%8C%20%EC%9D%BD%EC%9D%84%20%EC%88%98%20%EC%9E%88%EB%8A%94%20%ED%8C%8C%EC%9D%BC%EC%9D%84%20%EB%A7%8C%EB%93%9C%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
특정 토큰을 쉘 환경으로 내보내는 대신 내 컴퓨터에 파일을 저장하고 싶습니다. 따라서 sudo로만 토큰을 읽을 수 있기를 원하므로 액세스하려면 승인이 필요합니다. sudo로만 읽을 수 있는 파일을 작성하는 방법은 무엇입니까?
답변1
이는 sudo
루트/수퍼유저와 동의어가 아닙니다. 실제로 sudo
command를 사용하면 보안 정책에 지정된 대로 거의 모든 사용자가 명령을 실행할 수 있습니다.
$ sudo whoami
root
$ sudo -u bob whoami
bob
root
사용자만 읽을 수 있는 파일을 생성하려고 한다고 가정합니다 .
# Create the file
touch file
# Change permissions of the file
# '600' means only owner has read and write permissions
chmod 600 file
# Change owner of the file
sudo chown root:root file
파일 내용을 편집해야 하는 경우:
# Replace 'nano' with your prefered editor
sudo nano file
루트만 파일을 읽을 수 있는 방법을 확인하세요.
$ cat file
cat: file: Permission denied
$ sudo cat file
foo bar baz
답변2
그것을 알아 냈습니다 :
echo 'hello world' > test
sudo chown root test
sudo chmod 600 test
sudo cat test
다른 터미널에서 sudo를 사용하지 않는 경우 다음을 수행하십시오.
> cat test
cat: test: Permission denied
답변3
티셔츠를 가져오세요
$ echo "some text" | sudo tee tmpfile
some text
$ sudo chmod 700 tmpfile
$ cat tmpfile
cat: tmpfile: Permission non accordée
$ sudo cat tmpfile
some text
추가 사항:
$ echo "text appened" | sudo tee -a tmpfile
$ sudo cat tmpfile
somme text
text appened
$ sudo rm tmpfile