Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7580797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:00:26+00:00 2026-05-30T18:00:26+00:00

I am trying to make a python script executable with the setuid bit set.

  • 0

I am trying to make a python script executable with the setuid bit set. The program, belonging to user ‘bgmc’, must create some files in the directory ‘/home/bgmc’, but is called by another user, ‘client’. Indeed, I don’t want user ‘client’ to change the files created by the program. I used a c-wrapper to call the program (see setuid on shell scripts):

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
    setuid(0);
    system("/home/bgmc/myprogram.sh");
    return 0;
}

I set the setuid bit of the program on. When the c-compiled program belongs to root, the program runs well and creates the expected file. The properties of the c-compiled program are then:

8 -rws--x--x 1 root root 4657 Mar  2 16:25 myprogram

However, when I change the user-group of myprogram to bgmc:bgmc, the program cannot create the file anymore: “Permission denied”. I tried to change the line:

setuid(0);

with:

setuid(1002);

since 1002 is the user id of ‘bgmc’ (I used command “id -u bgmc” for this) but this didn’t help.

I would rather prefer not giving root access to the program. Is there a way to prevent this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:00:28+00:00Added an answer on May 30, 2026 at 6:00 pm

    Not sure about this since your question is very sparse on information, but did you forget to reset the permissions on the file after changing the owner? On most systems, any change of ownership automatically removes the setuid bit and you have to re-add it yourself if you want it.

    Also note that setuid shell scripts are a major vulnerability; this is why the kernel does not allow you to make a shell script setuid directly. At the very least you should:

    1. Use execve rather than system to call it, and
    2. Clear out everything from the environment (or pass a new empty environment to execve).

    As it is now, anyone who can run the program can make it do whatever they like by controlling environment variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a python program (using pyUNO ) to make some changes
I am trying to make my python script very user friendly, so I like
I'm trying to make a Python script run another program from its own path.
While trying to make one of my python applications a bit more robust in
I'm trying to make my python script run upon startup but I get the
I am trying to create a python script that opens a single page at
I'm trying to create a database connection in a python script to my DB2
I'm trying to make my Python script stream its output to my webpage as
I'm trying to create a python script that will allow me to load up
I'm trying to execute a python script (through a python process) under another user.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.