質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

Q&A

解決済

1回答

4735閲覧

ansible-playbookコマンドでssh接続エラー

wangzj

総合スコア53

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

0グッド

0クリップ

投稿2018/05/25 10:28

編集2018/05/25 11:13

前提・実現したいこと

実行コマンド:

ansible-playbook -u wangzj --private-key /home/wangzj/.ssh/id_rsa -i inventories/hosts setup.yml

実行するとエラーが発生してしまった

事前に作ったPrivateKey

wangzj@wangzj-virtual-machine:~$ ssh-keygen -C Comment Generating public/private rsa key pair. Enter file in which to save the key (/home/wangzj/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/wangzj/.ssh/id_rsa. Your public key has been saved in /home/wangzj/.ssh/id_rsa.pub. The key fingerprint is: SHA256:mMreCmLMxB9ZE74meODdLT+WpfnPxb+8PZryl5x/5UI Comment The key's randomart image is: +---[RSA 2048]----+ | . | | . . | | . + | |o + + +o | | = * =o.S. | |+ o.+.o = . E .| |.+..o B +..+| |.. o .. o ... =*+| | o.. ..oo+o*O| +----[SHA256]-----+

発生している問題・エラーメッセージ

TASK [Gathering Facts] ********************************************************* fatal: [192.168.255.5]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", "unreachable": true} [WARNING]: Could not create retry file '/etc/ansible/all-in-one/aaa.retry'. [Errno 13] Permission denied: u'/etc/ansible/all-in-one/aaa.retry'

sudo ansible -m ping allを実行しました。
もしかして、/etc/ansible/hostsに設定が足りないでしょうか?

wangzj@wangzj-virtual-machine:~$ sudo ansible -m ping all [sudo] wangzj のパスワード: [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

/etc/ansible/hostsの内容↓:

# This is the default ansible 'hosts' file. # # It should live in /etc/ansible/hosts # # - Comments begin with the '#' character # - Blank lines are ignored # - Groups of hosts are delimited by [header] elements # - You can enter hostnames or ip addresses # - A hostname/ip can be a member of multiple groups # Ex 1: Ungrouped hosts, specify before any group headers. ## green.example.com ## blue.example.com ## 192.168.100.1 ## 192.168.100.10 # Ex 2: A collection of hosts belonging to the 'webservers' group ## [webservers] ## alpha.example.org ## beta.example.org ## 192.168.1.100 ## 192.168.1.110 # If you have multiple hosts following a pattern you can specify # them like this: ## www[001:006].example.com # Ex 3: A collection of database servers in the 'dbservers' group ## [dbservers] ## ## db01.intranet.mydomain.net ## db02.intranet.mydomain.net ## 10.25.1.56 ## 10.25.1.57 # Here's another example of host ranges, this time there are no # leading 0s:

試したこと

下記、確認しました。問題ないはずです。

  1. 間違った鍵で接続しようとしている。キーペアは正しいか確認する
  2. 間違ったユーザー名で接続しようとしている。正しいユーザー名かどうか確認する
  3. ホスト名が間違っている。ホスト名が正しいかどうか確認する。

terminalにコマンド
ssh wangzj@192.168.255.5
でログインしてみました、成功しました。
上記以外、何か原因がかんがえられますでしょうか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

下記手順で解決しました。
①SSHサーバ構築が正しいか
②SSHクライアント構築が正しいか
③SSHのPrivateKey生成は正しいか
④生成したPubKeyをサーバのauthorized_keysにアップロードしたか
⑤パーミッション(アクセス権)が正しく設定されたか
$ chmod 700 ~/.ssh
$ chmod 600 authorized_keys
⑥クライアント側から接続できるか
$ ssh <ユーザ名>@<IPアドレス>

投稿2018/05/28 01:17

wangzj

総合スコア53

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問