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...