仅当从 nohup 恶魔后台运行时,SSH 因身份验证失败次数过多而失败

仅当从 nohup 恶魔后台运行时,SSH 因身份验证失败次数过多而失败

我有下面的脚本,它在远程 unix 服务器中运行 ssh 命令并将输出存储在变量中并打印该变量。

当我在前台运行或在后台使用 ( ) 运行时,只要会话处于活动状态,脚本就可以正常运行nohup ./script &,但是当我退出该会话时,脚本会失败,并显示“太可能身份验证失败”。

我检查过ps -ef | grep script,显示后台进程已分配给终端 /dev/pts1,现在显示“?”这是一个恶魔过程。

我已经检查了 ssh -n 或 -f 选项,但以同样的问题结束。请注意,SSH 命令使用自动密码运行。

脚本:(我运行命令为nohup ./script.sh > script.log 2>&1 &

#!/usr/bin/ksh
while ture;
do    
x=`ssh username@remote_server "ls -l /dir1/dir2/*|wc -l"`    
echo "the count is $x"    
sleep 2m    
done

之后,我尝试使用 ssh -v 选项进行捕获,请找到失败的输出。我发现它说 /dev/tty 未找到,我猜这是因为没有终端,因为它被分配给恶魔进程,因为我们已经杀死了运行 nohup & 的会话。

debug1: Host 'username' is known and matches the DSA host key.
debug1: Found key in /home/.ssh/known_hosts:15
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/.ssh/id_rsa --------here it was like Offering RSA public key: local_user_name
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /home/.ssh/id_dsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /home/.ssh/id_ecdsa
debug1: Trying private key: /home/.ssh/id_ed25519
debug1: Next authentication method: keyboard-interactive
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such device or address
Received disconnect from remote_IP_address:2: Too many authentication failures
Authentication failed.

根据成功日志的要求在此处进行编辑:

nohup: ignoring input
OpenSSH_7.4p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to remote_server [remoteserver_ip] port 22.
debug1: Connection established.
debug1: identity file /home/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2
debug1: match: OpenSSH_7.2 pat OpenSSH* compat 0x04000000
debug1: Authenticating to remote_server:22 as 'remote_server_user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ssh-dss
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha1 compression: none
debug1: kex: [email protected] need=20 dh_need=20
debug1: kex: [email protected] need=20 dh_need=20
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-dss SHA256some_key_goes_here
debug1: Host 'remote_server' is known and matches the DSA host key.
debug1: Found key in /home/.ssh/known_hosts:15
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: MY_user_id
debug1: Server accepts key: pkalg rsa-sha2-512 blen 533
debug1: Authentication succeeded (publickey).
Authenticated to remote_server ([remote_server_ip]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = C
debug1: Sending command: MY COMMAND HERE
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
debug1: fd 2 clearing O_NONBLOCK
Transferred: sent 3784, received 2544 bytes, in 0.1 seconds
Bytes per second: sent 37022.5, received 24890.4
debug1: Exit status 0

请让我知道如何解决这个问题。如果您需要更多信息来提供此问题的解决方案,请告诉我。本地服务器:GNU Linux

远程服务器:sunSolaris

相关内容