Gre*_*era 18 permissions command-line scripts steam games
我儿子去年圣诞节收到了一台新笔记本电脑,主要用于他的新学校......现在他有了自己的笔记本电脑,他很想安装 Steam。
但是妻子要我删除 Steam,因为笔记本电脑主要是供学校使用的……如果我不需要,我宁愿不这样做。
有没有办法限制或以其他方式限制对 Steam 的访问?也许是 Steam 本身的密码,或者设置它可以运行的时间?
理想情况下,它必须是使用起来非常简单的东西,因为我的工作经常让我远离家(和电脑、电信和......)很长一段时间,而我的妻子在电脑周围不像我那么舒服,更容易使用要好得多。
肯定有什么东西可以完成这项任务吗?
通过一个小的后台脚本,您可以为进程或应用程序设置时间限制。
只要您的用户不知道管理员的密码,就不太容易被超越。
就是这么小的后台脚本。它将每天的使用限制在定义的分钟数内,并在脚本的头部设置。一旦设置完毕(这并不太困难),它运行起来非常容易,之后不需要任何额外的操作。
#!/usr/bin/python3
import subprocess
import os
import sys
import time
#--- set the time limit below (minutes)
minutes = 1
#--- set the process name to limit below
app = "gedit"
uselog = "/opt/limit/uselog"
datefile = "/opt/limit/currdate"
def read(f):
try:
return int(open(f).read().strip())
except FileNotFoundError:
pass
currday1 = read(datefile)
while True:
time.sleep(10)
currday2 = int(time.strftime("%d"))
# check if the day has changed, to reset the used quantum
if currday1 != currday2:
open(datefile, "wt").write(str(currday2))
try:
os.remove(uselog)
except FileNotFoundError:
pass
try:
# if the pid of the targeted process exists, add a "tick" to the used quantum
pid = subprocess.check_output(["pgrep", app]).decode("utf-8").strip()
n = read(uselog)
n = n + 1 if n != None else 0
# when time exceeds the permitted amount, kill the process
if n > minutes*6:
subprocess.Popen(["kill", pid])
open(uselog, "wt").write(str(n))
except subprocess.CalledProcessError:
pass
currday1 = currday2
Run Code Online (Sandbox Code Playgroud)
limitlimit_use(无扩展名)文件夹内并使其可执行在脚本的头部编辑要限制的进程名称以及允许的最大分钟数。在示例中:
#--- set the time limit below (minutes)
minutes = 1
#--- set the process name to limit below
app = "gedit"
Run Code Online (Sandbox Code Playgroud)将文件夹复制到目录/opt:
cp -r /path/to/limit /opt
Run Code Online (Sandbox Code Playgroud)现在编辑/etc/rc.local以使脚本在启动时运行root:
sudo -i gedit /etc/rc.local
Run Code Online (Sandbox Code Playgroud)
就在排队之前
exit 0
Run Code Online (Sandbox Code Playgroud)
另一行:
/opt/limit/limit_use &
Run Code Online (Sandbox Code Playgroud)就是这样
当有人试图杀死后台脚本时:
(不允许的动作)
/opt/limit/uselog)。如果达到每日限制,脚本将不再允许该进程运行,如果存在则将其终止。rc.local只有具有 sudo 权限的用户才能停止脚本,即使只有在用户知道进程名称的情况下也是如此。如果您想停止脚本,请使用以下命令:
sudo kill "$(pgrep limit_use)"
Run Code Online (Sandbox Code Playgroud)
但同样,您需要 sudo 密码才能执行此操作。
尽管上面的脚本应该提供一种相当安全的方式来限制应用程序的使用,正如 @Bytecommander 所提到的,但它可以被超越,尽管不是很容易。结合下面的措施将使这种情况发生的可能性很小,除非你的儿子知道设置,并且对 Linux/Ubuntu 有丰富的经验。
下面的附加措施距离“简单解决方案”稍远一些,但设置起来仍然不太困难。如果我们怀疑的犯罪分子发现脚本是从 调用的/etc/rc.local,会设法成为 root,并删除 中的行/etc/rc.local,或者能够以这种方式停止脚本,我们可以让他面对下一个问题:屏幕在之后黑屏此外,该解决方案会在重启后 5 分钟后检查后台脚本是否正在运行,如果没有运行则停止运行。
额外的措施是启动 - 检查该行是否/opt/limit/limit_use &存在于 中/etc/rc.local,并在 5 分钟后检查脚本是否仍在运行。由于脚本从(隐藏在启动应用程序中)启动器运行,/etc/xdg/autostart因此很难找出正在发生的情况,除非您知道它是如何完成的。这两项措施的结合使您的儿子不太可能发现,即使他发现了,也可能没有什么可以阻止他。
涉及两个简单的步骤:
将以下代码复制到一个空文件中,将其保存blackout.desktop在桌面上:
[Desktop Entry]
Name=not allowed
Exec=/bin/bash -c "sleep 15 && /usr/local/bin/blackout.py"
Type=Application
Terminal=false
NoDisplay=true
Run Code Online (Sandbox Code Playgroud)
将文件复制到/etc/xdg/autostart:
sudo cp /path/to/blackout.desktop /etc/xdg/autostart
Run Code Online (Sandbox Code Playgroud)将下面的脚本复制到一个空文件中,将其保存blackout.py在桌面上,使其可执行并将其复制到/usr/local/bin:
cp /path/to/blackout.py /usr/local/bin
Run Code Online (Sandbox Code Playgroud)
剧本
#--- set the time limit below (minutes)
minutes = 1
#--- set the process name to limit below
app = "gedit"
Run Code Online (Sandbox Code Playgroud)中的启动器/etc/xdg/autostart将为所有用户启动一个应用程序(在本例中为额外的安全检查)。这可以在本地覆盖,但您必须知道检查运行。通过将该行NoDisplay=true放入我们的启动器中,它不会出现在本地Startup Applications,因此在不知道它存在的情况下,它不太可能被发现。
此外,你的儿子只有 15 秒的时间来找出答案(然后屏幕就黑了),所以他会遇到一个严重的问题,除非他是一个天才,有丰富的 Ubuntu 经验和创造性思维。