Vagrant ssh key pair

In this tutorial, I’m setup vagrant ssh key pair.  Generating ssh key with vagrant_rsa is private key and vagrant_rsa.pub is a public key. Log in to Virtual Machine without the password. Vagrant the essential for DevOps Roles.

The structures folder for the vagrant project as below:

/home/huupv/project
/home/huupv/project/keys/.ssh

The first, To create a vagrant ssh key

Using the ssh-keygen command to create the private key and public key for a vagrant.

ssh-keygen

The output private key and public key files in “/home/huupv/project/keys/.ssh” folder as below:

vagrant_rsa vagrant_rsa.pub

To configure vagrant ssh key in Vagrantfile

To add the lines in Vagrantfile file as below:

Vagrant.configure("2") do |config|
config.vm.box = "centos/6"
config.ssh.insert_key = false
config.vm.boot_timeout = 800
config.ssh.private_key_path = ["keys/.ssh/vagrant_rsa", "~/.vagrant.d/insecure_private_key"]
config.vm.provision "file", source: "keys/.ssh/vagrant_rsa.pub", destination: "~/.ssh/authorized_keys"
end
  • ~/.vagrant.d/insecure_private_key: You should append this default key. The use config.ssh.insert_key = false to Vagrant not generate a random key.
  • config.ssh.private_key_path: Changing Insecure Key To My Own Key On Vagrant box.

Conclusion

Finishing, We are customizing vagrant ssh key with Private/Public key. What you need to Private key saves in the host and Public key copy authorized_keys into a vagrant box for Virtual Machine. Reference to configure vagrant ssh of the vagrant main site.

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.