Vagrant Laravel Homestead SSH authentication failed - laravel

On vagrant provision of Laravel Homestead I get SSH authentication failed! and the Vagrant instance won't run.
SSH authentication failed! This is typically caused by the public/private
keypair for the SSH user not being properly set on the guest VM.
This seems to have started from the error when I first provisioned homestead:
==> default: tee: /home/vagrant/.ssh/authorized_keys: No such file or directory

Having the default folder mapped to /home/vagrant in the Homestead.yaml was causing the issue.
This was my folders setting:
folders:
- map: /Users/username/www
to: /home/vagrant
Adding a folder deep fixed the problem:
folders:
- map: /Users/username/www/homestead
to: /home/vagrant/www
Working :)
Perhaps someone can elaborate as to why this happens?

did you set your ssh key to the correct path?
authorize: <SSH KEY PATH TO YOUR PRIVATE KEY>
keys:
- <SSH KEY PATH TO YOUR PRIVATE KEY>
if you didnt set them right it cant connect
EDIT
You should not match your project to the root folder, because it matches the Homestead repository to your /home/vagrant/ path

Related

Laravel Homestead and vagrant don't create the folder inside vagrant box

I use Laravel Homestead for one year it all was good before I had decided change php version.
Firstly I update vagrant. Secondly I executed all commands from updating guide
vagrant destroy
git fetch
git pull origin release
vagrant box update
vagrant up
After vagrant up I saw that my databases were not created and my folder was not mounted (http://joxi.ru/Vm66DpgF410M5m).
I tried to connet via vagrant ssh, but there is not folder "code"
My Homestead.yaml
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /home/ubuntu/PhpstormProjects/fntr
to: /home/vagrant/code/fntr
schedule: true
sites:
- map: fntr.test
to: /home/vagrant/code/fntr/public
php: "7.4"
databases:
- homestead
- testing
- imports
- prod_copy
I tried use vagrant destroy && vagrant up. I also tried vagrant reload --provision.
I have found the same issues in google and github, but this advices (http://joxi.ru/52a53oGUEBZMZ2 and other) did not help me.
I have the latest versions of vagrant and homestead.
I think that schedule: true not belongs to folders but to sites, try to remove it and run vagrant reload --provision.
I have found solution. But I am not sure that it is solution exactly.
I just reinstalled laravel homestead. Yes, I deleted homestead folder and went via instalation tutorial again.
Then I pasted my old Homestead.yaml and init vagrant box again.
Note if you want to try this method do not forget copy all of your after.sh, homestead.yaml and other files which can be lost

Vagrant/Homestead ssh Identity file not accessible: no such file or directory

I'm having an issue when trying to run
vagrant ssh
I keep getting
Warning: Identity file C:/Users/Firstnamenot accessible: No such file or directory.
bash: Lastname/Homestead/.vagrant/machines/homestead-7/virtualbox/private_key: No such file or directory
I normally try to stick to one word usernames, but work set this computer so I'm stuck with that space there. At least I'm guessing that the command is seeing the space and thinking that's the end of the directory path. Is there a way to hard code this path, or a way around it?
Edit:
I'm running on windows
and my homestead.yaml is:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Projects
to: /home/vagrant/Projects
sites:
- map: homestead.app
to: /home/vagrant/Projects/Laravel/public
databases:
- homestead
I had to install homestead again in a different directory, to do so I followed
Change VAGRANT_HOME directory on windows
setx VAGRANT_HOME="X:\your\path"
Then as indicated at the manual I created the box again
vagrant box add laravel/homestead
I also created a Homestead dir outside my users folder and follow the manual:
git clone https://github.com/laravel/homestead.git Homestead
git chechout vX.Y.Z
bash init.sh
So if you can make directories outside your user directory, this should work.

Homestead Running, SSH Works, But HTTP Connections Time Out

I'm having an issue with a homestead configuration that was previously running correctly. After reading some bad advice online regarding a separate issue, I accidentally wiped out my homestead.yaml by re-running init.bat, and have recreated the homestead config from memory the best I can. Most everything seems to be working - I can start the box successfully, and I can connect via SSH. My web root is mapped to the box correctly, as I can see all my project files on the box where I chose to map them. When I try to access the site via http (through the name I've mapped it to), I get a timeout. I've ensured that my hosts file has the update from myapp.app to 192.168.10.10, the same IP as in my homestead.yaml file. I will note, however, that when I ping 192.168.10.10 from the terminal, I also get a timeout.
Here's my Homestead.yaml:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: C:/Users/MyUsername/.ssh/id_rsa.pub
keys:
- C:/Users/MyUsername/.ssh/id_rsa
folders:
- map: C:/Users/MyUsername/Projects/myapp_laravel
to: /home/vagrant/code/myapp
sites:
- map: myapp.app
to: /home/vagrant/code/myapp/public
databases:
- homestead
Here's my hosts file:
192.168.10.10 myapp.app
I'll also note that I can successfully access my app via: http://localhost:8000/
I have also restarted my host machine since updating the hosts file, and reprovisioned the box.
Restarting the host machine again solved this for me.

Laravel Homestead (Windows)

Today I have been trying to install the Laravel library together with Laravel Homestead.. But I can't seem to get it working.
The first thing, Laravel documentation tells you to do: composer global require "laravel/homestead=~2.0", but it didn't work.
So I searched the internet some and found: composer global require "laravel/homestead=~3.0", which actually worked.
But now when I try to run the homestead command in my command line, it gives me this: http://prntscr.com/9perhj, that's the only thing it's giving me.
I have added the directory to my path variable.
I hope someone can help me.
Thanks in advance!
Homestead itself command will return this expected screen. You would need to pass the command you want to run.
At first, run homestead init so that it will create the Homestead.yaml configuration file
This is an old question but I thought I'd put up my answer since it took me multiple tries to get it right and I documented the process while I was doing it so I wouldn't have such a hard time in the future.
Note: You should NOT have NginX, PHP, MySQL, etc. installed on your machine. The Vagrant Homestead virtual box provides all of this functionality. I had some issues where I had NginX and MySQL on my machine and it was connecting to my local machine's MySQL when it should be connecting to the virtual box's MySQL.
Without further ado, this is how I set it up for my Windows 7 machine:
Prerequisites:
VirtualBox:
https://www.virtualbox.org/wiki/Downloads
Vagrant:
https://www.vagrantup.com/downloads.html
Git Bash: A terminal that feels like a Linux terminal. You can do everything you do on an Ubuntu server in Windows.
https://git-scm.com/downloads
Putty: Telnet client that I used for connecting to my VirtualBox Homestead server
http://www.putty.org/
create project folder
open terminal in project folder (something like E:\Projects\Vagrant)
type 'vagrant box add laravel/homestead'
type 'git clone https://github.com/laravel/homestead.git Homestead'
This installs Homestead in the designated project folder.
type 'cd Homestead'
type 'bash init.sh' OR 'init.bat'
This creates a folder in:
C:\Users\USERNAME\.homestead
which has the file:
Homestead.yaml
If you open the Homestead.yaml file it should look something like this:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Code
to: /home/vagrant/Code
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
databases:
- homestead
The '~/' folder is the equivalent of:
C:\Users\USERNAME\
Change:
folders:
- map: ~/Code
to: /home/vagrant/Code
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
To:
folders:
- map: E:/Projects/Vagrant/Homestead
to: /home/vagrant/Homestead
sites:
- map: WEBSITE.dev
to: /home/vagrant/Homestead/Laravel/public
goto C:\Windows\System32\drivers\etc
open the file 'hosts' in a text editor
add '192.168.10.10 WEBSITE.dev' (the IP address should match the IP address in the Homestead.yaml file)
open a terminal in E:/Projects/Vagrant/Homestead folder
type 'ssh-keygen -t rsa -C "USERNAME#gmail.com"'
This creates the folder C:\Users\USERNAME.ssh and sets up your SSH Key
type 'vagrant init laravel/homestead'
type 'vagrant up'
You should see Homestead running in VirtualBox
You can use 'vagrant destroy' to kill it when done
Use putty.exe to log in to Homestead
IP Address: 127.0.0.1
Port: 2222
login as: vagrant
password: vagrant
Everything is now ready

How to setup Laravel Homestead server to run locally without being on a network/internet?

Previously, I manually setup my own VM on VirtualBox and configured it so it would also work when I'm coding offline (no internet/not connected to a router). I did this using settings in the VirtualBox GUI and also in Apache on the VM.
Now I'm interested in learning nginx and I've decided to try and use Laravel's Homestead. The tutorials I'm looking at seem to have the assumption I will be accessing the Homestead VM across the network (even though of course it's on the same PC). What do I need to do to ensure the VM will be accessible when I'm offline (like when I'm coding on a plane or train)? I'd like to still be able to have access to the internet from the VM whenever I do get back on WiFi (ie. for apt-get, etc.).
(note: My host machine is running Windows 7 64-bit)
Download and install fresh copies of Vagrant and Virtualbox.
https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2.msi
http://dlc-cdn.sun.com/virtualbox/4.3.22/VirtualBox-4.3.22-98236-Win.exe
Also download laravel/homestead manually
https://vagrantcloud.com/laravel/boxes/homestead/versions/0.2.2/providers/virtualbox.box
to my downloads folder C:\Downloads\homestead-0-2-2.box
After Installing Virtualbox and Vagrant. Installed laravel/homestead by running the following command in git bash (you can download git bash here: http://git-scm.com/downloads).
vagrant box add laravel/homestead /c/downloads/homestead-0-2-2.box
Run this command inside C:\users\yourusername
git clone https://github.com/laravel/homestead.git Homestead
NB: This will create this folder: C:\Users\yourusername\Homestead
With some files.
Still in Git bash, cd into C:\Users\yourusername\Homestead and run this command:
bash init.sh
NB: this will create a folder C:\Users\yourusername\.homestead that contains Homestead.yaml and some other files
Then Generate an SSH key which you will need when you want to login to your VM by running this command:
ssh-keygen -t rsa -C "youremailaddress#youremail.com"
NB: This will ask some question simply hit enter or type yes and hit enter.
This will create your ssh key inside C:\Users\yourusername\.ssh
Then you need to configure homestead by editing for Nginx
C:\Users\digitlimit\Homestead\Homestead.yaml
You can right-click Homestead.yaml file then click open then choose to open with wordpad.
My Homestead.yaml looks this after editing:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /wamp/www
to: /home/vagrant/Code
sites:
- map: laravel.dev
to: /home/vagrant/Code/laravel/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
# blackfire:
# - id: foo
# token: bar
NB: To understand the mapping which is a process of sharing a folder between the host and the VM:
My laravel project is located at C:\wamp\www\laravel
This directory /home/vagrant/Code will be inside the VM after installation.
So what am telling VM is, whenever you see /home/vagrant/Code reference this folder C:\wamp\www\laravel
Also in this:
sites:
- map: laravel.dev
to: /home/vagrant/Code/laravel/public
What we are saying here is when i go to my browser and type http://laravel.dev display the content of /home/vagrant/Code/laravel/public which is actually pointing to C:\www\wamp\laravel\public
After editing Homestead.yaml file save your chnages
NB: Before we can use http://laravel.dev in the host web browser to view our laravel project, we need to add this the following to the hosts file located in
C:\Windows\System32\drivers\etc\hosts
Add this ip address under the list of other ip address listed if any:
192.168.10.10 laravel.dev
Finally, go back to your Git bash, ensure you are in
/c/Users/yourusername/homestead and type:
vagrant up
Wait for vagrant to complete its processes. Click yes when you see any dialog box asking for permission to create network adapter on your system
Any VM running on your development machine will be accessible when you're offline. Just make sure you setup your development machine's host file to have the VM's location set.
If you're following the Laravel Homestead Setup:
In scripts/homestead.rb, you'll have a line that has the IP Address of the VM.
# in scripts/homestead.rb
# Configure A Private Network IP
config.vm.network :private_network, ip: settings["ip"] ||= "192.168.10.10"
Add this IP address into to your hosts file. This is located usually in C:\Windows\System32\drivers\etc\hosts
#in hosts file
192.168.10.10 yourwebsite.dev

Resources