มีวิธีใดบ้างที่จะอนุญาตให้ผู้ใช้เรียกใช้งานคำสั่งเป็นเวลา 2 วันเท่านั้น


13

จะให้สิทธิ์คำสั่ง sudo ในเวลาที่กำหนดได้อย่างไร มีวิธีใดบ้างที่จะให้สิทธิ์ในการใช้คำสั่งเฉพาะเป็นเวลา 2 วันในไฟล์ sudoers

คำตอบ:


18

ไฟล์ sudoers ไม่สนับสนุนการ จำกัด เวลาตาม แต่มีวิธีง่าย ๆ สร้างไฟล์ที่มีการเปลี่ยนแปลงของคุณใน/etc/sudoers.d/(กับsudo visudo -f /etc/sudoers.d/yourfile):

เพิ่มไปยังไฟล์ (ตัวอย่าง:) file.shต่อไปนี้

mv /etc/sudoers.d/yourfile /etc/sudoers.d/.yourfile

และสิ่งนี้จะปิดการใช้งานการเปลี่ยนแปลงของคุณ:

 sudo at -f file.sh 2pm + 2 days

ตัวอย่าง:

at -f file.sh 2pm + 2 days
warning: commands will be executed using /bin/sh
job 4 at Thu Oct 15 14:00:00 2015

ในกรณีนี้มันจะย้ายไฟล์ไปตอนบ่ายสองโมง 2 วันหลังจากที่คุณออกคำสั่ง at คู่มือมีบางตัวเลือก (คุณสามารถใช้เวลาวันสัปดาห์เดือนปีคำหลักเช่นเพิ่มถัดไปหรือ / periodes ลบ) มีการทดสอบบางอย่างพร้อมตัวเลือกเพื่อให้แน่ใจว่าคุณเข้าใจ (สิ่งที่ต้องพิจารณา: มันสำคัญถ้าคุณเริ่มatก่อนหรือหลัง 14.00 น. ของวันนั้น ๆ )

atยังมีชีวิตอยู่ในการรีบูตเครื่องดังนั้นจึงเป็นเครื่องมือที่ดีที่จะใช้กับสิ่งเหล่านี้ และคุณสามารถสลับการเข้าถึง ...

sudo mv /etc/sudoers.d/.yourfile /etc/sudoers.d/yourfile | at 2pm + 2 days
sudo mv /etc/sudoers.d/yourfile /etc/sudoers.d/.yourfile | at 2pm + 4 days
sudo mv /etc/sudoers.d/.yourfile /etc/sudoers.d/yourfile | at 2pm + 6 days
sudo mv /etc/sudoers.d/yourfile /etc/sudoers.d/.yourfile | at 2pm + 8 days

และทำให้ผู้ใช้รายนั้นบ้าคลั่ง (ตอนนี้ฉันสามารถทำได้)

README ใน/etc/sudoers/:

# As of Debian version 1.7.2p1-1, the default /etc/sudoers file created on
# installation of the package now includes the directive:
# 
#   #includedir /etc/sudoers.d
# 
# This will cause sudo to read and parse any files in the /etc/sudoers.d 
# directory that do not end in '~' or contain a '.' character.
# 
# Note that there must be at least one file in the sudoers.d directory (this
# one will do), and all files in this directory should be mode 0440.
# 
# Note also, that because sudoers contents can vary widely, no attempt is 
# made to add this directive to existing sudoers files on upgrade.  Feel free
# to add the above directive to the end of your /etc/sudoers file to enable 
# this functionality for existing installations if you wish!
#
# Finally, please note that using the visudo command is the recommended way
# to update sudoers content, since it protects against many failure modes.
# See the man page for visudo for more information.

ถ้าฉันอ่านอย่างถูกต้องมันจะไม่รันไฟล์ใด ๆ ที่มี "." ทุกที่ในชื่อ ดังนั้นmvคำสั่งที่1 ฉันวาง "." ด้านหน้าทำให้มองไม่เห็น หากถือว่าถูกต้องคุณสามารถวาง "." ทุกแห่ง ใช้ความระมัดระวังในการ "~" ที่ใช้เป็นคุณลักษณะ "สำรองข้อมูล" โดยผู้แก้ไขเช่น gEdit


atไม่ได้ติดตั้งเป็นค่าเริ่มต้น ติดตั้ง

sudo apt-get install at

ขอบคุณมากฉันคิดอยู่แล้ว แต่สถานการณ์เป็นผู้ใช้หลายคนที่ใช้ไฟล์เพื่อจุดประสงค์ของตัวเองดังนั้นจึงไม่สามารถทำการสำรองและกู้คืนไฟล์ sudoers ทุกครั้งที่ bcoz ผู้ใช้รายอื่น ๆ กำลังแก้ไขไฟล์ sudoers เดียวกันดังนั้นเมื่อฉันกู้คืนไฟล์เก่าทั้งหมด การเปลี่ยนแปลงที่ทำโดยผู้ใช้ ohter จะหายไป ...
Abbas Kapasi

2
แล้วท่านล่ะ โอ้และฉันขอแนะนำให้ผู้ใช้หลายคนของคุณให้ใช้ sudoers.d ด้วยชื่อไฟล์ของตัวเองด้วย ดูเหมือนว่าจะดีกว่าการแก้ไข sudoers
Rinzwind

@AbbasKapasi สร้างไฟล์ใหม่/etc/sudoers.dโดยที่ผู้ใช้รายอื่นของคุณจะไม่ได้ใช้
muru

ผมคิดว่าคำสั่งที่ใช้ทั้งหมดตลอดทั้งคำตอบที่ควรจะได้รับไม่ได้mv cp
คธูลู

3
คุณเห็นซีพีที่ไหน ผิวปากอย่างบริสุทธิ์ใจ
Rinzwind
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.