Laravel Envoy with Vagrant: Permission denied (publickey) - laravel

Trying to use Envoy via Vagrant (Homestead) to deploy to a server on EC2 that I would normally use a .PEM file when I SSH into it.
When using: #servers(['web' => 'ec2-user#myserver.com']) in my Envoy.blade.php
I get: Permission denied (publickey).
Any help would be huge!

Answer is here: https://stackoverflow.com/a/32088143/13346162
You need to pass the -A (as per the man page it - Enables forwarding of the authentication agent connection. This can also be specified on a per-host basis in a configuration file) in you ssh string.
You will also need add your ssh key for agent forwarding (on the machine which can access the git remote which I assume be your localhost)
ssh-add -K ~/.ssh/your_private_key
Something like this
#servers(['web' => '-A user#domain.com'])
#task('deploy')
cd /path/to/site
git status
#endtask
Git remote commands should now work.

Related

Adding ssh-keys in windows for private git

might be a dumb question.... but where do we add the ssh keys of the workstation to the git server both being purely on windows 2012 R2... ..Without the use of github
i had created a remote in the git server repo as
git remote add origin edscs-npe\bzky7x#IP:/c/temp/repo.git
In the workstation i am trying to clone the link as ..
$ git clone edscs-npe\bzky7x#IP:/c/temp/repo.git
Cloning into 'repo'...
ssh: connect to host "IP" port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Now the problem I think here is on the authentication between both the workstation and the git server... where do I add the ssh keys of the workstation to the git server both being windows machine...
Much help would be appreciated
Now the problem i think here is on the authentication between both the workstation and the git server...
To test this, just ssh from the workstation to the server. If it prompts you for a password and you are able to type it in and connect, then yes, you need to set up your ssh keys. If not, then there is more setup you need to do on the server end that is outside the scope of this question.
First, on your workstation you need to set up your public/private keys. You can do this with a command like:
ssh-keygen -t rsa
After hitting enter to accept the defaults, you should get some files in your ~/.ssh folder.
Now you need to add your public key to the authorized_keys on the server account you use for your git operations (You will need to enter a password for this operation)
cat ~/.ssh/id_rsa.pub | ssh user#server 'cat >> .ssh/authorized_keys'
You should be able to both interactively ssh into the server and use git to clone from the server.

Using git with SSH-key on Windows

I am connecting to my virtual machine with ssh like this:
ssh -i keyfile.key user#server.com
I have created a git repository on the server which I want to push to, but I do nott know how I should use the keyfile.key with git.
I am supposed to execute the command:
git push live master
But I getting the error "permission denied (publickey)", so how do I specify the key? I am on Windows 8.
You need to:
use a, ~/.ssh/config (check where %HOME% is set, since you are on Windows).
The config file would look like (replace <hostkey> by any string you want)
Host <hostkey>
HostName myserver
User user
IdentityFile C:\path\to\.ssh\keyfile.key
IdentitiesOnly yes
change your remote url to one using the config Host key
git rmeote set-url list <hostkey>:myrepo

use ssh private key from host in vagrant guest

