it just sudo_【IT专家】如果程序是用sudo运行的,如何让用户获得真正的uid?

本文由我司收集整编,推荐下载,如有疑问,请与我司联系

如果程序是用

sudo

运行的,如何让用户获得真正的

uid

如果程序是用

sudo

运行的,如何让用户获得真正的

uid

[

]How

do

I

get

the

users

real

uid

if

the

program

is

run

with

sudo?

The

program

I

am

running

needs

root

privledges and therefore is run with sudo, but it also needs to know what user is running it.

getuid and geteuid both return root. How do I get the actual users username (or uid)?

我运行的程序需要

root

权限,因此使用

sudo

运行,但它还需要知道用户正在运行

它。

getuid

geteuid

都返回

root

。如何获取实际用户的用户名(或

uid

)?

Thanks!

谢谢!

16

sudo provides some environment variables to help you with exactly this case:

sudo

提供了一些环境变量来帮助您完成这种情况:

SUDO_UID Set to the user ID of the user who invoked sudo SUDO_USER Set to the

login of the user who invoked sudo steveayre has pointed out in the comments that the user

can set these environment variables in some cases; the sudo(8) manpage includes in part:

steveayre

在评论中指出用户可以在某些情况下设置这些环境变量

;

sudo

(

8

)联机

帮助页包括:

The

sudoers

policy

subjects

variablespassed

on

the

command

line

to

the

same

restrictions

as

normalenvironment

variables

with

one

important

exception.

If

thesetenv

option is set in sudoers, the command to be run has theSETENV tag set or the command

matched

is

ALL,

the

user

may

setvariables

that

would

otherwise

be

forbidden.

See

sudoers(5)for more information. So be sure that you don’t grant ALL commands to users

when you need to rely upon this feature.

因此,当您需要依赖此功能时,请确保不向用户授予所有命令。

3

A Linux-specific audit_getloginuid() function provided by the auditing system may be

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值