3

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...

Tomek Wyderka
  • 1,425
  • 1
  • 15
  • 21

4 Answers4

1

There are 3 ways to achieve this:

1 - The proper way:

2 - Doing it with expect:

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
Community
  • 1
  • 1
sampson-chen
  • 45,805
  • 12
  • 84
  • 81
  • 1st way: I need to scp file to HOST and then ssh on that HOST, but I never was there before. First time log in. No – Tomek Wyderka Nov 09 '12 at 17:54
  • 2nd and 3rd way maybe will be useful for me. Thanks! I wish only I can avoid double starting connection. scp and ssh command open encrypted tunnel and it takes time... they are opening exactly the same tunnel, with same passwords. I wish we can reuse this that tunnel. – Tomek Wyderka Nov 09 '12 at 17:58
  • continuation of first comment: No keys exchanged. No knowledge about remote host, except it is linux. – Tomek Wyderka Nov 09 '12 at 18:00
1

Assuming you have an account on the remote machine, use SSH first to establish a connection, and then use scp to copy across wanted files - something like:

ssh -y joepublic@examplehost.example.com

Password: <joepublic's password>

joepublic@examplehost.example.com

scp joepublic@thathostoverthere:/home/joepublic/thefileireallywantoverhere .
Miguel
  • 1,966
  • 2
  • 18
  • 32
  • Last command scp requires password too. I need to type password just once. And I have just remote HOSTNAME/IP, not route back. – Tomek Wyderka Nov 09 '12 at 17:47
1

Assuming you're using publickey authentication, just set up ssh-agent. If not openssh has the ability to create a master connection which further connections can then use without additional authentication, but that's not common to all ssh implementations. I haven't played with it much, as it's a bit of a hassle for interactive use, but it might be worth looking into for scripted use.

twalberg
  • 59,951
  • 11
  • 89
  • 84
  • No publickkey authentication, just password. It need to work with remote hosts which I never was login before. No ssh-agent possible in my cases. – Tomek Wyderka Nov 09 '12 at 17:49
1
#/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();
salva
  • 9,943
  • 4
  • 29
  • 57