LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Getting permission denied when reading in password for use with Net::SSH::Perl (https://www.linuxquestions.org/questions/programming-9/getting-permission-denied-when-reading-in-password-for-use-with-net-ssh-perl-701113/)

exceed1 01-30-2009 04:25 PM

Getting permission denied when reading in password for use with Net::SSH::Perl
 
Hi

I have created a script that uses the Net::SSH::Perl module to learn how the module works and to learn how to use it.

The script i have created is shown below:
Code:

#!/usr/bin/perl

use warnings ;
use strict ;

# we need this to mange ssh sessions nicely
use Net::SSH::Perl ;

my $command = "pwd" ;
my $user = "exceed" ;
my $password = "" ;

my $sshConnection = Net::SSH::Perl->new("localhost") ;

print "Enter password: " ;
$password = <STDIN> ;
$sshConnection->login($user, $password) ;
my ($stdout, $stderr, $exit) = $sshConnection->cmd($command) ;

print "\n" . $exit . "\n" ;
print "\n" . $stderr . "\n" ;
print "\n" . $stdout . "\n" ;

Its a very simple script, but for some reason it doesnt work.

When the script is run i get a "Permission denied" message, but when i change the script so i dont read in the password, i just put the password in plain text in the $password variable, then it works for some reason.

I have tried the "interactive" and "debug" options to the new contructor for Net::SSH::Perl. When i used the "interactive" mode it just prompted me first for a password, then for a password for a DSA key, then for a RSA key and so on.. it never stopped asking for a password. I have not edited the secure shell server configuration that comes with the openssh-server in debian.

This is the output when running with the debug option:
Code:

exceed@ariel:/etc/init.d$ perl /home/exceed/Scripting/Perl/Scripts/wrappers/SSH/test1.pl
ariel: Reading configuration data /home/exceed/.ssh/config
ariel: Reading configuration data /etc/ssh_config
ariel: Connecting to localhost, port 22.
ariel: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5
ariel: Net::SSH::Perl Version 1.33, protocol version 2.0.
.riel: No compat match: OpenSSH_5.1p1 Debian-5
ariel: Connection established.
Enter password: <pwd>
ariel: Sent key-exchange init (KEXINIT), wait response.
ariel: Algorithms, c->s: 3des-cbc hmac-sha1 none
ariel: Algorithms, s->c: 3des-cbc hmac-sha1 none
ariel: Entering Diffie-Hellman Group 1 key exchange.
ariel: Sent DH public key, waiting for reply.
ariel: Received host key, type 'ssh-dss'.
ariel: Host 'localhost' is known and matches the host key.
ariel: Computing shared secret key.
ariel: Verifying server signature.
ariel: Waiting for NEWKEYS message.
ariel: Enabling incoming encryption/MAC/compression.
ariel: Send NEWKEYS, enable outgoing encryption/MAC/compression.
ariel: Sending request for user-authentication service.
ariel: Service accepted: ssh-userauth.
ariel: Trying empty user-authentication request.
ariel: Authentication methods that can continue: publickey,password.
ariel: Next method to try is publickey.
ariel: Trying pubkey authentication with key file '/home/exceed/.ssh/id_dsa'
ariel: Will not query passphrase for '/home/exceed/.ssh/id_dsa' in batch mode.
ariel: Loading private key failed.
ariel: Next method to try is password.
ariel: Trying password authentication.
ariel: Authentication methods that can continue: publickey,password.
ariel: Next method to try is publickey.
ariel: Trying pubkey authentication with key file '/home/exceed/.ssh/id_dsa'
ariel: Will not query passphrase for '/home/exceed/.ssh/id_dsa' in batch mode.
ariel: Loading private key failed.
ariel: Next method to try is password.
ariel: Trying password authentication.
ariel: Authentication methods that can continue: publickey,password.
ariel: Next method to try is publickey.
ariel: Trying pubkey authentication with key file '/home/exceed/.ssh/id_dsa'
ariel: Will not query passphrase for '/home/exceed/.ssh/id_dsa' in batch mode.
ariel: Loading private key failed.
ariel: Next method to try is password.
ariel: Trying password authentication.
ariel: Authentication methods that can continue: publickey,password.
ariel: Next method to try is publickey.
ariel: Trying pubkey authentication with key file '/home/exceed/.ssh/id_dsa'
ariel: Will not query passphrase for '/home/exceed/.ssh/id_dsa' in batch mode.
ariel: Loading private key failed.
ariel: Next method to try is password.
Permission denied at /home/exceed/Scripting/Perl/Scripts/wrappers/SSH/test1.pl line 17

Im also wondering if someone knows how to not show the keystrokes (whats being typed) when entering the password.

All help is appericiated, hope someone can help me with this. thanks.

Edit: I found this http://www.perlmonks.org/?node_id=590452, but i dont have any authorization and i wont be allowed to edit the source code of the perl module where im planning to run a script im going to create later that uses the Net::SSH::Perl module.

Edit 2: Problem solved. I had to use the "chomp" function with the password as the parameter to remove any newlines.


All times are GMT -5. The time now is 02:24 AM.