2

I recently start to use Vagrant (and recently move to Ubuntu from Windows too). My goal to understand fundamentals of vagrant ssh.

So, I'm trying to understand what vagrant ssh actually does. I've read What does vagrant ssh actually do?, but I haven't understood anything.

I'll try to explain with an example:

  1. The first time, I connect into the vagrant machine by ssh vagrant@192.168.0.x and typing the password.

  2. Next, I configure the keypair and connect into guest by ssh vagrant@192.168.0.x without typing password.

  3. Next, I try to understand how vagrant implements SSH into its own guest machine:

    • In /etc/ssh/sshd_config, I set PasswordAuthentication no, but vagrant ssh still works
    • Delete insecure_private_key placed in ~/.vagrant.d on the host machine, but vagrant restores it and vagrant ssh still works.
    • Remove openssh-server in the vagrant machine and now vagrant ssh really doesn't work :)

Please could anybody in plain English explain me how vagrant implements vagrant ssh?


Update: Vagrant Docs: SSH explains actually what I need.

Community
  • 1
  • 1
Timur Fayzrakhmanov
  • 17,967
  • 20
  • 64
  • 95

1 Answers1

0

May be I didn't get the point of your question, but I'll try to explain you the main differences between vagrant ssh and ssh.

vagrant ssh is actually the same as a normal ssh, but there are several differences between them:

  • port which ssh-client tries to access;
  • private key that ssh-client uses for authentication;
  • hosts-key is switched off for vagrant so you will not get initial message "The host is unknown";
  • other minor differences.

If you know the port where vagrant runs, and know where is the private key that vagrant uses, you can use ssh instead of vagrant ssh.

Igor Chubin
  • 61,765
  • 13
  • 122
  • 144
  • Вы случаем не русский?) May me I don't understand something, but is the ssh-client should use public key instead private key? As far as I know, private key are used on the machine we connect to, hence server and public key are used on the machine we connect from, hence client. In my mind `vagrant ssh` must use a public key. This moment confuse me.. – Timur Fayzrakhmanov Jan 07 '14 at 21:42
  • The vargrant ssh wrapper uses a predefined ssh key (private). The virtual machine you are connecting to has a corresponding public key already installed in the vagrant users authorised keys file. So, when you use `vagrant ssh`, it doesn't require the password. It is also doing a bunch of other things as listed in this answer. The public key will be found in the `~/.ssh/authorized_keys` file – S.Spencer Jan 07 '14 at 22:08
  • @TimurFayzrakhmanov: Я русский, но тогда надо идти на другой сайт, здесь за такие шуточки сразу забивают. In the both cases are used private keys, the authentication procedure is the same; the point is that vargrant uses its own keys. – Igor Chubin Jan 08 '14 at 09:04
  • Интересно!)) Thank you Igor! I've got it, the problem was poor ssh knowledge. – Timur Fayzrakhmanov Jan 08 '14 at 12:01