Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
By "terminal access" I mean "command prompt" of the sort usually accessed by some form of shell terminal, e.g. bash, csh, etc.

Some ways to get a command prompt on a Linux machine:

  • Virtual terminal a.k.a. console, i.e. keyboard and monitor connected to the machine. Linux emulates one or more VT100 derivates, and you can use keyboard shortcuts (typically Alt plus one of the F-keys) to switch between the terminals.
  • Real terminal, e.g. the original VT100, or just about any other computer running a terminal emulator, connected to one of the serial ports of the Linux machine. On an x86-derived PC, typically not enabled by default. Other hardware, especially servers and embedded hardware, may use a serial port for the console.
  • Terminal emulator (xterm and friends) displayed on an X11 or Wayland server ("Graphics mode"). Typically not available on servers.
  • Telnet via any TCP/IP connection. Not encrypted, password transmitted as plain text, insecure and thus typically not enabled by default.
  • Remote shell via any TCP/IP connection. Not encrypted, password often transmitted as plain text, insecure and thus typically not enabled by default.
  • SSH via any TCP/IP connection. Encrypted, secure with recent encryption protocols, can use public keys instead of passwords.
  • Remote code execution exploits in existing server implementations. Rarely legal, not always reliable, and often not encrypted.
I just want to execute privileged commands on the server.

You don't necessarily need a command prompt for that. Most privileged commands on Linux can run fine without a command prompt.

To execute unprivileged commands, just use fork, exec, and wait, or one of the wrappers (qx, system, ``, pipe open, ...). That's not even specific for Perl, almost all languages running on Linux can start other processes.

And to run privileged commands, just use sudo. Yes, sudo needs to be configured, and the documentaton for its config file was probably the inspiration for the right-hand side of https://xkcd.com/1343/, but it allows a very precise control about who is given privileged access, to which programs, and even the parameters passed to the programs can be restricted. Running sudo is trivial. Just execute sudo instead of the privileged command, and pass the privileged command and all of its parameters as parameters to sudo.

When running CGIs or SSI from Apache, you can alternatively use suEXEC. suEXEC is sufficiently paranoid, but not as flexible as sudo. And it explicitly prevents running code as root.

<Update>Just for inspiration: Webmin routinely runs privileged commands from a webserver. Unfortunately, it does so by simply NOT dropping privileges when starting the webserver, so everything runs as root. See Building a web-based system administration interface in Perl and especially Re: Building a web-based system administration interface in Perl for a better way; and Best way to write to a file owned by root? for some paranoid file handling when running with elevated privileges.</Update>

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^3: Perl terminal access to linux server by afoken
in thread Perl terminal access to linux server by Polyglot

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 wandering the Monastery: (3)
As of 2024-04-24 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found