이 세상에 하나는 남기고 가자

이 세상에 하나는 남기고 가자

세상에 필요한 소스코드 한줄 남기고 가자

Vagrant Box Packaging 후 "Warning: Authentication failure. Retrying... " 오류가 발생할 경우 해결 방법

유영재

vagrant를 사용하면서 직접 box를 만들 경우가 자주 발생하지는 않는다. 하지만 환경 구성을 위해 간혹 작업을 하게되는데 작업 과정에 문제가 생기는 경우가 간혹 있다. 이번에 CentOS 7 환경을 구성하면서 vagrant로 테스트를 진행했었다. 최초 설치 상태로 box를 만들어두고 환경을 구성해보고 문제가 있으면 초기 box로 다시 구성하는 식으로 작업을 했다. 그런데 이번엔 작업을 하면서 이전에 발생하지 않았던 문제가 발생했다.

이전글 Vagrant BASE Box 만들기(CentOS 7)에서 설명했던 것처럼 box 생성 전에 분명 ssh 관련 처리를 해 주었음에도 불구하고 만들어진 box를 사용해서 vagrant up을 하게되면 아래와 같은 결과가 계속 나왔다(여러번 box를 다시 만들어 봤음에도 불구하고).

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos7-dev-1'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: dev7_default_1449141471748_10760
==> 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: 80 => 8080 (adapter 1)
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> 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: Warning: Connection timeout. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

ssh 인증에 실패하면서 계속 시도하다가 결국 그냥 종료되어 버린다. 사실 가상 머신이 종료된 것은 아니다. ssh로 직접 접속하면 접속은 된다. 이 문제가 발생한 것은 이전이지만 당장 다른 작업들이 급해서 그냥 아래의 방법을 통해 사용중이었다.

Vagrantfile 에 아래의 내용을 추가한다.

config.ssh.username = "vagrant"
config.ssh.password = "vagrant"

이 방법은 ssh key를 사용하지 않고 아이디/비밀번호를 입력하는 방식으로 ssh 접속하는 것이다. 사실 이렇게하면 문제는 해결된다. 어짜피 비밀번호에 대한 보안이 중요한 상황도 아니므로 그냥 사용해도 무방하다. 그런데 그냥 사용하기에는 찜찜했다. 특별히 권장하거나 일반적인 방법이 아닌데다가 기존에는 굳이 이렇게하지 않아도 잘 동작하고 있었기 때문이다.

그래서 오늘 많은 검색과 여러가지 방법을 시도한 끝에 해결 방법을 찾았다. 결론은 box 내부에서 처리하는 과정에 문제가 아니라 내 PC의 문제로 보인다. 해결 방법은 다음과 같다.

Vagrantfile 에 아래의 내용을 추가한다.

config.ssh.insert_key = false

아마도 내가 vagrant를 자주 변경하고 실험하는 사이에 뭔가 설정이 꼬인 것 같다. 이 옵션을 해결되는 것으로 볼 때 내 컴퓨터에 잘못된 키가 저장되어 있고 vagrant up 과정에서 가상 머신에 key를 변경해 버려서 위 문제가 발생했던 것으로 보인다.

config.ssh.insert_key는 메뉴얼에 아래와 같이 설명되어 있다.

config.ssh.insert_key - If true, Vagrant will automatically insert an keypair to use for SSH, replacing the default Vagrant's insecure key inside the machine > if detected. By default, this is true.

This only has an effect if you don't already use private keys for authentication or if you are relying on the default insecure key. If you don't have to take care about security in your project and want to keep using the default insecure key, set this to false.

검색을 하다보니 이 두가지 방법 외에도 여러가지 방법이 제안되는 것으로 보아 다른 문제로 인해 이런 현상이 나타나는 경우도 있는 것 같다. 어쨌든 위와 같은 문제를 겪는다면 제시한 2가지 방법도 한번 적용해 보면 도움이 될 것으로 생각한다.

comments powered by Disqus