Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Send password in Net::SSH::Expect

by Fletch (Bishop)
on Jan 21, 2020 at 15:11 UTC ( [id://11111687]=note: print w/replies, xml ) Need Help??


in reply to Send password in Net::SSH::Expect

Perhaps use the existing ssh-copy-id that comes with most of the *NIX ssh implementations?

Update: Aaah, I missed you're trying to put the key from box B onto box C run from A ( A =hop=> B =hop=> C). It'd be a cleaner thing to run than your cat | ssh cat >>... but it's still going to prompt for the remote password going to the third box C.

Second update: Never used it, but reading over the docs I think you want to do something like this with send rather than exec:

## ... setup through to your login call the same $ssh->send( qq{ssh-copy-id bkpuser\@10.11.12.13} ); $ssh->waitfor( qq{Password:} ); $ssh->send( $epass );

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: Send password in Net::SSH::Expect
by gafaman (Novice) on Jan 23, 2020 at 08:41 UTC
    Unfortunately, this is a netscaler image without that function: -bash: ssh-copy-id: command not found I have been trying something a bit different though, and am stuck with this system call:
    system("ssh -q $ssh_user\@$bkp_destination 'sed -i \"s#.*$hostname#$sk +ey#g\" /tmp/test.txt'");
    The idea here is to replace the entry in /tmp/test.txt containing the $hostname with the $skey string. It works from the shell itself, but fails from the script, so I am pretty sure it is a escape issue.
      I ran ssh with -v and the problem is that it is sending only a bit of the command:
      system("ssh -qv $ssh_user\@$bkp_destination 'sed -i \"s#.*$hostname#$s +key#g\" /tmp/test.txt'"); Variables: $hostname = "HOSTA"; $skey = "ssh-rsa AAAAB3NzaC1yc2 root@HOSTA"; SSH output: ... debug1: Sending env LANG = en_GB.UTF-8 #ssh-rsa AAAAB3NzaC1yc2 root@HOSTA#g" /tmp/test.txt ...
      So it is not sending the entire -- sed -i \"s#.*$hostname -- bit.

        I would first construct the complete command and use the same string for debugging and for running the command:

        my $cmd = "ssh -qv $ssh_user\@$bkp_destination 'sed -i \"s#.*$hostname +#$skey#g\" /tmp/test.txt'"; warn "Launching [[$cmd]]"; system($cmd) == 0 or die "Couldn't launch ssh connection via [[$cmd]]: $? / $!";

        That way, the command you use for debugging and the command you run cannot deviate.

        Maybe using the # char (shell comment indicator) somewhere messes up your shell quoting. Even for readability, I would construct the shell string differently:

        my $cmd = qq(ssh -qv $ssh_user\@$bkp_destination 'sed -i "s#.*$hostnam +e#$skey#g" /tmp/test.txt');

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11111687]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (None)
    As of 2024-04-18 23:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found