Private Github Repositories with Envoy - deployment

Anybody has any problems deploying with Laravel's envoy when using private Github repos?
When manually cloning my repo from the production server, the ssh key seems to be accessible but when using Envoy, I always get a "Permission denied (publickey) error.
Thanks

It is probably because the ssh key on your remote server requires a password.
If you change the Envoy.blade.php to perform some other task you should be able to establish whether you are connecting to your remote correctly.
#servers(['web' => 'user#domain.com'])
#task('deploy')
cd /path/to/site
git status
#endtask
Should return something like:
[user#domain.com]: On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
If you are connecting using a Mac or Linux you probably don't have to enter your password because your terminal is using ssh-agent which silently handles your authentication.
Wikipedia article on ssh-agent
When connecting over ssh, ssh-agent isn't running and the script is being prompted for a password which is where it is failing.
To get around this you could to generate a new key on the remote machine that doesn't use a password.
If you want to restrict the ssh key to a single repository on GitHub have a look at deploy keys

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

How to use SSH connect Gitea and SourceTree?

now I long to build a private git server myself by gitea and use SourceTree as a git GUI (on Windows)
Current situation & steps:
1.I've already set up a host with gitea, and create a repos here.
2.I used SourceTree (putty) to create a public SSH key and save the .ppk file.
3.Adding this SSH on gitea page (something might be wrong because there is a verification button)
4.Using Pageant.exe on client to add key
5.Using SourceTree and try to clone the new repos by SSH
6.However, SourceTree on Client can not recognize the url
note:
1.both two computers connect to Local Area Network
2.opening port:3000 on host is done, and using "telnet HOSTNAME 3000" on client is successful
3.error message when using git command is here
Is there any step I did wrong?

GitBucket SSH Based Authentication

I configured the SSH based authentication as below
Created a public key on my UNIX server
Added the public key on my Bitbucket repository with reading and write privileges (also tried it at account level)
changed the URL from https to SSH at bitbucket and Unix server
verified the URL using and it is displaying SSH URL only
Then Tried to push, but I am getting the below error:
Permission denied (public key). fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
I have read and write access to the repository
push command
git push -u origin master
Any idea?
You should try:
GIT_SSH_COMMAND="ssh -Tv" git push
You will see what Git is using as an SSH key, and if there are any error messages.
If the error persists, it is possible there is something preventing SSH to operate properly (as in here, when not connected to a VPN)
Using HTTPS, of course, is a workaround:
git remote set-url origin https://git#bitbucket.XXX.com/XXX.com/XXX.git
After discussion, the missing step was to add the private key to the ssh-agent
ssh-add OEDQ_BIT added the private key

Pushing to GitHub without a key

I am using GitHub and C9 on a work computer and but GitHub will stop reading my SSH key after a few hours. IDK if it is because I am using my work computer (job is not currently programming), but is there a way I can push my code without an SSH key
First, check that your remote URL is indeed an ssh one:
cd /path/to/my/local/cloned/repo
git remote -v
If it is (git#github.com:user/repo), check what ssh -Tv git#github.com returns.
If SSH does not work (because SSH port might be blocked at work), switch to an HTTPS URL:
git remote set-url origin https://github.com/user/repo
From there, make sure git config credential.helper does reference an helper (like "manager" on Windows), and you will be prompted for your GitHub account username/password at the first push. After that, your credentials will be cached.

Why can the Git Shell use SSH with an HTTP remote origin URL?

I have read Configuring Git over SSH to login once. Muein Muzamil's answer says that to use SSH, we must configure as follows:
remote.origin.url=git#github.com:your_username/your_project.git
Which is to say, that in a normal Windows PowerShell, SSH does not work with HTTPS.
GitHub for Windows comes with the Git Shell. It's a souped-up PowerShell with some fancy features, including the ability to use SSH with HTTP. I know this because I just ran git push without needing to authenticate, and then ran git config -l to see that I am using HTTPS as the remote origin url.
Why does a normal Windows PowerShell require the git#github.com protocol whereas a Git Shell does not?
Windows PowerShell, SSH does not work with HTTPS
That doesn't make sense: you are using ssh or you are using https (http with ssl). One "does not work with" the other.
G4W (GitHub for Windows) has your GitHub account credentials, so it can use an https url.
A regular Git shell from msysgit/Git for Windows can use https or ssh, BUT for ssh, you need to make sure that:
the environment variable %HOME% is defined (which git-cmd.bat or git-bash.vbs do for you),
your id_rsa(.pub) private/public ssh keys are in it,
your id_rsa.pub public key is published in your GitHub account.

How do I specify the key file that capistrano will use when cloning the repository on the remote server?

Ideally, I want something like set :scm_keyfile, "~/.ssh/server-deploy-key". The path specified would of course be a path on the remote server.
If the remote user already has a ~/.ssh/id_rsa or ~/.ssh/id_dsa then git will use it by default.
If you wish to use an alternate file name for your private key, you can do this. Create a file on your remote server ~/.ssh/config and put these lines in it
Host github.com
User git
IdentityFile ~/.ssh/server-deploy-key
Now when you attempt to run a command like git clone git#github.com/xxx/yyy.git, Your ~/.ssh/server-deploy-key will be used.
Another method is to use ssh-agent forwarding. In this method, you don't need to put your deploy key on the remote server. As long as it is on your local machine, and you have enabled ssh-agent forwarding, your remote server will have access to the key and will use it . There is a nice article on github explaining this.