`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
3
votes
2 answers
setuid bit result
I have a shell script that I want to set uid bit.
I set the owner to root and set uid bit.
I added 'whoami'in the shell to check if it is working properly
but when I executed the script, whoami returned user's name, not root.
Then this is wrong,…

manatails008
- 229
- 4
- 8
3
votes
3 answers
Perl script to run as root (generalized)
I would like to be able to run certain Perl scripts on my system as root, even though the "user" calling them is not running as root.
For each script I can write a C wrapper, setting setuid root for that wrapper; the wrapper would change the UID to…

Bill Evans at Mariposa
- 3,590
- 1
- 18
- 22
3
votes
2 answers
Is seteuid a system call on Linux?
All of the literature that I have read so far on setuid talks about seteuid in a way that implies it is a system call. The section 2 man pages never say if a function is a system call or not, so seteuid(2) is no help. And if it isn't a system call,…

Melab
- 2,594
- 7
- 30
- 51
3
votes
2 answers
Using the setuid bit in Linux
I have this C file:
#include
#include
int main(void)
{
printf("%s\n", getlogin());
printf("%i\n", getuid());
}
I compile it, set the UID and GID both to root and set the setuid bit, so that it looks like…

hgiesel
- 5,430
- 2
- 29
- 56
3
votes
2 answers
setuid() failing - operation not permitted
changeIDs() is trying to use setuid() to change the effective user id
but it always errors out and I'm not sure why.
I have two users on computer. user is an admin with UID of 1000. The other standard user, user 2, has a UID of 1001.
I want to…

Angel
- 311
- 1
- 4
- 16
3
votes
3 answers
setuid(0) fails to execute for root owned program
I need to write some code which can gain root priveleges and execute system level operations. Here's what I've written (this is not the actual code, just to test if I'm doing things correctly or not):
#include
#include…

Tarun Verma
- 329
- 5
- 17
3
votes
2 answers
What's the difference between system() and execve()
I use linux and c.
First, I soft link bin/zsh to sh
Second, I login as root the run the following program.
#include
#include
#include
int main(int argc, char *argv[])
{
char *v[3];
if(argc < 2) {
printf("Please…

littletiger
- 651
- 1
- 8
- 14
3
votes
4 answers
how do i claim a low-numbered port as non-root the "right way"
I have a script that I want to run as a daemon listening on a low-numbered port (< 1024)
Script is in python, though answers in perl are also acceptable.
The script is being daemonized using start-stop-daemon in a startup script, which may…

qbxk
- 83
- 7
3
votes
1 answer
Effective UID not taking effect on kill command
I'm trying to understand user ID / effective user ID. When I switch to a user (in this example apache) I still can send SIGKILL signals to programs running under root UID.
Example of output:
[root@devserv ~]# ./testsuid
Real UID = 0
Effective…

Marco
- 368
- 1
- 4
- 16
3
votes
1 answer
Check if a file is setuid root in Python
I'm trying to check if a file has the setuid bit in Python.
The stat doc mentions a S_ISUID function but it only works with os.chmod(), not to actually read the setuid bit. It also lists S_IMODE, but I have no idea how to interpret it.
How can I…

raphink
- 3,625
- 1
- 28
- 39
3
votes
2 answers
Secure access to files in a directory identified by an environment variable?
Can anyone point to some code that deals with the security of files access via a path specified (in part) by an environment variable, specifically for Unix and its variants, but Windows solutions are also of interest?
This is a big long question -…

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278
3
votes
3 answers
setuid fails with PermissionDenied on Galaxy s4
I'm trying to create a setuid program on c for android. I tested it on android 2.3-4.2 and it works well on all devices except Samsung Galaxy s4 (i9500).
I used CF-Auto-Root to install su on device and it works fine. But my app is not doing well.
I…

Tishka17
- 305
- 2
- 12
3
votes
2 answers
How to get superuser privileges in Ruby?
So, I've been working on a Ruby script that blocks reddit during my school hours (useful stuff). Here's the code:
require 'fileutils'
puts "-----------------------------------"
puts "Welcome to the hosts file modifier!"
puts…

bluebunny
- 295
- 3
- 13
3
votes
1 answer
In Linux, does the location of an executable affect how the setuid bit is interpreted?
In a Linux system, does the permissions of the directory in which a setuid program resides affect how the kernel launches the process? The reason I ask is that when I compiled an identical setuid program in two different directories, it only…

Mr. Shickadance
- 5,283
- 9
- 45
- 61
3
votes
2 answers
setuid sets a large number
I have run a program using root in which I called setuid function for uid 9999999 then it successfully sets this uid even it doesn't exist in /etc/passwd.
SO how setuid validates uid and what will be the impact of setting this invalid uid ?

sonu tiwari
- 31
- 1