Automatic SSH login using Perl

Source: Internet
Author: User
Tags install perl

I. Password Verification:
1. Install the Net: SSH: Perl module. For the installation method, see install the Perl module.
2. In the example of automatic logon, log on to the server 192.168.0.100 using the testuser and run the DF command:

 
#! /Usr/bin/perl-wuse strict; Use Net: SSH: Perl; my $ host = '2017. 168.0.196 '; my $ user = 'root'; my $ Password = 'pass'; my $ SSH = net: SSH: Perl-> New ($ host ); $ ssh-> login ($ user, $ password); my ($ stdout, $ stderr, $ exit) = $ ssh-> cmd ("DF-h "); $ ssh-> cmd ("exit"); if ($ stderr) {print "errorcode: $ exit \ n"; print "errormsg: $ stderr ";} else {print $ stdout;} exit $ exit;

 

Ii. Authentication Based on a public key pair with a password (passphrase:
1. Install the Net: OpenSSH module. For the installation method, refer to the Perl module. In fact, this module is more powerful than the above module. You can also use this module for Password Logon.
2. Code For example, log on to the server 192.168.0.100 using the testuser and run the DF command:
#! /Usr/bin/perl-wuse strict; Use Net: OpenSSH; my $ host = '2017. 168.0.100 '; my $ user = 'testuser'; my $ passphrase = '000000'; my $ key ='/home/testuser /. SSH/id_rsa '; my % Param = (user => $ user, passphrase => $ passphrase, key_path => $ key, timeout => 10); my $ SSH = net:: OpenSSH-> New ($ host, % PARAM); my ($ stdout, $ stderr) = $ ssh-> capture2 ("DF-h"); if ($ stdout) {print $ stdout;} else {print $ ssh-> error; $ stderr and Print $ stderr ;}

 

After the module is installed with CPAN net: SSH: Perl and the prompt is successful, the "can't locate math/Pari. PM in @ INC" error occurs when the script is run.

Run and install Perl-mcpan-e 'Install Math: pari '.

Reference: http://www.cnblogs.com/morya/archive/2011/08/09/2132822.html

 

N days later, net: SSH: Perl was found to be incredibly slow, and the SCP module was used...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.