If you are using ssh then you are half way there!

You need to generate yourself an identity using ssh-keygen on the local machine. You then copy the public part of this into the ~/.ssh/authorized_keys file on the remote server.

You'll then be able to log into the remote machine without using a password (provided you didn't set a password on the identity you made).

This requires that you keep your identity secret, but you are proposing putting the username and password in a file which is just as bad.

This is the way I use ssh for all our system administration. We have a web page showing disk usage on all or our servers generated in exactly this way.

Once you've got it working you can do this

# ssh myremoteserver.net 'df -k' Filesystem 1024-blocks Used Available Capacity Mounted on /dev/sda3 17092820 2255644 13954808 14% / /dev/sdb4 30639063 11498971 17533191 40% /home
Note the lack of login propmt!

You need to take care passing commands to ssh - if you don't use the list form of system you'll end up running your commands through two shells (one remote, one local) which may be bad for your server health. Use like this

system("ssh", "-l", "root", "df -k") == 0 or die "Couldn't run command";
Take care with commands run on the remote server since they will be run through the shell. Judicous use of ''s or \Q\E can help, or use Shell::StringQuote.

In reply to Re: Auto login and password entry by ncw
in thread Auto login and password entry by BlackLab

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.