Reputation: 1475
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
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
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
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
Reputation: 47367
There are 3 ways to achieve this:
1 - The proper way:
2 - Doing it with expect:
3 - Use pscp instead of scp:
sudo apt-get install putty-tools
pscp -scp -pw $password $file_path $login@$IP:$dest_dir
Upvotes: 1