scp:マイコンピュータを介してルーティングせずに2つのサーバー間でファイルをコピーします。

scp:マイコンピュータを介してルーティングせずに2つのサーバー間でファイルをコピーします。

server12台のサーバーがありますserver2

ssh root@server1キーログインを有効にするか、マイコンピュータからssh root@server2両方のサーバーにSSH経由で接続できます。

server1からファイルをコピーしたいserver2

制限要因:

  1. どのサーバーにもSSH秘密鍵を保存したくありません。また、パスワードを求めるメッセージも表示しないでください。
  2. 私のコンピュータを介してデータをルーティングしたくありません。したがって、この-3オプションは使用できません。

これは私が得た結果です。

$ scp -o StrictHostKeyChecking=no root@server1:~/script.sh root@server2:~/

Permission denied (publickey).
lost connection

詳細な出力:

$ scp -v -o StrictHostKeyChecking=no root@server1:~/script.sh root@server2:~/

Executing: /usr/bin/ssh '-x' '-oClearAllForwardings=yes' '-n' '-v' '-o' 'StrictHostKeyChecking=no' '-l' 'root' '--' 'server1' 'scp -v' '~/script.sh' 'root@server2:~/'
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /home/johndoe/.ssh/config
debug1: /home/johndoe/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to server1 [11.22.33.44] port 22.
debug1: Connection established.
debug1: identity file /home/johndoe/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/johndoe/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to server1:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:dS7************************************************Dw
debug1: Host 'server1' is known and matches the ECDSA host key.
debug1: Found key in /home/johndoe/.ssh/known_hosts:9
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 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
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:gw*******************************bc /home/johndoe/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 277
debug1: Authentication succeeded (publickey).
Authenticated to server1 ([11.22.33.44]: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.UTF-8
debug1: Sending command: scp -v ~/script.sh root@server2:~/
Executing: program /usr/bin/ssh host server2, user root, command scp -v -t ~/
OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to server2 [55.66.77.88] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.8
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.8 pat OpenSSH* compat 0x04000000
debug1: Authenticating to server2:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:pj***************************************eA
debug1: Host 'server2' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
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
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
lost connection
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2780, received 7200 bytes, in 1.1 seconds
Bytes per second: sent 2501.1, received 6477.7
debug1: Exit status 1

メモ:

  1. authorized_keys各サーバーのファイルに公開鍵を設定しました。
  2. 私の秘密鍵は、マイコンピュータのディレクトリにのみ保存されますid_rsa.ssh
  3. マイコンピュータのオペレーティングシステムserver2はUbuntu 18.04で、上記のオペレーティングシステムserver1はUbuntu 16.04です。

ベストアンサー1

おすすめ記事