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

ベストアンサー1

おすすめ記事