vagrant upのあとにvagrant sshでゲストPCにログインできると思うのですが、その際に毎回パスワードを聞かれます.
work hogeTaro$ vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile "/Users/hogeTaro/work/.vagrant/machines/default/virtualbox/private_key"
IdentitiesOnly yes
LogLevel FATAL
とssh-configを見る限りはIdentityFileで秘密鍵を指定しているのですが、これだけではダメなのでしょうか?例えばVagrantは~/.ssh/configも見に行っているとか、そういうことなんでしょうか?(sshに関する知識が中途半端ですいません)
vagarnt sshでパスワードを入力ぜずにログインできる方法を教えていただけますと幸いです。
よろしくお願い致します。
Vagrant 1.8.1
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility).
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "debian/jessie64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network "private_network", ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
config.vm.synced_folder "./", "/home/vagrant/"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
# end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
end
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'debian/jessie64' is up to date...
==> default: A newer version of the box 'debian/jessie64' is available! You currently
==> default: have version '8.4.0'. The latest is version '8.5.0'. Run
==> default: `vagrant box update` to update.
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: hostonly
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Machine booted and ready!
GuestAdditions 5.0.16 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /Users/hogeTaro/work/ => /vagrant
==> default: Mounting shared folders...
default: /home/vagrant => /Users/hogeTaro/work
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
checkベストアンサー
+2
公開鍵認証には公開鍵が必要です。
Vagrantは対象となるVMの~/.ssh/autorized_keys
に公開鍵情報を追記してくれます。
まずはこちらのファイルが存在するか確認してみましょう。(パーミッションも)
秘密鍵と公開鍵のペアを生成
→公開鍵をログインしたい先の~/.ssh/autorized_keys
に追記
→秘密鍵を指定してssh接続
という流れは一般的なSSH公開鍵認証方式です。
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
0
以下のコマンドでssh設定を確認します。
$ vagrant ssh-config
IdentityFileの項目が秘密鍵のファイルになりますので、以下のコマンドでパスワードなしに設定します。
$ ssh-keygen -f {IdentityFile項目のファイル名} -p
Enter old passphrase: {現在のパスワードを入力}
Key has comment '{IdentityFile項目のファイル名}'
Enter new passphrase (empty for no passphrase): {空欄のままEnter}
Enter same passphrase again: {空欄のままEnter}
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.34%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
2016/06/06 13:10
vagrant up時に~/.ssh/autorized_keysは自動生成されないのでしょうか?
加えてもう1点、秘密鍵の場所はIdentityFileで指定されている箇所にあるとは思いますが、vagrant ssh接続するゲストPCへの公開鍵は通常どこに生成されるのでしょうか?(vagrant up時に秘密鍵、公開鍵ともにが生成される?)
2016/06/06 13:47 編集
一度VMを破棄して再度立ち上げてみると良いかもしれません。
(代わりにssh-keygenコマンドを使って秘密鍵から公開鍵を生成しても良いですし、自分で秘密鍵と公開鍵を作りなおしても良いです。)
秘密鍵と公開鍵は初回vagrant up時に生成されます。
公開鍵はゲスト側の~/.ssh/autorized_keysに追記されます。
2016/06/06 14:42 編集
ホスト側で~/.ssh/authorized_keysを探してました(よくよく考えたらsshする側に公開鍵は必要ないですよね)。ゲスト側(VM側)にはそもそも~/.ssh/(~ = /home/vagrant)が存在していません。ちなみにvagrant destroyしても.sshは作成されませんでした。
ゲスト側の公開鍵の場所をホスト側で教えて上げる必要はあるのでしょうか?(例えばVagrantfileに記述するとか)
また、ゲスト側に~/.ssh/autorized_keysが作成されなかったのはどんな原因があるのでしょうか?(vagrantが正しくインストールされなかった?)
2016/06/06 15:03
通常その必要はありません。
生成されなかった原因についてはちょっと特定難しいですね。
差し支えなければVagrantfileとvagrantのバージョン、vagrant up時のコンソールについて記載してもらえますか。
2016/06/06 18:42 編集
2016/06/06 18:45
2016/06/07 14:19 編集
ホーム直下をsynced_folderに指定するのはダメです。(.sshフォルダはホーム直下に作られるので)
例えば以下のように指定してあげてください。(hogeフォルダは自動で作られます)
config.vm.synced_folder "./", "/home/vagrant/hoge"
それとコードブロックはコメント欄では効かないようなので、質問に追記する形でお願いします。履歴も残りますので。
2016/06/08 23:54 編集
そのディレクトリをsynce_folderに指定するのはダメというのは,つまり,通常authorized_keysはゲスト側の/home/vagrant/.ssh/authorized_keysに作成されるので,そのディレクトリを指定してsynce_folderでホスト側のディレクトリと同期してしまうと結果的にauthorized_keysを削除(上書きされるといったほうがいいのか)している,ということでしょうか?
2016/06/09 00:04
2016/06/09 00:33
また機会がございましたら回答お願い致します.