사용자가 2일 동안만 명령을 실행하도록 허용하는 방법이 있습니까?

사용자가 2일 동안만 명령을 실행하도록 허용하는 방법이 있습니까?

특정 시간에 sudo 명령 권한을 부여하는 방법은 무엇입니까? sudoers 파일에서만 2일 동안 특정 명령을 수행할 수 있는 권한을 부여하는 방법이 있나요?

답변1

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일 후 오후 2시에 파일을 이동합니다. 그만큼at 수동몇 가지 옵션이 있습니다(시간, 일, 주, 월, 연도, 다음과 같은 키워드 또는 마침표 추가/빼기 등을 사용할 수 있음). 옵션을 통해 몇 가지 테스트를 통해 이해했는지 확인하세요. (고려할 사항: at당일 오후 2시 이전에 시작하는지, 아니면 이후에 시작하는지가 중요합니다.)

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명령에 "."를 배치했습니다. 앞에도 보이지 않게 만듭니다. 올바르게 가정한 경우 "."를 배치할 수 있습니다. 어딘가에. "~"는 gEdit과 같은 편집자가 "백업" 기능으로 사용하므로 주의하세요.


at기본적으로 설치되지 않습니다. 설치하기 위해서

sudo apt-get install at

관련 정보