プロンプトを表示せずにssh-addにパスワードを渡すにはどうすればよいですか?

プロンプトを表示せずにssh-addにパスワードを渡すにはどうすればよいですか?

読みましたが、パスワードの転送などのフラグman ssh-add表示されません。ssh-p

頑張った

# the -K is for macOS's ssh-add but it's not relevant
ssh-add -q -K ~/.ssh/id_rsa <<< $passphrase

しかし、私は次のような結果を得ます。

ssh_askpass: exec(/usr/X11R6/bin/ssh-askpass): No such file or directory

プロンプトを表示せずにパスワードを渡す方法

修正する

私がやっていることにさらにコンテキストを追加するためにSSHキーを生成するスクリプトを作成しています。そのパスワードを使用してパスワード、SSHキーを生成し、それをエージェントに追加します。

# ...
passphrase=$(generate_password)

ssh-keygen -t rsa -b 4096 -C $email -f $filename -N $passphrase -q
ssh-add -q -K $filename

Stephenの答えによると、これがどのように機能するのかわかりません。 SSH_ASKPASSが機能するには、一時スクリプトを作成してディスクに保存する必要があるようです。どんなアイデアがありますか?

ベストアンサー1

ssh-addマンページから:

 DISPLAY and SSH_ASKPASS
         If ssh-add needs a passphrase, it will read the passphrase from
         the current terminal if it was run from a terminal.  If ssh-add
         does not have a terminal associated with it but DISPLAY and
         SSH_ASKPASS are set, it will execute the program specified by
         SSH_ASKPASS (by default ``ssh-askpass'') and open an X11 window
         to read the passphrase.  This is particularly useful when calling
         ssh-add from a .xsession or related script.  (Note that on some
         machines it may be necessary to redirect the input from /dev/null
         to make this work.)

だから我々はそれを少し欺くために使用することができます。

プロキシにIDがない状態で起動します。

$ ssh-add -l
The agent has no identities.

今、パスワードを提供するプログラムが必要です。

$ cat x
#!/bin/sh
echo test123

次に、ssh-addがこのスクリプトを使用するように説得します。

$ DISPLAY=1 SSH_ASKPASS="./x" ssh-add test < /dev/null
Identity added: test (sweh@godzilla)

それだけです:

$ ssh-add -l                                          
2048 SHA256:07qZby7TafI10LWAMSvGFreY75L/js94pFuNcbhfSC0 sweh@godzilla (RSA)

修正された質問に基づいて追加するように編集されました。

パスワードは、Askpassスクリプトで使用される変数に渡すことができます。

たとえば、

$ cat /usr/local/sbin/auto-add-key
#!/bin/sh
echo $SSH_PASS

$ SSH_PASS=test123 DISPLAY=1 SSH_ASKPASS=/usr/local/sbin/auto-add-key ssh-add test < /dev/null
Identity added: test (sweh@godzilla)

提示されたワークフローでは、SSH_PASS=$passphrase新しく作成されたパスワードを使用します。

おすすめ記事