There's more than one way to do things | |
PerlMonks |
Re^3: Perl terminal access to linux serverby afoken (Chancellor) |
on Sep 22, 2021 at 19:59 UTC ( [id://11136957]=note: 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:
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 Section
Seekers of Perl Wisdom
|
|