Last active
January 4, 2016 00:09
-
-
Save kazuph/8539765 to your computer and use it in GitHub Desktop.
Vagrantでvagrantのデフォの秘密鍵じゃなくて自分のいつもの秘密鍵を使えるようにするシェルスクリプト ref: http://qiita.com/kazuph/items/0d9d723b36720b9bd6ed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Host vagrant | |
HostName 127.0.0.1 | |
User vagrant | |
Port 2222 # ← これは変わる可能性がある |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Host vagrant | |
HostName 127.0.0.1 | |
User vagrant | |
Port 2222 # ← これは変わる可能性がある |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
echo べいぐらんとに自分のいつもつかってる公開鍵をつっこむよ! | |
echo べいぐらんが立ち上がってないなら起動 | |
[ -z "`vagrant status | grep running`" ] && echo 立ち上がってないので起動させるよ! && vagrant up | |
vagrant ssh -- cat .ssh/authorized_keys > authorized_keys | |
[ `cat authorized_keys | wc -l` == 3 ] && echo すでに設定してるみたいなので終了 && exit 1 | |
echo 自分の秘密鍵から公開鍵を生成する(パスフレーズを入力してください) | |
ssh-keygen -y -f $HOME/.ssh/id_rsa >> authorized_keys | |
echo べいぐらんとに入るためのssh-configを生成 | |
vagrant ssh-config > ssh_config | |
echo 公開鍵をvagrantユーザーのディレクトリに設置 | |
scp -F ssh_config authorized_keys default:.ssh/authorized_keys | |
cat <<_EOF_ | |
構築DONE! | |
------------------------------ | |
$ cat $HOME/.ssh/config | |
Host vagrant | |
HostName 127.0.0.1 | |
User vagrant | |
Port 2222 # ※Port番号は適宜変更の必要あり | |
上記を記述すると | |
$ ssh vagrant | |
で仮想環境に入れるようになるよ! | |
そんじゃーね☆ | |
------------------------------ | |
_EOF_ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment