Change git .ssh credential location - windows

I am trying to pull the repo from my bitbucket repository. However when I do this I get the following error.
Could not create directory '/f/.ssh' (No such file or directory).
Failed to add the host to the list of known hosts (/f/.ssh/known_hosts)
I see that git is trying to access my /f/ drive, however because it is a network drive the contents can change. I have a /c/ drive that has an .ssh folder in it but I cannot get git to recognize that drive instead of defaulting to the /f/ drive.
I am running git bash in my C drive. And I have tried reinstalling git with my /f/ drive disconnected.
How can I get git to see my users/ssh folder?

Check your environment variables (set) in case a GIt_SSH or GIT_SSH_COMMAND would indicate a private key in /f/....
Similarly, check the output, from your local repository folder, of git config -l --show-scope --show-origin, for anything SSH related.
Those are the two sources of settings which could explain why Git is not using $HOME/.ssh for its SSH operations.

Related

How to change ownership of a local GIT repository on Windows 11

I am a relatively new/light GIT user. I use a local git repository to backup my code and I have not setup a remote repository on github.com or any other remote repository hosting system. I am working on Windows 10 & Windows 11 machines.
I created a local git repository using git init which created a .git folder under my project directory. I moved the .git folder so created to a USB thumb drive (D:) and renamed it myrepo. In my project directory I created a .git file with the setting gitdir: D:/myrepo. My though process was in case my C: drive fails I will have my local repository safe on the USB thumb drive as I have not setup a remote repository. All worked well with this setup.
Now I have a new machine (Windows 11). I copied my project code to the new machine and plugged in the USB thumb drive (D:). However when I execute any git commands I get an error -- fatal: detected dubious ownership in repository..... After some research I found out that due to a recent git security vulnerability an update to git causes it to check for repository ownership before executing commands.
One easy solution is to add a safe.directory setting git config --global -add safe.directory <project directory>. But I am trying to get to the bottom of this. ON WINDOWS PLATFORM - How does git know the owner of the local repository? As mentioned the local repository is on a USB thumb drive which is a FAT32 partition and does not have any kind of file ownership. So how does git know the repository was created by some other user? Also is there a way to change the ownership of the git local repository so that I don't have to use the safe.directory setting.
Thank you in advance for any help the community can offer.

Git remote add origin: correct URL and path to add remote repo on the local network

I am trying to set up a remote repository on a Mac on my local network. I have done the following:
Set the sharing privileges on the remote, allowing access to all users (using System Preferences/Sharing)
confirmed that I can SSH to the remote machine
created the repo in the remote directory
created a repo in the local machine directory
executed this command from the local repo directory:
git remote add origin FSM13#192.168.1.51:/Library/FileMaker\ Server/HTTPServer/htdocs/fm-php
when I attempt to push:
git push -u remote origin master
I get these errors:
fatal: 'remote' does not appear to be a git repository
fatal: Could not read from remote repository.
I get the same error using this syntax to set the remote
git remote add origin ssh://FSM13#192.168.1.51/Library/FileMaker\ Server/HTTPServer/htdocs/fm-php
FMS13 is the administrator user account on the remote machine.
What steps might I be missing?
There were three things I needed to do in order to solve this issue:
set up the SSH Keys correctly
initialize the remote repo correctly (using --bare) (this worked but I need to try a few more things. a bare repo does not have any files, just the history: http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/ )
set the path correctly for the git remote add command
Note that I am using OS X.
This youtube vid and blog post laid it out perfectly:
https://www.youtube.com/watch?v=DDzeiI2yZL8
http://crosbymichael.com/setup-password-less-login-over-ssh.html
SSH Keys:
On the local machine, starting from home directory:
cd .ssh
cat id_rsa.pub
then copy the printed public key. I happened to already have one. The blog post above explains how to create one.
SSH into the remote:
ssh FMS13#192.168.1.51
ls -a
Is there a .ssh directory? If not create one. It needs to be in the home directory.
mkdir .ssh
cd .ssh
then create a keys file
touch authorized_keys
nano authorized_keys
Then paste the key and save the file.
Confirm the install of the key by ssh'ing from the local machine:
ssh FMS13#192.168.1.51
No password was requested, so the key install was successful
Correct repo initialization:
On the remote machine, cd to the desired parent directory and:
mkdir remote-git
cd remote-git
git init --bare
On the local machine from the repo directory, the correct path was as follows to set the remote origin:
git remote add origin ssh://FMS13#192.168.1.51/Users/FMS13/Desktop/remote-git
Where FMS13 is the user on the remote computer, followed by the ip address and then the full path to the directory of the remote repo.
Push to remote:
Then back in the local machine, cd to the repo directory and:
git push origin --all
I have used something similar to this command recently which worked for me:
git remote set-url origin ssh://FSM13#192.168.1.51/USERNAME/REPOSITORY.git
Check out this link for more information. For your case, you may need to be adding the following instead. I have not seen using an IP address with this, though- so refer to the link.
ssh://git#192.168.1.51/USERNAME/REPOSITORY.git
You may also need to generate a new ssh key. Here is a link on that:
ssh-keygen -t rsa -C "your_email#example.com"

