จะให้สิทธิ์คำสั่ง sudo ในเวลาที่กำหนดได้อย่างไร มีวิธีใดบ้างที่จะให้สิทธิ์ในการใช้คำสั่งเฉพาะเป็นเวลา 2 วันในไฟล์ sudoers
จะให้สิทธิ์คำสั่ง sudo ในเวลาที่กำหนดได้อย่างไร มีวิธีใดบ้างที่จะให้สิทธิ์ในการใช้คำสั่งเฉพาะเป็นเวลา 2 วันในไฟล์ sudoers
คำตอบ:
ไฟล์ 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
/etc/sudoers.d
โดยที่ผู้ใช้รายอื่นของคุณจะไม่ได้ใช้
mv
cp