Setting up Git Server on windows remote computer - bash

I want to perform CI/CD on remote server running on windows for hosting my VueJs project. For doing that I have performed the following steps
I have added my ssh of my local machine to remote server as authorised keys and I am able to access the admin(cmd) remote server via ssh by using the following command.
ssh remote_server#<ip_address>
Using the above command the git bash opens cmd with following location c:/users/remote_user1 of remote server where I had added ssh of my local machine as authorized key.
I created bare git repo in C:/users/remote_user1 by logging in remote computer by rdp using the following command
git init test.git --bare
I gave Full access rights to test.git from remote server
I tried to clone test.git on my local machine using the command from git bash
git clone ssh://remoteserver#<ip_address>:/test.git
when I use the command from my local machine I get the error message from git bash
fatal: ''/test.git'' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I am not able to understand what am I am doing wrong here, Please guide me on this.

The format for ssh urls must be one of :
# 'ssh://' url :
ssh://remoteserver#<ip_address>/test.git
# scp-like syntax :
remoterserver#<ip_address>:test.git
(link to docs)
The url you posted contains a :/ which makes it a mixture of both, you should modify this url to match one of the two accepted formats.

Related

How to git push to a remote windows machine using ssh

When I try to push from a local repository to a remote windows machine, using the next command:
git push ssh://username#ip_address:/C/Users/username/project.git master
After entering credentials I get this error:
fatal: ''/c/Users/username/project.git'' does not appear to be a git
repository
fatal: Could not read from remote repository.
It seems like /C/Users/username/project.git must be replaced by C:/Users/username/project.git (without "/" before C) but when I try this variant, I get another error before asking for credentials:
ssh: Could not resolve hostname ip_address:C:: Name or service not
known
Any ':' in the SSH URL would make SSH interpret it as SCP syntax
An actual URI is as commented ssh://username#ip_address/C/Users/username/project.git
Make sure you check the case (lower/upercase) of the path used here.
Try also with /c/... vs /C/...

Gitlab connectivity from Go CI/CD

