Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

two scp and ssh processes with single authentication

Tags:

shell

scp

ssh

I need to scp and then ssh to the same host. Is it possible to authenticate just one time? Is it possible to input password once, then scp file, then ssh on that host and work interactively?

Update

I get HOSTNAME and SSH_PASSWORD. I never log in on that machine before. I need to send some files (probably using scp) and then log in using ssh and work on that HOST interactively. I want to save time and input password just once. I have lots of such hosts...

like image 314
Tomek Wyderka Avatar asked Aug 21 '26 07:08

Tomek Wyderka


2 Answers

#/usr/bin/perl

use strict;
use warnings;
use Net::OpenSSH;

$ssh = Net::OpenSSH->new(host => '...', user => '...', password => '...');
$ssh->scp_put('/local/path/to/file', '/remote/path/to/file');
$ssh->system();
like image 77
salva Avatar answered Aug 23 '26 05:08

salva


There are 3 ways to achieve this:

1 - The proper way:

  • First, set up ssh keys.
  • Then you can use scp with your ssh keys.

2 - Doing it with expect:

  • Here's an example of how to ssh with expect and have it supply the password for you.

3 - Use pscp instead of scp:

  • pscp is part of "putty-tools": sudo apt-get install putty-tools
  • pscp allows you to supply the password as part of a cmdline option
  • sample usage: pscp -scp -pw $password $file_path $login@$IP:$dest_dir
like image 36
sampson-chen Avatar answered Aug 23 '26 05:08

sampson-chen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!