Git and SSH - How to know what address to use?

I need to set up a git repository in the production server so I can upload all my commits. So, these are the steps I followed:
Production Server (Windows Server 2008)
Installed Git
Created an empty repository at inetpub/wwwroot
Installed CopSSH
Created a new user account
Enabled the user with CopSSH
Changed the default directory of the new user to the repository address
Setted environment variables to read Git commands
Development (Windows 7 + Netbeans)
Installed Git
Created a repository right where my project is
Added all files of the project to the repository
Now, I need to upload my dev project to prod. First, I'm checking if the SSH default directory where I'm pointing to is a repository:
$ git ls-remote ssh://user#server/
fatal: '/' 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 tried adding the folder name, ".git", foldername.git, everything, and I get the same error.
Where am I having the issue? Thank you beforehand.
P.S. I already tested the new default directory and it points right to the empty repository in the server, so it's working.
EDIT: I tried this:
$ git ls-remote user#host:.git
user#host's password:
$_
I got no output. Is that okay?
You're saying the git repository at your server is located at / (say, you should have a /.git directory). As that's probably not true, I'd suggest you to connect via ssh to the server and run pwd (or it's Windows equivalent) to found where your home directory is, and then get the relative path to your repository.
Say, if running pwd right after logging into the server gives you C:\users\my_user and your git repository is at C:\users\my_user\git\my_project, use ssh://user#server:git/my_project as the URL. The : means a relative path from your home directory.
Also you can use an absolute path, as in ssh://user#server/c/users/my_user/git/my_project, or however Windows decides to name your C: partition :)
As you use ssh transport, your syntax tries to access the root of your Copssh installation, Example: if you installed Copssh at c:\copssh, then your root (/) is the same directory.
Your command git ls-remote ssh://user#server/ tries to access that directory.
Try something like
git ls-remote ssh://user#server/home/user* (c:\copssh\home\user) or
git ls-remote ssh://user#server/cygdrive/d/mygit if your repository is at d:\mygit)
If you all want to create a Windows based Git repository, you may consider to stick with Gitwin which has a fully functional free edition. It is Git on Cygwin though and Disclaimer: I'm the developer.

Setting up a Git repository on MacOS X with network drive

