I'm getting started with Vagrant.
I'm trying to connect to Scotch Box with MySQL Workbench.
First I did succeed to connect to mysql with a PHP script inside the box, but I can't do it with MySQL Workbench.
Here is my Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.network "private_network", ip: "192.168.33.10"
config.vm.network "forwarded_port", guest: 3306, host: 3306
config.vm.hostname = "scotchbox"
config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
I've got the error message: "Could not connect the SSH Tunnel"
I've edited the file "/etc/mysql/my.cnf" to bind-address = 0.0.0.0
I'm on Windows 10
Thank you very much for helping me, I don't know what's wrong, everything I already read online and tried didn't worked.
I found where was my issue. I wasn't using the right SSH key file...
To find the the location of your key file:
-> Execute vagrant ssh-config in your Vagrant directory.
So my config for this scotch-box:
SSH Hostname: 192.168.33.10
SSH Username: vagrant
SSH Password: vagrant
SSH Key File: your-path-here
MySQL Hostname: 127.0.0.1
MySQL Server Port: 3306
Username: root
Password: root
For developers using puphpet
Choose Standard TCP/IP over SSH
Parameters (Mostly default values since I did not change it)
SSH Hostname: 192.168.56.101
SSH Username: vagrant
SSH Password: vagrant
SSH Key File: C:\cygwin64\home\(username)\puphpet\sutfva\puphpet\files\dot\ssh\id_rsa
MySQL Hostname: 127.0.0.1
MySQl Server Port: 3306
Username: root
Password: 123
Related
I have vagrant vm centos 7 running ssh on XXXX port (not default 22)
How can I connect to XXXX port using "vagrant ssh" command
I tried this but did not work.
config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh" , disabled: true
config.vm.network :forwarded_port, guest: xxxx, host: 2223, auto_correct: true
config.ssh.port = 2223
It might depend on the provider you're using, but setting config.ssh.guest_port=XXXX along with a port forwarding does the trick for me when using Virtualbox as a provider.
With that you shouldn't even have to specify config.ssh.port, as Vagrant will detect the port forwarding settings automatically.
See also vagrantfile documentation
Wandering what configuration #su_li used exactly, I tried different possibilities and the following code came to work as expected :
config.vm.network "forwarded_port", guest: 54321, host: 2222, id: "ssh"
config.ssh.guest_port = 54321
The guest OS (the VM) runs sshd on port 54321.
The host OS will send ssh request to port 2222.
With this configuration, all requests to port 2222 on the host side will be forwarded to port 54321 on the guest side.
And all responses from port 54321 from the guest side will be forwarded to port 2222 on the host side.
Note that the id: "ssh" part is necessary if you want to override the default ssh port forwarding configuration.
I have a Vagrant file looks like the one below.
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.ssh.host = "0.0.0.0"
config.ssh.password = "foo"
end
I want to access to my box via an SSH tool. When I try to connect it with a command like ssh vagrant#0.0.0.0:22, I encounter with an error that says ssh: Could not resolve hostname 0.0.0.0:22: nodename nor servname provided, or not known
.
According to Vagrant documents, it is possible to set a hostname and password by setting host and password properties of ssh object of the config.
I am sure that the current Vagrant box is up and running. I can even access apache via port 80 if I set forwarded_port attribute.
config.vm.network "forwarded_port", guest: 80, host: 80, host_ip: "127.0.0.1"
That's not valid ssh command line syntax. Use the -p command line parameter to specify the port. For example:
This works: ssh -p 2222 -i /path/to/identity/file vagrant#localhost
This does not: ssh -i /path/to/identity/file vagrant#localhost:2222
Note: port 22 is the default port for ssh, if you're attempting to connect to port 22 then you don't have to specify the port.
I installed vagrant box in mac system. In that vagrant box I configured apache and it is running. I am trying to access it from my machine, but I am not able to access.
*Vagrant.configure(2) do |config|
config.vm.box = "oar-team/debian8"
config.vm.network "forwarded_port", guest: 80, host: 8000
config.vm.synced_folder "./", "/vagrant", id: "vagrant-root",
owner: "vagrant",
group: "www-data",
mount_options: ["dmode=777,fmode=777"]
config.ssh.forward_agent = true
config.vm.define "127.0.0.1"
end*
Above one is my vagrant file. I am vagrant up and it is running the vagrant box.
I found the answer finally. After running the vagrant up
My site has some set of scripts to run. To run those scripts I need to run
vagrant provision. then only it is running the site.
I like using the "vagrant" user to provision my Vagrant VM using Ansible. But once I get the box set up, I'd like to be able to log in to it using either the vagrant account or my personal account "smith." However, when I log in as smith, I'd like to not be prompted for my password. Is there a way to set this up? I've created the smith account on the Vagrant box and I've copied my public and private SSH keys from my .ssh directory on the OS X management host to user smith's .ssh directory on the VM. Right now I can log in by doing "ssh smith#192.168.2.100" but I get prompted for my password. Is there any way to configure both machines so that I can log in using my SSH keys?
Thanks.
# Vagrantfile
DEV_GID = 1001
Vagrant.configure(2) do |config|
config.vm.box = "debian/jessie64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 443, host: 8443
config.vm.network "private_network", ip: "192.168.2.100"
config.vm.synced_folder "website/", "/srv/http/example.com",
owner: "root",
group: DEV_GID,
mount_options: ["dmode=775"]
config.vm.provision "shell", path: "provision.sh"
end
Instead of copying all the files in the .ssh directory, you should create the file
/home/smith/.ssh/authorized_keys
(or wherever your home folder in the vagrant box is) in your vagrand box and copy-paste your id_rsa.pub inside this file. By copying-paste I mean open id_rsa.pub with an editor, copy all of it, and paste it in .ssh/authorized_keys file. You should also change the directory permissions to 0600.
Your private id_rsa file is not needed in the vagrant box, it is only needed in the host you use to ssh into that vagrant box.
Given the following Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "centos_64"
config.vm.host_name = 'web'
config.vm.network "private_network", ip: "192.168.50.4"
end
Why can't I ssh onto the guest from the host?
$ ssh vagrant#web -p 22
ssh: connect to host web port 22: Connection timed out
But using vagrant ssh works:
$ vagrant ssh
Last login: Tue Mar 4 21:29:24 2014 from 10.0.2.2
[vagrant#web ~]$
As expected, I can ping the IP Address from the guest. But I can't ping from the host.
I'm confused as to why it's happening since my setup does not look different from this configuration.
First, vagrant ssh uses the forwarded port and not the private network address. You can get the configuration with vagrant ssh-config.
Is the name "web" really resolving to the specified IP? Can you ping/connect using the IP instead of the name? If not, verify that you don't have other VMs or external networks with the same address. Also some VPN products mess up the routing.
I managed to change the ssh address with
config.ssh.host = '192.168.0.13'
config.ssh.port = '22'`
as mentioned in https://superuser.com/questions/920536/how-to-change-the-ssh-host-in-vagrantfile/921728#921728
Just because the guest host has a defined hostname does not mean that the host machine will resolve its ip.
You should be able to ssh into the machine by doing:
ssh vagrant#192.168.50.4 <==== vagrant is the default password,
but you can avoid typing it alway by doing:
ssh-copy-id vagrant#192.168.50.4
here is my configuration and it's working for me
config.vm.box = "ubuntu/xenial64"
config.vm.network "private_network", ip: "192.168.88.88"
config.ssh.host = "192.168.88.88"