我在脚本中有一个简单的远程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,我会收到如下所示的错误。
请注意,我在本地和远程服务器上都有格式正确的authorized_keys。另请注意,任何一台服务器都没有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).
答案 0 :(得分:0)
从错误日志中:
可以继续的身份验证:publickey,password
由于您没有设置公钥(&#34;没有id_rsa&#34;),您需要输入密码才能访问远程服务器,但是您已经断开了stdin的连接:
read_passphrase:无法打开/ dev / tty:没有这样的设备或地址
SSH不太容易自动输入密码,所以如果你不能在那里输入id_rsa,最好的办法是在进入远程服务器之后进行背景和分离&# 39;密码试试^ Z:
nohup nohupssh.sh > out.log 2>&1
bg %1
答案 1 :(得分:0)
当我的私钥格式错误时,我遇到了这个 read_passphrase: can't open /dev/tty
错误 - 它不是多行,而是作为单行传递,并且您可能有任何其他格式问题,例如忘记的“-”开始或结束,或者行尾出现错误,例如缺少换行符格式或行尾的附加字母。
有关详细信息,请参阅 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。