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

Just started experimenting with Perl, and my goal in this little project is to ssh to remote host(s) and process some files, run some commands, and stuff..I am able to ssh user@localhost from the command line but I seem to be doing something wrong in my script:

my $ssh = Net::SSH::Perl->new($host, debug=>1, protocol=>'2', identity +_files=>["/Users/jaldama /.ssh/id_dsa.pub"], ); $ssh->login($user); . . .

and this is what happens!:

jaldama$ perl hostcheck.pl Jackie-Aldamas-MacBook.local: Reading configuration data /Users/jaldam +a/.ssh/config Jackie-Aldamas-MacBook.local: Reading configuration data /etc/ssh_conf +ig Jackie-Aldamas-MacBook.local: Connecting to localhost, port 22. Jackie-Aldamas-MacBook.local: Remote protocol version 2.0, remote soft +ware version OpenSSH_5.2 Math::BigInt: couldn't load specified math lib(s), fallback to Math::B +igInt::FastCalc at /Library/Perl/5.10.0/Crypt/DH.pm line 6 Jackie-Aldamas-MacBook.local: Net::SSH::Perl Version 1.34, protocol ve +rsion 2.0. .ackie-Aldamas-MacBook.local: No compat match: OpenSSH_5.2 Jackie-Aldamas-MacBook.local: Connection established. Jackie-Aldamas-MacBook.local: Sent key-exchange init (KEXINIT), wait r +esponse. Jackie-Aldamas-MacBook.local: Algorithms, c->s: 3des-cbc hmac-sha1 non +e Jackie-Aldamas-MacBook.local: Algorithms, s->c: 3des-cbc hmac-sha1 non +e Jackie-Aldamas-MacBook.local: Entering Diffie-Hellman Group 1 key exch +ange. Jackie-Aldamas-MacBook.local: Sent DH public key, waiting for reply. Jackie-Aldamas-MacBook.local: Received host key, type 'ssh-dss'. Jackie-Aldamas-MacBook.local: Host 'localhost' is known and matches th +e host key. Jackie-Aldamas-MacBook.local: Computing shared secret key. Jackie-Aldamas-MacBook.local: Verifying server signature. Jackie-Aldamas-MacBook.local: Waiting for NEWKEYS message. Jackie-Aldamas-MacBook.local: Send NEWKEYS. Jackie-Aldamas-MacBook.local: Enabling encryption/MAC/compression. Jackie-Aldamas-MacBook.local: Sending request for user-authentication +service. Jackie-Aldamas-MacBook.local: Service accepted: ssh-userauth. Jackie-Aldamas-MacBook.local: Trying empty user-authentication request +. Jackie-Aldamas-MacBook.local: Authentication methods that can continue +: publickey,keyboard-interactive. Jackie-Aldamas-MacBook.local: Next method to try is publickey. Jackie-Aldamas-MacBook.local: Trying pubkey authentication with key fi +le '/Users/jaldama/.ssh/id_dsa.pub' Jackie-Aldamas-MacBook.local: Will not query passphrase for '/Users/ja +ldama/.ssh/id_dsa.pub' in batch mode. Jackie-Aldamas-MacBook.local: Loading private key failed. Permission denied at hostcheck.pl line 18

So I figured maybe I should run in interactive mode so it would prompt for the password...but i'm not being prompted for the password when I set it to 1.

Replies are listed 'Best First'.
Re: SSH using Net::SSH::Perl, Having issues connecting
by atcroft (Abbot) on Jan 13, 2012 at 22:53 UTC

    I suspect strongly that you may be using the wrong portion of your key-try using "/Users/jaldama /.ssh/id_dsa" instead of "/Users/jaldama /.ssh/id_dsa.pub". (The .pub file is normally the portion you copy into the authorized_keys file in the account on the remote server, while the file without is normally the private key, at least as I understand it.)

    Hope that helps.

      Thanks a lot for the reply, I'm gonna try it out and hopefully that solves the problem. If not...I'm sure I'll be back here.. Thanks again!

Re: SSH using Net::SSH::Perl, Having issues connecting
by TJPride (Pilgrim) on Jan 14, 2012 at 02:42 UTC
    This may be a bit of a tangent, but as I understand it, Net::SSH::Perl is a pure-Perl implementation of SSH, and as such can involve quite a long delay on login (I'm guessing because of the math crunching involved? Or is it transfer delay?) What would be the best way to implement something that just layers on top of the standard ssh client, but allows you to specify a password rather than RSA/DSA keys? For instance, I'm using Net::SFTP::Foreign for SFTP, it's hugely faster than Net::SFTP.