生産環境のSCP自動化

生産環境のSCP自動化

scp本番環境でコマンドの使用を実装したいです。自動化スクリプトにパスワードを提供したくありません。

解決策は何ですか?

段階的なソリューションが必要です。

ベストアンサー1

次の記事に続きここ:

あなたはする必要がありますssh-keygenを使用したパスワードレスSSH接続の設定これにより、パスワードやその他のリモート操作を求めるプロンプトを表示せずにscpを使用できます。

ssh-keygenとssh-copy-idを使用してSSHパスワードレスログインを実行する手順3

ssh-keygenssh-copy-id簡単な手順3を使用して、パスワードを入力しなくてもリモートLinuxサーバーにログインできます。この記事

  • ssh-keygen公開鍵と秘密鍵を作成します。
  • ssh-copy-idローカルホストの公開鍵をリモートホストのAuthorized_keysファイルにコピーします。また、リモートホストのホームに~/.ssh適切な権限を割り当てます~/.ssh/authorized_keys

この資料では、使用する際の3つのマイナーな問題とその使用ssh-copy-id方法についても説明します。ssh-copy-idssh-agent


ステップ1:localhostでssh-key-genを使用して公開鍵と秘密鍵を作成する

jsmith@local-host$ [Note: You are on local-host here]
jsmith@local-host$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 jsmith@local-host

ステップ2:ssh-copy-idを使用して公開鍵をリモートホストにコピーします。

jsmith@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
jsmith@remote-host's password:

メモ: ssh-copy-idリモートホストの.ssh/authorized_key

ステップ3:パスワードを入力せずにリモートホストにログインする

jsmith@local-host$ ssh remote-host
Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2
[Note: SSH did not ask for password.]

 jsmith@remote-host$ [Note: You are on remote-host here]

ほとんどの場合、上記の簡単な3つの手順を実行して作業を完了します。

また、以前に openSSH から openSSH にパスワードを入力せずに SSH と SCP を実行する方法について詳しく説明しました。

SSH2を使用する場合は、以前にSSH2からSSH2、OpenSSHからSSH2、SSH2からOpenSSHへのパスワードなしのSSHおよびSCPの実行方法について説明しました。

ssh-copy-id/と一緒にssh-add使用されますssh-agent

オプションに値が渡されず、使用できない場合は、次の-iエラー~/.ssh/identity.pubメッセージssh-copy-idが表示されます。

 jsmith@local-host$ ssh-copy-id -i remote-host
 /usr/bin/ssh-copy-id: ERROR: No identities found

ssh-agentロードキーを使用した場合は、ssh-addリモートホストからssh-copy-idキーをインポートしてコピーします。ssh-agentつまり、 にssh-add -Lオプションを渡さない場合です。-issh-copy-id

 jsmith@local-host$ ssh-agent $SHELL

 jsmith@local-host$ ssh-add -L
 The agent has no identities.

 jsmith@local-host$ ssh-add
 Identity added: /home/jsmith/.ssh/id_rsa (/home/jsmith/.ssh/id_rsa)

 jsmith@local-host$ ssh-add -L
 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsJIEILxftj8aSxMa3d8t6JvM79DyBV
 aHrtPhTYpq7kIEMUNzApnyxsHpH1tQ/Ow== /home/jsmith/.ssh/id_rsa

 jsmith@local-host$ ssh-copy-id -i remote-host
 jsmith@remote-host's password:

ssh 'remote-host'次に、次のようにマシンにログインしてチェックインします。.ssh/authorized_keys予期しない追加キーが追加されていないことを確認してください。

メモ:表示されたキーが追加されましたssh-add -L

おすすめ記事