Score:1

Delete files from root owned folders without sudo

ธง cn

There is an application that creates logs owned by root user (this cannot be changed, at least in my work environment) in the directory logs: enter image description here

This app is executed through a docker-compose and Makefile, and it will be stopped and resumed several times. So I want to execute the app, it will generate logs, stop the app and delete the logs and after a certain amount of time, execute the app again, which will generate new logs.

Deleting the logs (all the subfolders and files that are within the logs folder) has to be done with the command rm -rf logs, without sudo involved, because it is made by a Makefile that is also executed in Mac computers. In Mac, if you have a sudo command, it will ask for a password, and I don't want that.

I have added write permissions to the folder with sudo chmod a+rwx and sudo chmod 777 (have tried both because didn't make it work), which according to a few questions might be enough.

I have also added the ubuntu user to the root group as stated in for example https://unix.stackexchange.com/a/139284, with:

adduser ubuntu root

And

usermod -aG root sysadmin

Following this, https://askubuntu.com/a/213959/999435, I have restarted the server after that.

But still, I am unable to remove the files. How could I do this?

pLumo avatar
in flag
โปรดบอกเราว่าปัญหาเริ่มต้นของคุณคืออะไร ทำไมคุณต้องลบไฟล์นี้โดยไม่ใช้ `sudo` ? โปรดอ่าน https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem
cn flag
ขอบคุณ. ฉันปรับใช้แอพทั้งในเครื่อง MAC และ Ubuntu EC2 ด้วย Makefile ที่มีคำสั่งหยุดการเขียนนักเทียบท่าและลบบันทึก ถ้าฉันเพิ่ม sudo ใน rm ใน mac ของฉัน ฉันต้องป้อนรหัสผ่าน ซึ่งฉันไม่ต้องการให้เกิดขึ้น ดังนั้นความต้องการลบที่ไม่ใช่ sudo
bac0n avatar
cn flag
ในการลบเนื้อหาของบันทึก คุณต้องทำ `rm -rf logs/*` ตั้งค่ากลุ่มเป็นผู้ใช้กลุ่ม `chown root.bac0n logs` จากนั้น `chmod 775 logs` น่าจะดีกว่า 777
cn flag
"สิ่งนี้ไม่สามารถเปลี่ยนแปลงได้" แน่ใจ 100% ว่าสามารถเปลี่ยนแปลงได้: กระแสลมใช้กระแสลมของผู้ใช้ที่เป็นส่วนหนึ่งของกลุ่มรูท `sudo chmod 777` ไม่ใช่คำตอบที่ถูกต้อง @bac0n ฉันจะอ้างว่ามากกว่า 750 เป็นปัญหาด้านความปลอดภัยด้วยซ้ำ "adduser ubuntu root" ขออภัย? ไม่เพียงแค่ไม่มี.
bac0n avatar
cn flag
@Rinzwind: ฉันควรจะชัดเจนกว่านี้ ข้ามสิ่งนี้ด้วย adduser และ usermod คุณต้องเปลี่ยนกลุ่มใน 'logs' เป็นผู้ใช้ที่ควรมีสิทธิ์ในการลบเนื้อหาของ 'logs/*' (ในกรณีนี้ ดูเหมือนว่าจะเป็นอูบุนตู) หากมีผู้ใช้หลายคนที่ต้องการลบเนื้อหา มีความเป็นไปได้ที่จะสร้างกลุ่มร่วมกัน แต่ก็ยังต้องมีอย่างน้อย `770`
muru avatar
us flag
การเพิ่มเครื่องหมายถูกใน Makefile ของคุณให้ใช้ `sudo` เฉพาะบน Linux ไม่ใช่เรื่องยาก
Score:0
ธง by

ใช้ sudo chown -R ผู้ใช้: directory_name

cn flag
ขอบคุณสำหรับคำตอบ. จากนั้น แอปจะไม่พร้อมใช้งานสำหรับสร้างบันทึกใหม่อีกต่อไป ขออภัย ฉันไม่ได้อธิบายสิ่งนั้นในคำอธิบาย ฉันได้อัปเดตคำถามแล้ว

โพสต์คำตอบ

คนส่วนใหญ่ไม่เข้าใจว่าการถามคำถามมากมายจะปลดล็อกการเรียนรู้และปรับปรุงความสัมพันธ์ระหว่างบุคคล ตัวอย่างเช่น ในการศึกษาของ Alison แม้ว่าผู้คนจะจำได้อย่างแม่นยำว่ามีคำถามกี่ข้อที่ถูกถามในการสนทนา แต่พวกเขาไม่เข้าใจความเชื่อมโยงระหว่างคำถามและความชอบ จากการศึกษาทั้ง 4 เรื่องที่ผู้เข้าร่วมมีส่วนร่วมในการสนทนาด้วยตนเองหรืออ่านบันทึกการสนทนาของผู้อื่น ผู้คนมักไม่ตระหนักว่าการถามคำถามจะมีอิทธิพลหรือมีอิทธิพลต่อระดับมิตรภาพระหว่างผู้สนทนา