Difference between EUID and UID?

一曲冷凌霜 提交于 2020-08-03 14:50:33

问题


EUID is not the same as UID. At what context are these both are used in the script?

I tried to get the values by echo "UID is $UID and EUID is $EUID", but only space came as output. My machine runs Ubuntu 12.04 LTS. Seen at some sites that this is usually used to check whether it is root user and all but not able to get proper difference.


回答1:


It only works on bash, not in dash (in Debian based distros as Ubuntu sh is usually a symlink to dash).

If you are running the script interactively you might not have bash configured as your default shell, run bash before trying.

If you are running it from console:

bash script.sh

If you are running it using its path (for example ./script.sh) ensure the first line of the script is:

#!/bin/bash

And not:

#!/bin/sh

For a more generic way to do it check: https://askubuntu.com/questions/15853/how-can-a-script-check-if-its-being-run-as-root

In that post the command id is mentioned, where:

id -u    # is the EUID
id -u -r # is the UID



回答2:


They're different when a program is running set-uid. Effective UID is the user you changed to, UID is the original user.



来源:https://stackoverflow.com/questions/27669950/difference-between-euid-and-uid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!