Tomek Wyderka
Tomek Wyderka

Reputation: 1475

two scp and ssh processes with single authentication

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

Upvotes: 3

Views: 2059

Answers (4)

salva
salva

Reputation: 10242

#/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();

Upvotes: 1

twalberg
twalberg

Reputation: 62499

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.

Upvotes: 1

user1812764
user1812764

Reputation: 11

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 [email protected]

Password: <joepublic's password>

[email protected]

scp joepublic@thathostoverthere:/home/joepublic/thefileireallywantoverhere .

Upvotes: 1

sampson-chen
sampson-chen

Reputation: 47367

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

Upvotes: 1

Related Questions