I would not do this within Perl. I would use the OS to accomplish this task. You mentioned terminals, so that might imply a Unix flavor or variant. I would use a special user id and sudo to accomplish this task in Unix.

NOTE: I intend to meet your requirements of being able to run a command, but not being able to view the command. I do not intend to encrypt anything. Encryption in this case seems to be an XY problem.

Here is the example command. The file is owned by our special user sexec. The group owner is root. The other permissions are all turned off.

root@mybox:/tmp/fakebin # ls -ld . drwxr-xr-x 2 root root 1024 Jan 28 09:44 . root@mybox:/tmp/fakebin # ls -l total 1 -rwxr-x--- 1 sexec root 90 Jan 28 09:44 cmd.pl root@mybox:/tmp/fakebin # cat cmd.pl #!/usr/bin/perl -w use strict; use warnings; print "Secret command output.\n"; exit 0;

Here is the /etc/sudoers line that lets user bob run cmd.pl as user sexec.

bob ALL = (sexec) NOPASSWD: /tmp/fakebin/cmd.pl

Here is the end result actions. User bob can run the command, but he can't view it.

bob@mybox:~ $ sudo -u sexec /tmp/fakebin/cmd.pl Secret command output. bob@mybox:~ $ cat /tmp/fakebin/cmd.pl cat: /tmp/fakebin/cmd.pl: Permission denied bob@mybox:~ $ sudo -u sexec /bin/cat /tmp/fakebin/cmd.pl Password: Sorry, user bob is not allowed to execute '/bin/cat /tmp/fakebin/cmd.p +l' as sexec on mybox.localdomain.tld.

In reply to Re: Encrypt perl script by jffry
in thread Encrypt perl script by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.