【问题标题】:plink puts me in an interactive shell prompt while executing batchplink 在执行批处理时让我进入交互式 shell 提示符
【发布时间】:2014-03-05 16:34:06
【问题描述】:

我正在尝试使用 plink(Putty link) 使用批处理文件连接到测试服务器,以避免任何用户提示和执行 shell 脚本。但是它通过在使用我不想要的用户名和密码登录后显示用户交互提示而暂停。

请提供任何建议说明为什么会发生这种情况,或者我是否需要更改配置中的任何设置以使其正常工作。

以下是相同的日志。我希望它在此步骤之后执行一个 shell 脚本,在此之前它会停止并且 plink 将我置于交互式 shell 中

D:\>plink -v -ssh xxx@xxx.xxx.xxx.xx.com –pw XXXXX
Looking up host "xxx@xxx.xxx.xxx.xx.com"
Connecting to xxx.xx.xxx.xx port 22
Server version: SSH-2.0-OpenSSH_5.1
Using SSH protocol version 2
We claim version: SSH-2.0-PuTTY_Release_0.63
Doing Diffie-Hellman group exchange
Doing Diffie-Hellman key exchange with hash SHA-256
Host key fingerprint is:
ssh-rsa 1024 a5:c3:96:57:53:7c:72:06:8d:86:09:76:27:3e:18:8d
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "xxx".

Attempting keyboard-interactive authentication
Access granted
Opening session as main channel
Opened main channel
Allocated pty (ospeed 38400bps, ispeed 38400bps)
Started a shell/command
Last login: Wed Mar  5 09:56:41 2014 from 10.34.39.22


←[?1034hxxxxavu2:←]2;xxx@xxxxavu2~ >

【问题讨论】:

    标签: unix batch-file ssh plink


    【解决方案1】:

    它为您提供了一个交互式外壳,因为您实际上并没有给它一个在连接后执行的命令。用引号将您的命令括起来,例如:

    D:\>plink -v user@xxx.xxx.xxx.xxx -pw XXXXX "df -h"
    

    【讨论】:

    • 感谢您的回复。
    【解决方案2】:

    使用 SSH 时,首次连接时,您需要验证服务主机密钥才能建立连接。

    通过plink,命令行会产生提示,要求用户“接受服务主机密钥?(y/n)”。

    第 1 步:修复“来自服务器的键盘交互式身份验证提示”

    按照 URL 说明并取消选择“在您的 putty 中尝试键盘交互式身份验证 (SSH-2)。

    https://support.linuxacademy.com/hc/en-us/articles/360027730172-How-Can-I-Copy-and-Paste-into-Putty-on-Windows

    第 2 步:以下命令将为使用 plink 的每个 Linux 服务器首次 SSH 连接修复“验证服务主机密钥”。

     回显是| C:\PuTTY\plink.exe 用户名@10.148.147.41 -pw *************** 日期

    第 3 步:现在您可以使用带有 -batch 选项的 plink 立即运行下一个脚本,例如“服务器正常运行时间检查”或“监控代理重启”(禁用所有交互式提示)

    C:\PuTTY\plink.exe -batch 用户名@10.148.147.41 -pw *************** -m C:\uptime_linux.sh 
    C:\PuTTY\plink.exe -batch 用户名@10.148.147.41 -pw *************** -m C:\monitoring-agent-check_linux.sh 
    

    上述信息 100% 将帮助您使用 plink 实用程序自动执行 linux 任务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-19
      • 2014-09-06
      • 1970-01-01
      • 1970-01-01
      • 2015-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多