简体   繁体   English

非交互式ssh到服务器但交互式

[英]Non-interactively ssh to server but interactively

I understand all the security risks using ssh in this way, but what I need at the moment is a few line (bash) shell script capable to log-in to the target server and just do a foo command and get back to the source host, something like: 我以这种方式理解使用ssh的所有安全风险,但我现在需要的是一些能够登录到target服务器并执行foo命令并返回源主机的一行(bash)shell脚本, 就像是:

while true
do
   ssh target foo   # Here I get the prompt for a password which
                    # I would like to give non-interactively
   sleep 1
done

I do not want to use the ssh key based authentication because what I truly need is to simulate once a second (or so) the interactive log-in process (but not-interactively!). 不想使用基于ssh密钥的身份验证,因为我真正需要的是每秒模拟一次(或左右)交互式登录过程(但不是交互式!)。

You'll need to script it with expect in something like, say, perl . 你需要脚本它expect在类似,也就是说, perl的

Edit: You could also try scripting expect directly in bash . 编辑:您也可以尝试脚本expect直接庆典

You have to edit the SSH server to allow login based only on a key and not from a password. 您必须编辑SSH服务器以允许仅基于密钥而不是密码进行登录。

Try to see if this can help you. 试着看看这是否可以帮到你。

Of course if you can't edit the server configuration, you need to check other solutions 当然,如果您无法编辑服务器配置,则需要检查其他解决方案

sshpass is designed to provide a password to ssh programatically, instead of interactively. sshpass旨在以编程方式提供ssh的密码,而不是以交互方式提供。 So you can replace ssh target foo by eg sshpass -f passwordfile ssh target foo . 所以,你可以替换ssh target foo例如通过sshpass -f passwordfile ssh target foo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM