read

Docker를 설치 하면서 알게 된 Vagrant

vagrant 명령어 탐색 경로

  • 자신의 디렉토리 -> 조상 디렉토리

LOOKUP PATH

When you run any vagrant command, Vagrant climbs up the directory tree looking for the first Vagrantfile it can find, starting first in the current directory. So if you run vagrant in /home/mitchellh/projects/foo, it will search the following paths in order for a Vagrantfile, until it finds one:

       /home/mitchellh/projects/foo/Vagrantfile
       /home/mitchellh/projects/Vagrantfile
       /home/mitchellh/Vagrantfile
       /home/Vagrantfile
       /Vagrantfile

This feature lets you run vagrant from any directory in your project.

You can change the starting directory where Vagrant looks for a Vagrantfile by setting the VAGRANT_CWD environmental variable to some other path.

참조 사이트 1

SSH 키 쌍(private-public)

  • VAGRANT_HOME 밑에 insecure-private-key와 VM의 vagrant 유저 /home/vagrant/.ssh/authorized_keys
  • Episod
    • gfstest2 VM의 vagrantfile 변경으로 master vm 생성(변경된 vagrant 파일에 config.vm.define “master” do |master| 정의 기존 default VM)
    • 기존 VM(default)과 deassosiated 됨 —> virtual box VM uuid(C:\Users\SDS\VirtualBox VMs\gfstest2\gfstest2.vbox)와 vagrant 의 id(D:\vagrant\two.vagrant\machines\master\virtualbox\id)를 일치시겨 vagrantfile과 기존 default VM assosiate
    • VM 생성 삭제 와중에 private key인 insecure-private-key 새로 생성으로 SSH 키 쌍 불일치 발생
  • SSH 접근 시 insecure key 쌍 보다는 별도의 키를 생성/사용 해야 보다 안전(예: AWS, EFSS 등 )

“vagrant” User
By default, Vagrant expects a “vagrant” user to SSH into the machine as. This user should be setup with the insecure keypair that Vagrant uses as a default to attempt to SSH. Also, even though Vagrant uses key-based authentication by default, it is a general convention to set the password for the “vagrant” user to “vagrant”. This lets people login as that user manually if they need to.

To configure SSH access with the insecure keypair, place the public key into the ~/.ssh/authorized_keys file for the “vagrant” user. Note that OpenSSH is very picky about file permissions. Therefore, make sure that ~/.ssh has 0700 permissions and the authorized keys file has 0600 permissions.

When Vagrant boots a box and detects the insecure keypair, it will automatically replace it with a randomly generated keypair for additional security while the box is running.

Insecure Keypair

These keys are the “insecure” public/private keypair we offer to base box creators for use in their base boxes so that vagrant installations can automatically SSH into the boxes.

If you’re working with a team or company or with a custom box and you want more secure SSH, you should create your own keypair and configure the private key in the Vagrantfile with config.ssh.private_key_path

참조 사이트 2

vagrantfile 내용 실행

  • VM 이미지 : 최초 vagrant up 사용시 생성, 로컬 box에 이미지가 없는 경우 자동 다운로드 하며 이후 생성된 이미지 사용
  • vagrant up 실행 시마다 vagrantfile 의 셋팅(hostname, ip, cpu, port forwar 등) 내용과 shell script 수행 함

Lessons & Learned

  • 아무리 급해도 바늘 허리 꿰어 못 쓴다. → 사용 전 충분한 선행 학습 필요. 기초 Documentaion 학습

Vagrant Documentation

Blog Logo

igotoo


Published

Image

igotoo

IT 관련 기술 공부/기록용 블로그

Back to Overview