2

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

4

4 回答 4

1

假设您使用的是公钥身份验证,只需设置ssh-agent. 如果没有openssh,则能够创建一个主连接,然后可以在没有额外身份验证的情况下使用该主连接,但这并不是所有ssh实现都通用的。我没怎么玩过它,因为交互式使用有点麻烦,但它可能值得研究一下脚本使用。

于 2012-11-09T16:54:51.920 回答
1

有3种方法可以实现这一点:

1 -正确的方法:

2 - 用期望做:

3 - 使用pscp而不是 scp:

  • pscp是“putty-tools”的一部分:sudo apt-get install putty-tools
  • pscp 允许您将密码作为 cmdline 选项的一部分提供
  • 示例用法:pscp -scp -pw $password $file_path $login@$IP:$dest_dir
于 2012-11-09T16:28:07.723 回答
1

假设您在远程计算机上有一个帐户,首先使用 SSH建立连接,然后使用 scp 复制所需文件 - 类似于:

ssh -y joepublic@examplehost.example.com

Password: <joepublic's password>

joepublic@examplehost.example.com

scp joepublic@thathostoverthere:/home/joepublic/thefileireallywantoverhere .
于 2012-11-09T16:29:01.173 回答
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();
于 2012-11-09T22:58:02.073 回答