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

  • SEARCH
  • Home
  • 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 8098855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:12:28+00:00 2026-06-05T22:12:28+00:00

I’m trying to run a python script as other user (not root) which is

  • 0

I’m trying to run a python script as other user (not root) which is also a system user with no shell. I understand that I can’t set suid flag directly on the script so I wrote a C++ wrapper.

wrapper.cpp

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <iostream>

int main(void)
{
    std::cout << geteuid() << std::endl;

    setgid(getgid());
    setuid(getuid());

    execl("/usr/bin/python2.6", "/usr/bin/python2.6", "test.py", NULL);
}

And set following permissions

sudo chown NoShellUser:NoShellGroup /path/to/wrapper
sudo chmod 7755 /path/to/wrapper

Finally, to try it out I have a python script

import sys
import getpass
import os
import pwd
print "VERSION:", sys.version
print "USER:", getpass.getuser(), pwd.getpwuid(os.getuid())
print "EUSER:", pwd.getpwuid(os.geteuid())

With following permissions if that matters at all

sudo chown NoShellUser:NoShellGroup /path/to/test.py
sudo chmod 7755 /path/to/test.py

Now when I run this whole thing as user “test” I see this:

255                                                    # UID of NoShellUser
VERSION: 2.6.8 (unknown, Apr 12 2012, 20:59:36)        # Don't know where that comes from
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]                # Don't know where that comes from
USER: test pwd.struct_passwd(pw_name='test', pw_passwd='hash', pw_uid=20804, pw_gid=604, pw_gecos='Name Surname', pw_dir='/home/test', pw_shell='/bin/bash')
EUSER: pwd.struct_passwd(pw_name='test', pw_passwd='hash', pw_uid=20804, pw_gid=604, pw_gecos='Name Surname', pw_dir='/home/test', pw_shell='/bin/bash')

As you can see the effective user is still “test”. Can somebody please point to me what am I doing wrong, because I looked at few examples already and they all seems to be showing exact same thing more or less?

  • 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-06-05T22:12:30+00:00Added an answer on June 5, 2026 at 10:12 pm

    Your wrapper is slightly wrong – try this instead

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <iostream>
    
    int main(void)
    {
      std::cout << "Real user " << getuid() << std::endl;
      std::cout << "Effective user " << geteuid() << std::endl;
    
      setregid(getegid(), getegid());
      setreuid(geteuid(), geteuid());
    
      std::cout << "Real user " << getuid() << std::endl;
      std::cout << "Effective user " << geteuid() << std::endl;
    
      execl("/usr/bin/python2.6", "/usr/bin/python2.6", "test.py", NULL);
    }
    

    It sets the real and effective user/group ids to the effective group id before execing the python script.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small

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.