【问题标题】:nohup causes "read_passphrase: can't open /dev/tty"nohup 导致“read_passphrase:无法打开 /dev/tty”
【发布时间】:2014-05-14 18:56:32
【问题描述】:

我在脚本中有一个简单的远程 ssh 命令,nohupssh.sh

sleep 30
ssh -v  -l developer server11  "/usr/local/jdk1.7.0_45/bin/jmap -histo:live 1770;"

我运行脚本如下:

nohup nohupssh.sh > out.log 2>&1 & 

当我如上所示执行它时,jmap 实用程序在远程服务器上成功执行。但是,如果我如上所示执行它并退出 bash shell,则会收到如下所示的错误。

请注意,我在本地和远程服务器中都有一个格式正确的授权密钥。另请注意,由于这些服务器是共享的,因此两个服务器中都没有 id_rsa。

我尝试了很多组合:

ssh -v -A -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null server11 .... 

但无济于事。我仔细检查了 ssh 的手册页以获取线索,尝试了各种选项。我认为必须有一个或一组 ssh 选项可以解决这个问题。真正的脚本(而不是上面的删节)也有 scp 。因此,我希望我无法使用的选项对 scp 和 ssh 都有效。

完整的详细日志是

OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /home/developer/.ssh/config
debug1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to server11 [10.255.10.20] port 22.
debug1: fd 4 clearing O_NONBLOCK
debug1: Connection established.
debug1: identity file /home/developer/.ssh/identity type -1
debug1: identity file /home/developer/.ssh/id_rsa type -1
debug1: identity file /home/developer/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
Warning: Permanently added 'server11,10.255.10.20' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
****************************************************************************
WARNING: Unauthorized access to this system is forbidden and will be
prosecuted by law. By accessing this system, you agree that your
actions may be monitored.
****************************************************************************


debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/developer/.ssh/identity
debug1: Trying private key: /home/developer/.ssh/id_rsa
debug1: Trying private key: /home/developer/.ssh/id_dsa
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such device or address
ssh_askpass: exec(/usr/libexec/openssh/ssh-askpass): No such file or directory
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: No such device or address
ssh_askpass: exec(/usr/libexec/openssh/ssh-askpass): No such file or directory
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: No such device or address
ssh_askpass: exec(/usr/libexec/openssh/ssh-askpass): No such file or directory
debug1: Authentications that can continue: publickey,password
debug1: No more authentication methods to try.
Permission denied (publickey,password).

【问题讨论】:

标签: ssh scp nohup


【解决方案1】:

来自错误日志:

可以继续的身份验证:公钥、密码

由于您没有设置公钥(“没有 id_rsa”),您需要输入密码才能访问远程服务器,但您已断开标准输入:

read_passphrase: 无法打开 /dev/tty: 没有这样的设备或地址

SSH 不太适合黑客自动输入密码,因此,如果您无法在其中放置 id_rsa,最好的办法是在输入远程服务器密码后后台分离。试试^Z:

  1. 运行nohup nohupssh.sh &gt; out.log 2&gt;&amp;1
  2. 等待 30 秒,然后输入远程服务器密码
  3. 按控制-Z
  4. 运行bg %1
  5. 您现在应该可以退出 shell。

【讨论】:

    【解决方案2】:

    当我的私钥格式错误时,我遇到了这个read_passphrase: can't open /dev/tty 错误 - 它不是多行,而是作为单行传递的,并且您可能有任何其他格式问题,例如在开始时忘记了“-”或end,或行尾有问题,例如缺少换行符格式或行尾的附加字母。

    更多详情请参见Dockerfile: clone repo with passwordless private key. Errors: “authentication agent” or “read_passphrase: can't open /dev/tty”,主要思想来自Add private key to ssh-agent in docker file,其思想又来自Gitlab CI/Docker: ssh-add keeps asking for passphrase

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 2021-06-29
      • 2014-12-23
      • 1970-01-01
      • 1970-01-01
      • 2015-06-09
      • 1970-01-01
      相关资源
      最近更新 更多