Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Welcome to unix. A bit of convolution, but still far simpler than the Windows security model, IMO. (Though still not perfect, but I digress.)

First off, just because you can't log in as root doesn't mean you can't log in as root. ;-) It just means you can't log in via gdm (the GUI) as root - a good thing by any security-minded definition. You should be able to gain root access in any number of other ways, some requiring a password, others have the password as optional.

What I've done in the past is set up sudo to allow running of a particular command without a password. In my case, I want to run it as a particular user, so I have:

%build ALL=(nobody) NOPASSWD: /full/path/to/script
With this, anyone can run "sudo -u nobody /full/path/to/script" and not be asked for a password. Well, that's great, but a bit cumbersome. So my script does this:
# Are we the right user? use User::pwent; my $user_wanted = 'nobody'; my $user = getpwnam($user_wanted); if ($< != $user->uid()) { exec(qw(sudo -u), $user_wanted, $0, @ARGV); } [...]
Now I can just run /full/path/to/script, and it will exec itself as the right user if it isn't already.

Hope that helps.


In reply to Re: Executing unix command from script by Tanktalus
in thread Executing unix command from script by Neminath

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 22:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found