2016-12-12 8 views
2

私はubuntu ec2ホスト上で稼働しているドッカー悪魔を持っています。外部のマシンからec2 ubuntuホストのドッカーコンテナにsshする方法

私はこのubuntu ec2ホスト上でsshd conatainerをセットアップすることができ、ドッカーホスト.i.eからsshを実行することができます。

[email protected]:~/docker-work$ sudo docker run -d -P --name ssh-enabled ssh-enabled 
bb7f535124b3df403ae97da770fe2e4a4969a7ecddfb5d546aaddfe00e40374d 

[email protected]:~/docker-work$ sudo docker port ssh-enabled 
22/tcp -> 0.0.0.0:32768 

[email protected]:~/docker-work$ ssh [email protected] -p 32768 

The authenticity of host '[127.0.0.1]:32768 ([127.0.0.1]:32768)' can't be established. 
ECDSA key fingerprint is e6:74:aa:52:8e:3d:19:7a:92:da:85:d4:b9:f9:ed:f1. 
Are you sure you want to continue connecting (yes/no)? yes 
Warning: Permanently added '[127.0.0.1]:32768' (ECDSA) to the list of known  hosts. 
[email protected]'s password: 
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.19.0-30-generic x86_64) 

* Documentation: https://help.ubuntu.com/ 

The programs included with the Ubuntu system are free software; 
the exact distribution terms for each program are described in the 
individual files in /usr/share/doc/*/copyright. 

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by 
applicable law. 

[email protected]:~# 

しかし、私はどのように外のドッカーホストからこのコンテナに接続できるかわかりません。

Iは、しかし、私は、コマンド応答下

[email protected]:~/docker-work$ sudo docker ps -as 

CONTAINER ID  IMAGE    COMMAND     CREATED     STATUS      PORTS     NAMES    SIZE 
bb7f535124b3  ssh-enabled   "/usr/sbin/sshd -D"  8 minutes ago  Up 8 minutes    0.0.0.0:32768->22/tcp ssh-enabled   32.51 kB (virtual 868.4 MB) 
で示すよう

ドッカーコンテナが起動している容器に直接sshをしたい

ssh -i /home/xxxxxx/xxxxxxxxx.pem [email protected] 

以下のような外部装置からホストをドッカーへのSSHができます

ドッキングホストがポート32768でリッスンしています。ユーザーrootでsshコンテナに接続しようとすると失敗します。

秘密鍵を考える
[email protected]:~$ ssh -i '/home/xxxxx/xxxxxxx.pem' [email protected] -p 32768 -v 
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH_6.6.1* compat 0x04000000 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: server->client [email protected] <implicit> none 
debug1: kex: client->server [email protected] <implicit> none 
debug1: sending SSH2_MSG_KEX_ECDH_INIT 
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY 
debug1: Server host key: ED25519 3e:6a:c6:9e:34:98:2e:81:b5:e1:88:d1:15:63:bb:41 
debug1: checking without port identifier 
The authenticity of host '[172.16.27.205]:32768 ([172.16.27.205]:32768)' can't be established. 
ED25519 key fingerprint is 3e:6a:c6:9e:34:98:2e:81:b5:e1:88:d1:15:63:bb:41. 
Are you sure you want to continue connecting (yes/no)? yes 
Warning: Permanently added '[172.16.27.205]:32768' (ED25519) to the list of known hosts. 
debug1: ssh_ed25519_verify: signature correct 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentications that can continue: publickey,password 
debug1: Next authentication method: publickey 
debug1: Trying private key: /home/rbharadwaj/syd01-devops-ruc-app-instances 
debug1: key_parse_private2: missing begin marker 
debug1: read PEM private key done: type RSA 
debug1: Authentications that can continue: publickey,password 
debug1: No more authentication methods to try. 
Permission denied (publickey,password). 

210は私も親切に私は上記のシナリオでは、直接の容器に接続できることができる方法を提案、それは

ssh -i '/home/xxxx/xxxxx.pem' [email protected] -p 32768 

を失敗したが、以下のように容器にsshをしようとしたユーザーのUbuntuのある

答えて

1

sshの出力は、秘密鍵を正しく設定していないようです。それはコンテナ内の正しい場所にありますか(/root/.ssh/authorized_keys)、正しいアクセス権を持っていますか?

chmod 700 /root/.ssh 
chmod 600 /root/.ssh/authorized_keys 
+0

あなたは、これが認証された鍵の問題であると指摘したログの正確な内容を強調するのを助けてください。 –

+0

ただ、これら2行: DEBUG1:秘密鍵しよう:/ホーム/ rbharadwaj/syd01-DevOpsチーム-RUC-APP-インスタンスを DEBUG1:key_parse_private2:私は前にこの問題が発生しており、ファイルに関連していたされたマーカー を開始行方不明パーミッション。 – Gabb0

2

sshを実行するようにコンテナを設定することは常に勧められません。ログを監視し、サービスなどを制御する必要がある場合は、コンテナへの直接的なsshアクセスを設定する代わりに、これを達成する他の方法(ログアグリゲータなど)を見つける方が良いかもしれません。

詳細はhttps://jpetazzo.github.io/2014/06/23/docker-ssh-considered-evil/を参照してください。

私はこれがあなたの質問に直接答えないことを理解します。しかし、利便性以外にコンテナに直接アクセスする必要がある理由は不明です。どのようにsshキーを管理していますか?

+0

を接続することができましたconclainersと接続し、配備を行う必要があります。 私は、現在の展開構成管理戦略に可能な限り最小限の変更を加えることができますが、ドッカーホスト自体には責任があることを理解します。私はシナリオの上で達成する見ています –

+0

ちょうどあなたの更新されたコンテナを構築し、それをあなたのホストにプッシュするジェンキンスを得るようなものは、プレイブックを使用するのではなく、再現可能な方法で物事を行う標準的な方法です。 FWIWこれはJenkinsやECSのようなDevOpsフレームワークがあり、リビジョンの青緑の展開を容易にする理由です。 IMOあなたのドッカーファイルであなたのリビジョンをキャプチャする方が、Anoughプレイブックによって更新される必要がある最新のDockerfileに頼るよりもきれいです。いずれかの方法!私はあなたが解決策を見つけてうれしいです。乾杯@ RuchirBharadwaj! – W4t3randWind

1

上記の推奨事項に従って私が行ったコンテナには、/root/.sshフォルダはありませんでした。

1))は、コンテナに

2. /root/.sshディレクトリを作成し、承認されたファイル

3を作成した)私が接続しようとしているホストからの公開鍵のコンテンツを配置このホスト

と私は展開のためansibleを使用して既存のセットアップ、(構成管理のためのリモートホスト上ansible SSH)、私はセットアップコンテナにしようと私のANS-胆汁ホストを使用していている

関連する問題