1752806 Members
5876 Online
108789 Solutions
New Discussion юеВ

Perl-SSH & permissions

 
SOLVED
Go to solution
Kalin Evtimov
Regular Advisor

Perl-SSH & permissions

Hello!

I have a small problem with ssh. I am using the Perl-SSH module to connect to a server and runa command. But I get:

Permission denied (publickey,gssapi,password,keyboard-interactive).

problem is that I don't know how to create this public key and how to use it in my code. It would be great if somebody can show me a link to read or a small example. Here is my code(same as example):
_______________________________
#! /opt/perl5/bin/perl

use Net::SSH qw(sshopen2);
use strict;

my $user = "root";
my $host = "hpserv";
my $cmd = "ls";

sshopen2("$user\@$host", *READER, *WRITER, "$cmd") || die "ssh: $!";

while () {
chomp();
print "$_\n";
}

close(READER);
close(WRITER);

______________________________

Thank you!
6 REPLIES 6
Simon Hargrave
Honored Contributor
Solution

Re: Perl-SSH & permissions

You need to setup keys such that this works from the shell: -

host1# ssh root@host2 ls

To do this: -

On host1: -

cd ~/.ssh
shh-keygen -f id.rsa -t rsa
(enter a blank passphrase when asked)

copy the contents of the public key file id.rsa.pub to host2, then

On host2: -

cat id.rsa.pub >> ~/.ssh/authorized_keys


Basically you are generating an id.rsa and id.rsa.pub on the "local" machine, then adding the public key to the authorized_keys list on the "remote" host, to allow access.

This procedure assumes you have a ~/.ssh directory on each host. If you do not, then simply ssh somehost on each box and this will create it with the correct permissions.
Kalin Evtimov
Regular Advisor

Re: Perl-SSH & permissions

Ok, now I have generated the keys on host and added the public key on the remote machine, but the script shows the sme errormessage. When I use ssh from the shell, I must type the password, and within the script there is no password..that is confusing me.
Simon Hargrave
Honored Contributor

Re: Perl-SSH & permissions

Check your ssh daemon config file /opt/ssh/etc/sshd_config and make sure you don't have the option

PubkeyAuthentication no

This will disallow public key authentication.

It this is set to yes (or commented out, yes is the default value), then check syslog for any errors. Chances are it's something like directory permissions (sshd is fussy about home directory permissions as well as .ssh directory and authorized_keys/id_rsa files etc).

Please post any relevant error messages.
H.Merijn Brand (procura
Honored Contributor

Re: Perl-SSH & permissions

Very important for ssh is the file and directory permissions

# chown -R logname ~/.ssh
# chmod 700 ~/.ssh
# chmod 600 ~/.ssh/*
# chmod +r ~/.ssh/*.pub

On both machines
Then please check if it works from the command prompt with ssh and scp before digging into perl failures

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Kalin Evtimov
Regular Advisor

Re: Perl-SSH & permissions

Well, ssh works as before, asks for a password. Perl does not authenticate. I think I have to find a book for ssh to check what are all the options in the config-file for.
If I succeed I will post.

Thank you.
Emil Velez
Honored Contributor

Re: Perl-SSH & permissions

I found a few challenges trying to setup passwordless ssh sessions between systems. Enclosed is a cookbook I created to summarize what I found worked on HPUX. I hope it helps