The given:
A mac with my work folder set up as Git repository.
A network drive (Seagate FreeAgent GoFlex Home, if that helps).
The task:
Set up the specific folder on my network drive as a place where a backup of my repository can be stored.
What I tried:
Setting up the location through Volumes path as a Remote (via Add Remote in Git GUI) - returned with:
fatal: GIT_WORK_TREE (or --work-tree=<directory>) is not allowed without specifying GIT_DIR (or --git-dir=<directory>
Then, I tried
git --git-dir=Volumes/xxxxxxx/GoFlex_Home/Personal/xxxxxxxx
in the terminal, and though it did not turn up with an error, it does not appear to be of result, as another try to add remote ended with the same error as above.
After that, I started to have doubts if specifying the path to network drive through Volumes and/or trying to add it as remote are the right things to do to solve the task. Maybe there are other ways to accomplish the goal that I am not yet aware of?
I assume you get these errors because nothing exist yet in the network share. A remote must point to an existing repository, so you first have to clone it: in the original repo do:
git clone --bare . /Volumes/xxxxxxx/GoFlex_Home/Personal/xxxxxxxx
This will copy your repository data to the network folder.
Then you can add it as a remote:
git remote add --mirror=push backup /Volumes/xxxxxxx/GoFlex_Home/Personal/xxxxxxxx
You will be able to synchronize both with:
git push backup

How to git clone a repo in windows from other pc within the LAN?

I have this git repo "c:/xampp/htdocs/**" in my main PC and its IP address is 192.168.0.6. Now I want to git clone this repo from ubuntu-server which running on a Vmware Player in my main PC.
I did
git clone \\192.168.0.6\c:\xampp\htdocs\****
and
git clone //192.168.0.6/c:/xampp/htdocs/****
from ubuntu-server and neither worked.
fatal: could not create work tree dir '****'.: Permission denied
What did I wrong?
what should I do?
You should use the command git daemon to host your repo, like this:
In your computer that will act as a server:
git daemon --base-path=<path_to_folder_containing_project_folder> --export-all
(please note that path_to_folder_containing_project is the folder containing your projects folders, it will provide all projects under that folder)
In your client:
git clone git://<local ip>/<project name>
The cloned repo will have its origin pointing to the server in your LAN, so you may want to use git remote set-url origin to point it to the original origin.
You may want to run git daemon with the --verbose option to get more details in case you run into problems.
Make sure that your c:/xampp/htdocs folder (or sub folders of it) is shared in windows, so you can navigate on the network by this address:
\\192.168.0.6\htdocs
Then you clone by using file:////. Note that there are four slashes:
git clone file:////192.168.0.6/htdocs/somerepo.git
To access the repo, you must either share it on 192.168.0.6 or must be the same domain user as the one that owns the file on 192.168.0.6.
If you share the directory on 192.168.0.6 (e.g. with share name myrepo), you access it with //192.168.0.6/myrepo.
If you are logged in on your box with a user accout that is known on 192.168.0.6, you could try accessing the repo through the administrative shares:
//192.168.0.6/c$/xampp/htdocs/...
Always use forward slashes.
Another alternative would be using SSH to access the remote machine.
Using explorer (smb) to mount the remote repository as a network share is the easiest way. I'm not entirely sure, but I think you paths might be wrong. Try file:///192.168.0.6\c:\xampp... instead.
There are two things that might have gone wrong for you:
You don't have read permission on the remote repository
You don't have write permission in the location you want to create your repository ( the current working directory or the directory you specify as second argument to git clone)
And also check if your samba server works for normal file access.
To make git repo on Windows local network you'd need to do the following:
Create new repo
git init --bare projectName.git
Share this folder (projectName.git) with the users you need
Find your PC ip with ipconfig command (e.g. 192.168.2.101)
Run this command from some user's machine
git clone //192.168.2.101/projectName.git
Note: open \\192.168.2.101 in finder to see the correct path to the projectName.git (e.g. //192.168.2.101/some/path/projectName.git)
I recently ran into this error while trying to clone a repository in a remote pc to a local pc within the same LAN network.
The solution was to first make sure the drive location in the remote pc had the correct access rights for the local PC(Read/Write-which can be set using windows sharing options)
Copy the path of the remote repository. In your local pc paste the path in a windows explorer window. Then copy its directory address and paste it into any browser.
Now you should get a link with the hostname and the correct cloning URL format.
Use this link to clone the repository in the local pc.
Hope this helps.
Cheers.
"I have a few different computers that I use at home and I wanted to set up GIT that I can access my code from any of them. It took me a bit because I was too used to working with a client-server model where I designate one machine as the "server" that holds the repository and everything else was a client. Instead, GIT seems to operate more like a merge tool and every local copy is its own "master." Once I understood that, it turns out that setting up GIT is very simple and just needs GIT itself and SSH".
To read more you can check this link:
http://blog.lazyhacker.com/2010/04/setting-up-git-for-home-network.html

Resources