`setuid` is a file permission flag under Unix-like systems that will run an executable with the file owner's permissions rather than the invoking user's. On some systems (FreeBSD), it further works identically to the related `setgid` flag on directories, causing new files to inherit the directory's permissions rather than the current user's.
Questions tagged [setuid]
254 questions
55
votes
4 answers
Run child processes as different user from a long running Python process
I've got a long running, daemonized Python process that uses subprocess to spawn new child processes when certain events occur. The long running process is started by a user with super user privileges. I need the child processes it spawns to run as…

Peter Parente
- 1,269
- 2
- 12
- 16
41
votes
4 answers
RealUID, Saved UID, Effective UID. What's going on?
This is a set-root-uid program
$ls -l
-rwsr-sr-x 1 root root 7406 2011-12-13 22:37 ./x*
The source code:
int main(void) {
printf(
" UID GID \n"
"Real %d Real %d \n"
"Effective %d Effective…

Lelouch Lamperouge
- 8,171
- 8
- 49
- 60
31
votes
5 answers
Calling a script from a setuid root C program - script does not run as root
I need to run a bash script as root (passwordless sudo or su not viable) and since you cannot setuid a script in Linux, I thought about calling it from an executable and making it setuid:
$ cat wrapper.c
int main(void)
{
system("/bin/bash…
Jack
19
votes
2 answers
Getting message "sudo: must be setuid root", but sudo IS already owned by root
I'm trying to run sudo, and it's failing:
gregd@david $ sudo ls
sudo: must be setuid root
gregd@david $ which sudo
/usr/bin/sudo
gregd@david $ ll /usr/bin/sudo
-rwxr-xr-x 1 root root 165K 2012-05-16 00:25 /usr/bin/sudo*
Any suggestions on how to…

Greg Dougherty
- 3,281
- 8
- 35
- 58
17
votes
1 answer
Using $ORIGIN with setuid application does not fail as expected
I have a librandom.so library and a main exectuable which was compiled as follows:
$ clang++ -o main main.o -lrandom -L. -Wl,-rpath,"\$ORIGIN"
They are both in the same directory. Since main has $ORIGIN in its rpath, it works fine - ./main returns…

Amir Rachum
- 76,817
- 74
- 166
- 248
17
votes
3 answers
system() vs execve()
Both system() and execve() can be used to execute another command inside a program. Why in set-UID programs, system() is dangerous, while execve() is safe ?

Jake
- 16,329
- 50
- 126
- 202
16
votes
4 answers
Setuid bit on python script : Linux vs Solaris
I am running this small python script on both linux and Solaris as a not privileged user :
#!/usr/bin/python
import os
print 'uid,euid =',os.getuid(),os.geteuid()
Before running, the setuid bit is set on the script (not on python interpreter)…

Eric
- 4,821
- 6
- 33
- 60
15
votes
3 answers
Linux C programming execute as user
I have an program which I run as root. I would like the program to execute another application as a normal user. I tried setgid() and it works, but I can't then go back to root or another user. The program for the time being is very simple;
…

Dominik Brzeziński
- 199
- 1
- 7
15
votes
5 answers
how do i run valgrind to a process which has super user bit on?
I am running valgrind as follows:-
/usr/local/bin/valgrind "process_name"
After excecution its giving me following error
==21731==
==21731== Warning: Can't execute setuid/setgid executable:
==21731== Possible workaround: remove…

anish
- 1,035
- 4
- 13
- 27
13
votes
1 answer
What does connecting to own network daemon mean?
i'm currently doing the bandit wargames from overthewire.org (for those of you who don't know it's a website with different tasks that you get to do in order to improve your hacking skills).
i did them before but i got stuck pretty early and i…

jumpindonuts
- 582
- 1
- 6
- 11
13
votes
3 answers
setuid vs seteuid function
What is the difference between setuid and seteuid function. In man page both of the function have similar description.
setuid:
DESCRIPTION
setuid() sets the effective user ID of the calling process. If the effective UID of the caller is…

mohangraj
- 9,842
- 19
- 59
- 94
12
votes
1 answer
Why do I need setuid(0) within a setuid-root C program that calls an administrative program with system()?
I had to do a dirty Linux hack for somebody so they could start a printer with the cupsenable printername shell command while being a non-root user. I didn't want them to be able to use the entirety of the cupsenable syntax as root, so I just wrote…

JCCyC
- 16,140
- 11
- 48
- 75
11
votes
5 answers
LD_PRELOAD with setuid binary
I am trying to use LD_PRELOAD to preload a library with an application that has setuid permissions. Tried LD_PRELOAD at first, and it seemed like it was being ignored with the setuid binary, though it was working when I tried it with others like ls,…

Mark Lobo
- 331
- 2
- 3
- 9
11
votes
4 answers
How to use setuid() from root to become user, with the possibility of becoming root again later?
I'm trying to do the safe thing, and have a program that needs to runs as root to drop its privileges when it doesn't need them. This works well if I chmod my binary with the SUID bit, and make it belong to root, as now I have UID = some user, and…

Florian
- 1,725
- 3
- 14
- 13
11
votes
2 answers
Git post-receive hook to update a local clone owned by a different user
I'm trying to set up a git post-receive hook such that when a commit is received, another clone of the repository on the machine gets updated (i.e. does a git pull origin master). I'm using gitosis to serve the repository and as such I believe a…

Ibrahim
- 1,883
- 19
- 27