I want to clone a bunch of private git repositories while provisioning a vagrant box. According to this article this should be possible using config.ssh.forward_agent = true. However, when trying to connect to github via something like ssh -T git#github.com -o StrictHostKeyChecking=no it fails with the following error:
Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.
Permission denied (publickey).
I cut my configuration down to the simplest possible configuration. You can find it here: https://gist.github.com/TomTasche/31f7c45fcffc2997d43a
When I do "vagrant ssh" and try the same again, a similar error occurs:
Cloning into 'private-repositories'...
Warning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Edit: the configuration linked above does work on a host running Ubuntu, but does neither work on a Mac host, nor on a Windows host. My goal is to have a configuration that works on all these three hosts.
Please check whether your host system has ssh-agent forwarding enabled. You can do so for example by adding this block to your ~/.ssh/config file:
Host *
ForwardAgent yes
If this is enabled vagrant ssh (and also vagrant provision) should be able to forward your key to the guest machine.
You also might want to check using ssh-add -l whether your ssh-agent does know about your SSH-key. If it is in the list and you have agent-forwarding activated you should have a success. Otherwise you can add the key to your ssh-agent by running ssh-add <path to your key file>.
It sounds like you may be hitting this particular bug:
https://github.com/mitchellh/vagrant/issues/1735
(Despite it being "closed" it's actually not fixed)
On Windows, SSH Forwarding in Vagrant does not work properly by default (because of a bug in net-ssh).
However, there is a workaround or simple hack. You can auto-copy your local SSH key to the Vagrant VM via a simple provisioning script in your VagrantFile. Here's an example:
https://github.com/mitchellh/vagrant/issues/1735#issuecomment-25640783
Tom,
What you're doing is fairly generic in nature and I don't think is Vagrant specific.
Try some of the following to track down the issue:
edit your /etc/ssh/sshd_config
Set LogLevel debug
Restart the sshd service sudo service sshd restart or /etc/init.d/sshd restart
tail -f /var/log/authlog -- note, the file may be something else like /var/log/authd.log or /var/log/secure or something.
Watch what happens when you connect. It should give you some indication of why it's failing.
Again sorry, I'm not that familiar with Vagrant but I'm wondering if the provisioning script is running as another user, in which case the agent forwarding may not work as expected?

Laravel "envoy run" command not working with ssh key

I am running following command in a laravel project folder and getting following error.
rakib$ envoy run list --env=production
[ubuntu#54.187.123.4]: Permission denied (publickey).
But I can successfully ssh using following command:
ssh -i ~/.ssh/sw-new.pem ubuntu#54.187.123.4
My ~/.ssh/config file content looks like:
Host 54.187.123.4
IdentityFile ~/.ssh/sw-new.pem
Can anyone suggest me what is the possible reason of getting "Permission denied" error?
It's possible that envoy is using the wrong user when attempting to ssh into the production server. Specify a user in your ~/.ssh/config file:
Host 54.187.123.4
IdentityFile ~/.ssh/sw-new.pem
User ubuntu
That should work.
It is possible as answer above for AWS user when you attempting to ssh in production mode, after define "config" file as "~/.ssh/config":
Host ec2-52-29-45-15.eu-central-2.compute.amazonaws.com
IdentityFile /home/tux/Desktop/ssh/masterpro.pem
User ubuntu

SSH error on push to an existing project Permission denied (publickey)

Made all necessary steps to use the GitLab, these settings are:
Created a rsa as described in this link
Copied the code generated in {my key}.pub and added this code in GitLab
In my existent repository added to url with command git remote add gitlab git#gitlab.com:ridermansb/breezenhibernateproblem.git
I tried to make the push git push -u gitlab master
My .ssh/config
Host gitlab.com
HostName gitlab.com
IdentityFile C:\Users\Riderman\.ssh\gitlab_rsa
IdentitiesOnly yes
Error below:
Warning: Permanently added 'gitlab.com,54.243.197.170' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I made a video showing all the steps: http://www.screenr.com/euVH
What am I doing wrong?
After seeing your screencast, I see that you don't have a %HOME%\.ssh\config file.
This is important because:
by default, ssh will look for the public/private key in %HOME%\.ssh\id_rsa(.pub)
With an scp-like syntax (git#gitlab.com:yourRepo, with the ':' as separator), ssh could look in a .ssh/config file for the location of the actual public/private key, using gitlab.com as an entry in said config file.
Add %HOME%\.ssh\config with:
Host gitlab.com
HostName gitlab.com
IdentityFile C:\path\to\.ssh\gitlab_rsa
IdentitiesOnly yes
and your git push -u gitlab master will work.
It turned out it was also about setting HOME correctly:
%HOME% was not correct.
I configured the variable %HOME% to point to %USERPROFILE% locally and it worked
Mysygit does set HOME, but if you are using git outside of a git-cmd session, then it is your responsibility to set HOME correctly.

Resources