LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-30-2009, 04:25 PM   #1
exceed1
Member
 
Registered: Mar 2008
Location: oslo
Distribution: debian,redhat
Posts: 199

Rep: Reputation: 31
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.

Last edited by exceed1; 01-31-2009 at 05:51 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh -- Permission denied (publickey,password,keyboard-interactive). davidkline Linux - Networking 11 08-20-2014 02:19 PM
No longer able to log into ssh. Password right but "permission denied" Baix Linux - Software 11 11-21-2008 12:44 PM
SSH Permission Denied Chimney Linux - Security 1 11-10-2005 06:01 PM
fc3 /proc/net permission denied adem0rdna Fedora 15 05-25-2005 11:08 PM
perl: bad interpreter: Permission denied bulliver Linux - Software 4 01-27-2003 03:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration