Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

The documentation for Net::Rsh states that if a script uses this module, it must either be run by root or must be suid root. Does anyone know of a way around this limitation? I like to avoid running my scripts as root if at all possible and I really don't like to set them as SUID unless absolutely necessary.
  • Comment on Get around root requirement for Net::Rsh

Replies are listed 'Best First'.
Re: Get around root requirement for Net::Rsh
by jj808 (Hermit) on Sep 23, 2002 at 16:05 UTC
    The RSH protocol states that the local port (i.e. on the machine initiating the connection) must be in the range 512-1023. However, UNIX will only let the root user open a port below 1024.

    So unless you can recompile the rsh server to remove this restriction and accept connections from ports >1023, it will be necessary to run your script as root.

    Sorry this isn't very positive, but that's just how the protocol works. If you're happy to send passwords in plain text across the network (rsh is quite insecure anyway), you could always try Net::Telnet as an alternative, or Net::SSH / Net::SSH::Perl if you're more security conscious.

    JJ

Re: Get around root requirement for Net::Rsh
by blm (Hermit) on Sep 23, 2002 at 16:21 UTC

    The reason the root privileges are needed is the Net::Rsh module seems to connect from a port < 1024 to server port 514(rsh). I beleive to listen on ports < 1024 or connect from ports <1024 to a server port you neet to be a superuser (like root) (but not on Windows XP)

    You could get around this by modifying Rsh.pm to start trying to connect from ports higher then 1024 by altering the value of $end_port to something like 2048

    NB THIS INFORMATION BEARS NO WARRANTY. USE ONLY AT YOUR RISK. The author must have done this for a reason. I don't know why so please be careful. Please note rsh is considered a huge security risk .

    Update:The server (at least on debian) does not seem to require connection from port < 1024 as indicated above. Some web sites (like here) say the server will terminate connection if source port is < 1024.

    I got to get faster at typing and submitting ;-)

    --blm--
      I have just tried modifying Rsh.pm as you suggest, but on my system (RedHat 7.3) the connection is refused with the following message in the system log:
      Sep 23 17:47:27 mondas rshd[23026]: Connection from 127.0.0.1 on illeg +al port
      Good point and worth a try though, if only to determine if your system has a broken rsh implementation (mmmm, security!) ;-)

      JJ