ttyのないユーザーとしてsshできません


10

ttyを持たないユーザー(私のapacheサーバーを実行しているユーザー)からsshを(キー認証を使用して)呼び出して単一のコマンドを実行しようとしていますが、次の結果が得られます。

OpenSSH_5.9p1, OpenSSL 1.0.0g 18 Jan 2012
Pseudo-terminal will not be allocated because stdin is not a terminal.
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to localhost [::1] port 54367.
debug1: Connection established.
debug1: identity file nonpublic/id_rsa type 1
debug1: identity file nonpublic/id_rsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9
debug1: match: OpenSSH_5.9 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
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: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA e3:c2:37:8e:8b:d4:77:63:7f:d2:ba:12:e5:e9:d1:9a
debug1: checking without port identifier
debug1: read_passphrase: can't open /dev/tty: No such device or address
Host key verification failed.

sshを呼び出すと、-tフラグが設定されます。キーにはパスフレーズがないため、入力の必要性は抑制されますが、明らかにそうではありません。sshが/ dev / ttyを開こうとしないようにするにはどうすればよいですか?

編集:コードタグが機能していませんか?

Edit2:フルsshコマンド:

ssh -i nonpublic/id_rsa -l username -p 54367 -t -v username@localhost /home/username/minecraftserver/Scripts/start 2>&1

ユーザー名を「username」に置き換えました。

Edit3:rootと同じキーを使用してssh-ingを試行し、次の結果を得ました。

OpenSSH_5.9p1, OpenSSL 1.0.0g 18 Jan 2012
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to localhost [::1] port 54367.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /srv/http/nonpublic/id_rsa type 1
debug1: identity file /srv/http/nonpublic/id_rsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9
debug1: match: OpenSSH_5.9 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
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: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA e3:c2:37:8e:8b:d4:77:63:7f:d2:ba:12:e5:e9:d1:9a
debug1: checking without port identifier
The authenticity of host '[localhost]:54367 ([::1]:54367)' can't be established.
ECDSA key fingerprint is e3:c2:37:8e:8b:d4:77:63:7f:d2:ba:12:e5:e9:d1:9a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:54367' (ECDSA) to the list of known hosts.
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /srv/http/nonpublic/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/srv/http/nonpublic/id_rsa':
debug1: No more authentication methods to try.
Permission denied (publickey).

パスフレーズは必要ないはずですが、パスフレーズの入力を求められます。さらに、WindowsマシンでPuTTYを使用してSSHでキーを使用しても問題なく、パスフレーズの入力を求められません。

Edit4:私はサーバーをapacheユーザーのknown_hostsに追加し、今これを取得します:

OpenSSH_5.9p1, OpenSSL 1.0.0g 18 Jan 2012
Pseudo-terminal will not be allocated because stdin is not a terminal.
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to localhost [::1] port 54367.
debug1: Connection established.
debug1: identity file nonpublic/id_rsa type 1
debug1: identity file nonpublic/id_rsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9
debug1: match: OpenSSH_5.9 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
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: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA e3:c2:37:8e:8b:d4:77:63:7f:d2:ba:12:e5:e9:d1:9a
debug1: Host '[localhost]:54367' is known and matches the ECDSA host key.
debug1: Found key in /srv/http/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: nonpublic/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: key_parse_private_pem: PEM_read_PrivateKey failed
debug1: read PEM private key done: type
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: No more authentication methods to try.
Permission denied (publickey).`

また、これはknown_hostsの内容です:

[localhost]:54367 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBILr7jLp5CeYfyrCroaDjkaWgDHXRrQD+G8Fz/CQOY1PcluUFTkrN447bXmC6R27LOClE+RPaveYb4MOlObpGGE=

ecdsaと表示されるのはなぜですか?これは、RSAキーです。

Edit5:解決しました。問題は、キーペアがPuTTYによって生成され、OpenSSHと互換性のない形式で秘密キーを書き込むことでした。コメントでcjcによって提供されるソリューション。


Re:コードタグ。いいえ、コードをバックティックで囲むか、行の前に4つのスペースを入れます。
cjc 2012年

完全なsshコマンドとは何ですか?
cjc 2012年

なぜ合格-tですか?
Zoredache

@Zoredache助けになると思った。一部のサイトはそれを提案しました。
Surma

1
@ Surma、ecdsaはクライアントのキーではなく、サーバーのキーを参照しています。
amcnabb 2012年

回答:


11

問題は、実際にはパスフレーズを読み取ろうとしていることではないようです。これは単なる警告です。むしろ、それはホスト鍵の検証を行おうとしていますが失敗しています。ホストキーについて決して尋ねないようにしたい場合は、sshコマンドラインに次のオプションを追加することを検討してください:

-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null

セキュリティに影響する可能性があることに注意してssh_configください。これらのオプションについては、manページで必ずお読みください。

編集:更新されたエラーメッセージを考えると、IDファイルが破損しているようです(またはcjcが指摘したように、形式が間違っている可能性があります)。ssh-keygenを使用して手動で新しいものを作成し、それをサーバーのauthorized_keysに追加してください。


あなたは正しいようです、私はルートとしてキーを使用しようとしました。結果はOPになります。
Surma

1
実際には、StrictHostKeyChecking = noを使用する代わりに、サーバーの公開鍵を取得して、ユーザーの.ssh / known_hostファイルに貼り付けることもできます。または、システム全体のknown_hostsファイルに入れます。
cjc 2012年

@cjc、私は通常それがより良い解決策であることに同意します。
amcnabb 2012年

@cjc(サーバーを既知のホストに追加した)ルートからknown_hostsをコピーし、適切な権限を設定しました。異なる出力が表示されるので、OPを確認してください。
スルマ2012年

1
@amcnabb PuTTYでキーを使用したとのことですが、キーをOpenSSHに変換しましたか?
cjc 2012年

0

興味深いことに、環境として何が設定されているか/etc/passwd-不足している/bin/bashことがおそらく問題です。


/ bin / false私はおそらくこれがphpによって実行されていることを述べるべきだったでしょう。
Surma

1
わかった。次に、その場合、なぜハックするのではなく、pecl.php.net / package / ssh2を使用しないのですかshell_exec()
Ben Lessani-Sonassi

それはいいアイデアです。
スルマ2012年

確かに、あなたはあなたが本当にあなたがあなたがあなたがあなたの質問でこれをPHP経由でこれをやろうとしていることを説明すべきです-私が提供した答えはあなたの質問を解決するためにより正確です。
ベンレッサーニ-ソナッシ
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.