从任何服务器的脚本动态ssh

ssh dynamically from script from any server

好的,我已经搜索了几个小时,但似乎找不到解决方案。

我在远程服务器上有一个文件,该服务器上的一个本地用户对其具有写入权限。我有凭据。要求是:

shell/perl 脚本应该自动登录到服务器并写入该文件。 该脚本应该可以在网络上的任何服务器上运行,而无需安装任何额外的软件包,因为这将需要我进行 sudo,这将再次要求输入密码,因此无法通过脚本运行。

我尝试使用 expect,但服务器一直说找不到 spawn。

请指教

#!/bin/bash
ssh -l username hostname "password; ~/updatefile.sh params"

无效。

要使用密钥方法,请尝试以下操作:

#!/usr/bin/env ssh-agent /usr/bin/env bash
KEYFILE=`mktemp`
cat << EOF > ${KEYFILE}
-----BEGIN RSA PRIVATE KEY-----
[.......]
EOF
ssh-add ${KEYFILE}

ssh user host command

# Remove the key file.
rm -f ${KEYFILE}

生成密钥供使用,参考如下:http://www.ece.uci.edu/~chou/ssh-key.html