stdinでssh-copy-idを使用する方法は?

stdinでssh-copy-idを使用する方法は?

他の同様の質問があることは既に知っていますが、答えは役に立ちませんでした。他のフォーラムではSSHキーを使用またはプレインストールすることを提案していますが、私のシステムではSSHキーを使用またはプリインストールすることはsshpassできません。sshpass

stdin inまたは他の方法を使用してssh-copy-idSSHキーをリモートサーバーにコピーしたいと思います。 .stdinを使用してstdinを介してパスワードを渡すことができますecho

このような:

echo -e "1234" | ssh [email protected] "echo "my_key" >> ~/.ssh/authorized_keys"

これはCentOSシステムにあります。

ベストアンサー1

SSH_ASKPASSこれにはこの変数を使用できます。

connect.sh

#!/bin/bash

pwd="mypassword"

if [ ! -t 1 ]; then
   # The output is not going to stdout, assume the invoke is from SSH_ASKPASS
   printf "%s\n" "$pwd"
   exit 0
fi

# SSH_ASKPASS will be used only if DISPLAY is defined
export DISPLAY=:0

# Set the SSH_ASKPASS program to THIS script+
export SSH_ASKPASS="$0"

# setsid is required (Run a program in a new session)
setsid ssh-copy-id user@localhost

おすすめ記事