I have created a new vagrant box using
vagrant init ubuntu/trusty64
vagrant up
I want to ssh into this without using "vagrant ssh"
ifconfig of the box machine gave me
eth0 Link encap:Ethernet HWaddr 08:00:27:ca:3e:f9
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:feca:3ef9/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:254 errors:0 dropped:0 overruns:0 frame:0
TX packets:187 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:26220 (26.2 KB) TX bytes:22208 (22.2 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
I tried
ssh [email protected]
"who" on box gave
vagrant pts/0 Jan 5 14:46 (10.0.2.2)
So I tried
ssh [email protected]
But neither worked!
Neither ping works on this ips
First, you can't access ip's behind an NAT gateway. You need to access the server using the IP address of the NAT gateway and the forwarded port which is 2222 by default for ssh in vagrant. You also need to tell ssh that it should use vagrant's insecure private key:
ssh -i ~/.vagrant.d/insecure_private_key -p 2222 vagrant@localhost
The vagrant ssh
command is meant to hide this complexity.
If you've launched multiple vagrant boxes at the same time or you've explicitly chosen a port different from 2222, you need to use the port which is actually in use. You can find that out using:
vagrant ssh-config
For permanently creating a host alias, you can add an entry to your ~/.ssh/config that looks like:
Host my-vagrant-box User vagrant HostName localhost Port 2222 IdentityFile /Users/atesgoral/Sandbox/my-vagrant-box/.vagrant/machines/default/virtualbox/private_key IdentitiesOnly yes
Then you can simply do:
ssh my-vagrant-box
To determine the host port that's mapped to the SSH port on the guest (the Vagrant box):
vagrant port --guest 22
In this repo, you can find a shell script that you can run inside the directory with the Vagrantfile. It will generate a host entry that can be appended to ~/.ssh/config:
./ssh-config.sh >> ~/.ssh/config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With