Getting permission denied when pushing to git vps server - windows

I installed git for windows, creating my ssh key and uploaded the public to my server.
I have this working on my Mac, trying to get it working on my windows machine now.
I did a :
chmod 700 ~/.ssh/
chmod 600 ~/.ssh/*
Here is an image of me doing a ssh -v gitserveralias
I have a config file that has the gitserveralias and port etc.
I tried clearing out the known hosts file also.
My config looks like:
Host serveralias
User xxx
Hostname 123.234.452.232
Port 22222
IdentityFile ~/.ssh/id_rsa
TCPKeepAlive true
IdentitiesOnly yes
PreferredAuthentications publickey
Again I have my setup working fine on my Mac.

Two things to check:
Do you have "PubkeyAuthentication yes" in sshd_config on your server? Try setting it.
Is there an offending key in .ssh/known_hosts? Try removing this file.

Related

Using cloud-init to write_files to ~/.ssh/ breaks SSH to EC2 instance (perhaps any machine)

I'm using a Cloudformation template in YAML with an embedded cloud-init UserData to set hostname and install packages and so on, and I've found that once I include the write_files directive it will break the default SSH key on the EC2 instance i.e. it seems to interfer with whatever process AWS uses to manage authorized_files, in EC2 logs I can see fingerprints of random keys be generating, not the expected keypair.
#cloud-config
hostname: ${InstanceHostname}
fqdn: ${InstanceHostname}.${PublicDomainName}
manage_etc_hosts: true
package_update: true
package_upgrade: true
packages:
- build-essential
- git
write_files:
- path: /home/ubuntu/.ssh/config
permissions: '0600'
owner: "ubuntu:ubuntu"
content: |
Host github.com
IdentityFile ~/.ssh/git
Host *.int.${PublicDomainName}
IdentityFile ~/.ssh/default
User ubuntu
power_state:
timeout: 120
message: Rebooting to ensure hostname has stuck correctly
mode: reboot
Removing the write_files block works fine, leave it in and I cannot SSH to the host due to ssh key mismatch.
So is it due writing a file to ~/.ssh, maybe ~/.ssh/authorized_keys gets deleted? Or maybe the permissions on the directory are changed?
Appending to ~/.ssh/authorized_keys with runcmd works fine, but I'd like to use the proper write_files method for larger files
For AWS EC2 Linux instances, the SSH public key from your keypair is stored in ~/.ssh/authorized_keys. If you overwrite it with something else, make sure that you understand the implications.
The correct procedure is to append public keys from keypairs to authorized_keys AND set the correct file permissions.
If you are setting up a set of keypairs in authorized_keys, this is OK also. Make sure that you are formatting the file correctly with public keys and setting the file permissions correctly.
The file permissions should be 644 so that the SSH server can read them.
Another possible issue is that when you change authorized_keys you also need to restart the SSH server but I do see that you are rebooting the server which removes that problem.
Ubuntu example:
sudo service ssh restart

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

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.

SSH in git behind proxy on windows 7

I am testing SSH connection for checking RSA key in git.
I am working over proxy server.
I am using window 7 and have installed msysGit-fullinstall-1.7.3.1-preview20101002.
Now in msys.exe window i have set proxy by command 'git config --global http.proxy http://host:port'
After that i have tried command 'ssh git#github.com' .
This gives me error like 'ssh: github.com: no address associated with name'
What should i do?
Setting http.proxy will not work for ssh. You need to proxy your ssh connection. See this description. To summarize:
Start git-cmd.bat and create ~/.ssh/config (notepad %home%\.ssh\config.)
ProxyCommand /bin/connect.exe -H proxy.server.name:3128 %h %p
Host github.com
User git
Port 22
Hostname github.com
IdentityFile "C:\users\username\.ssh\id_rsa"
TCPKeepAlive yes
IdentitiesOnly yes
Host ssh.github.com
User git
Port 443
Hostname ssh.github.com
IdentityFile "C:\users\username\.ssh\id_rsa"
TCPKeepAlive yes
IdentitiesOnly yes
(set the correct proxy hostname:port, and the path to id_rsa. When you use git-bash, use slashes in the path to id_rsa)
(My version of msysgit includes connect.exe, so I do not need to download and compile connect.c). A precompiled exe is also available here.
Now ssh github.com should work
Note that if you want to connect via a socks5 proxy, then change -H to -S.
ProxyCommand connect -S proxy.server.name:1080 %h %p
If you use a Linux file system, the file permission of ~/.ssh/config must be 600, but on a standard NTFS windows partition, these kind of permissions do not exist.
If your proxy requires NTLM authentication, you can use cntlm, see also this answer.
Does your proxy require a password? Then it might be that.
export http_proxy="http://<domain>\<username>:<password>#<server>:<port>"
See : How do I pull from a Git repository through an HTTP proxy? (duplicate!)

Resources