I am trying to clone a project from gitlab using GO CI/CD pipeline. Steps i did as below,
I already have ssh key which i have added to gitlab.
tried to clone from my local machine and i am able to clone using "git clone" command
I also tried on the Go-agent server using command "git clone" and project is cloned there.
After clone the project I opened the ssh folder and "known_hosts" file is modified with some key. So i have placed the ssh folder at "C:\Windows\System32\config\systemprofile" location because GO- CD pipeline looks there only.
But whenever i am trying to test the connection of pipeline it says access denied. below is the error
:
Repository ssh://git#gitlab.demo.com/exampleproject/someproject.git not found! :
Error performing command: --- Command ---
git ls-remote ssh://git#gitlab.demo.com/exampleproject/someproject.git
--- Environment ---
{}
--- INPUT ----
--OUTPUT ---
--- ERROR ---
STDERR: Host key verification failed.
STDERR: fatal: Could not read from remote repository.
STDERR:
STDERR: Please make sure you have the correct access rights
STDERR: and the repository exists.
I also tried running command ssh -T git#gitlab.demo.com but it shows "Permission denied (publickey).". Can anyone tell me why? what configuration i am missing?
If you have created a key using the default name of id_rsa, try copying it to C:\Windows\SysWOW64\config\systemprofile.ssh (https://startbigthinksmall.wordpress.com/2012/04/26/how-to-authorize-local-system-account-for-openssh/).
If that doesn't work after restarting your service, or if you think you will need to use more than one identity, the following might be helpful:
I assume restarting your Go-CD server service didn't work and that you are running your Go Server service using the default Local System account. I prefer to run using a domain account as that helps with some tricky permissions issues and this type of configuration. Take a look at this answer first: .ssh/config file for windows (git)
If you are running under a service account, your RSA keys are typically written to ~/.ssh/ - which likely translates to: C:/Users/your-account/.ssh. If this folder doesn't exist, open a command window in admin mode, cd to your account folder and run mkdir .ssh.
When Go-CD makes a connection to a Git repository using SSH, it uses git commands which in turn call ssh commands. With all these layers there are a number of approaches to configuring what identity or identities to use. An article to read first is (https://medium.com/#pinglinh/how-to-have-2-github-accounts-on-one-machine-windows-69b5b4c5b14e) Notice how the sshCommand overrides which identity git will use by specifying the file path to your rsa file.
Instead of editing the git configuration directly, my opinion is that editing the global ssh configuration will better handle multiple identities/keys and will be easier for Go-CD to handle. See https://www.ssh.com/ssh/config/. By default the ssh configuration file is located at ~/.ssh/config. If you don't have one, create a text file named config without any extension. Edit the file and add an entry that specifies the path to your Identity File (RSA Key) or files. For example (https://superuser.com/questions/366649/ssh-config-same-host-but-different-keys-and-usernames):
Host github_username1
Hostname github.com
User git
IdentityFile ~/.ssh/rsa_1
Host github_username2
Hostname github.com
User git
IdentityFile ~/.ssh/rsa_2
This establishes an host alias you can use for your material. So, instead of using git#gitlab.com/pathtorepo, you would use git#github_username2/pathtorepo if you were using the second host shown above.
Always give your Go-CD service a bounce after making changes, just in case.

Specify SSH credentials/keys in Windows Git under Jenkins user

I am using Jenkins in our builds
So I am already using the GIT Plugin
This plugin lets me specify Jenkins credentials, where we have already specified and installed/setup SSH keys.
However at the end of the build, I'd like to git tag my repo. I am calling the git.exe command line, and I get this error on a push:
Permission denied (publickey).
fatal: Could not read from remote repository.
Ideally, we don't want to use another plug in, (e.g. Git Publisher), as we are trying to do more of this via our own scripts as there is a good possibility that we may not use Jenkins in the future.
Also, ideally, we don't want to install items on our build server if we don't have to.
So the question is - how can I specify ssh keys/credentials on the command line for the given 'session'?
Thank you.
Put this in a shell script:
ssh -i path-to-your-private-key
Set the path to the shell script in GIT_SSH for Jenkins. git pull will then use that instead of plain ssh to access the remote repository.
Alternately you could configure ssh in $HOME/.ssh for the account under which Jenkins runs, but that can get tricky if your Jenkins runs as a Windows service.

Need help setting up a git server on windows

i'm trying to set up a git server on Windows, but i'm having some issues getting it all to work.
I have locally created a normal repository, and remotely i created a bare repository. On the local repository i added a single text file and committed it, but when I try to push it into the remote repository I always get the following message:
fatal: protocol error: bad line length character: fata
I searched SO and other sources, and most of them suggest it's an issue regarding command echos. I'm using freeSSHd as a SSH solution (remote repository is hosted on a windows server), and I tried to use both the git bash and the windows CMD as a command shell.
I start CMD with /Q to disable echoing and /K to change directory to a directory where repositories are located, so I don't think that would be a problem.
Using the remote desktop, i can clone the repository to a folder next to it, and using the git bash locally i can access the SSH shell and also clone the repository in the same way. But using git clone ssh://<address>:/myRepo.git I always get the above message (The SSH's working folder is the same where the repository is located). Does anyone have any idea what's going on? How can I see what command is triggering the error, and how can I see the full error message?
I also met the same error using freeSSHd as a ssh solution for git server on Windows. I couldn't find a solution for a whole day and gave up. :(
Later I found another powerful ssh server from Bitvise called WinSSHD worked well. It has free version for personal use. I suggest you to switch to it. Though I'd also like to know if there's a fix to the error we both met.
To setup ssh server with WinSSHD is quite simple, and you can add virtual accounts with private/public key access.
The key part is to setup the ssh access for git server. Please follow the steps of the blog here.
It should work well for Windows git client. For Mac, you may meet an error as follows.
grp.sh: No such file or directory
fatal: Could not read from remote repository.
To fix it, you need to create the two files gup.sh and grp.sh in your git bin directory (GIT_PATH/bin or GIT_PATH/libexec/git-core configured in system environment variable PATH) in your git server.
The content of gup.sh:
git-upload-pack.exe $*
The content of grp.sh:
git-receive-pack.exe $*

Git push command not working with msysgit setup

I installed GIT onto my windows 2k8 server following these directions: http://code.google.com/p/tortoisegit/wiki/HOWTO_CentralServerWindowsXP
All commands work fine except the "push" command. I get this error:
git.exe push -v "origin" master:master
git: '/path/to/repo' is not a git command. See 'git --help'.
Pushing to user#ipaddress/path/to/repo
fatal: The remote end hung up unexpectedly
Does anyone know how to fix this?
It looks like the remote origin is not set up correctly.
I recommend re-creating that remote, either by renaming it or deleting it and making a new one:
git remote rename origin origin_backup
git remote add origin ssh://user:pass#address/path/to/repo.git
Then try again, preferably with a fetch before you push.
What protocol are you using? If git://, then make sure there is a Git daemon listening for connections. If ssh://, make sure you have ssh access and write permission on the appropriate directory tree.
Another possibility is that the server and client are running different versions of Git. It could cause problems if one is running a version that expects commands in the format git cmd and the other expects git-cmd.
First check, if your plain SSH access to 5.16.217.81 is working: is
ssh 5.16.217.81
able to open a connection to the host?
If that is successful, ensure that you specify the path to your repo in a way your SSH server understands. In the HowTo, the path is specified different from the path you typed:
5.16.217.81/d/private/test/ (your path) vs.
<server>:d:/DeeDriveRepos/Repo2
Obviously, the CopSSH server wants colons to separate the drive letter from the host, so that your URL should be 5.16.217.81:d:/private/test/.
If you used Cygwin, your URL would be 5.16.217.81/cygdrive/d/private/test/
My pushes work for msysgit version 1.6.5 but not for 1.7.x

Resources