linux - IPython 检查运行脚本的用户是否是 root 用户 (Linux)

标签 linux root ipython

让 IPython 脚本检查用户当前是否为根用户的正确方法是什么?

这是我在 bash 脚本中的做法:

if [ $(id -u) != "0" ];then
   echo "This script must be run as root."
   exit 1
fi

有没有比使用“!id”或“!whoami”更好的方法?

最佳答案

在 *nix 操作系统上有 geteuid() in the os module .

关于linux - IPython 检查运行脚本的用户是否是 root 用户 (Linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10842132/

相关文章:

python - FileNotFoundError 尝试在 Pycharm 中使用 Jupyter 读取数据文件

jupyter-notebook - 在 Google Colab 中导入 .py 文件

linux - 当上游发生错误时,如何从标准输入回滚 Vertica 副本?

c - 缺少新的环境变量

python - 在 emacs 中启动 ipython 时没有提示

domain-driven-design - 您使用什么方法来识别域驱动设计中的聚合根?

macos - 具有提升权限的 Mac App Store 应用程序

linux - ZSH 中的 Kill/Yank(剪切/粘贴)

linux - 将系统上所有 git 存储库的远程从 http 更改为 ssh

java - 验证根访问权限 : How to do?