orionlin
orionlin

Reputation: 207

Cannot "git clone" from local host

Two laptops with ubuntu installed.

ssh and git config for user1 on these systems are identical settings.

cat /home/user1/.ssh/config
Host system1
        Hostname <system1_ip>
        User user1
        IdentityFile ~/.ssh/id_rsa_common

cat /home/user1/.gitconfig
[user]
        email = [email protected]
        name = user1

Rsa private/public key are also the same in these systems

user1@system1:~/.ssh$ ls -al
total 28
drwx------  2 user1 user1 4096 Apr 18 00:09 .
drwxr-xr-x 50 user1 user1 4096 Apr 18 00:06 ..
-rw-------  1 user1 user1  408 Feb 18  2017 authorized_keys
-rw-rw-r--  1 user1 user1   91 Apr 18 00:04 config
-r--------  1 user1 user1 1675 Feb 24  2017 id_rsa_common
-rw-r--r--  1 user1 user1  408 Feb 24  2017 id_rsa_common.pub
-rw-r--r--  1 user1 user1 1550 Apr 12 19:51 known_hosts


user1@system2:~/.ssh$ ls -al
total 24
drwxrwxr-x  2 user1 user1 4096 Apr 17 20:12 .
drwxr-xr-x 21 user1 user1 4096 Apr 17 23:08 ..
-rw-rw-r--  1 user1 user1   91 Apr 17 20:12 config
-r--------  1 user1 user1 1675 Apr 17 20:12 id_rsa_common
-rw-r--r--  1 user1 user1  408 Apr 17 20:12 id_rsa_common.pub
-rw-r--r--  1 user1 user1 1550 Apr 17 20:12 known_hosts

A git repository created in system1.

user1@system2 can do "git clone" properly

user1@system2:~/job/test$ git clone ssh://<system1_ip>/home/git_root/mypicture.git
Cloning into 'mypicture'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
orion@ubuntu-pavilion:~/job/test$ ls -al mypicture/
total 12
drwxrwxr-x 3 user1 user1 4096 Apr 18 01:38 .
drwxrwxr-x 3 user1 user1 4096 Apr 18 01:38 ..
drwxrwxr-x 7 user1 user1 4096 Apr 18 01:38 .git

user1@system1 try to "git clone"

The response is Permission denied (publickey).

user1@system1:~/job/git_test/local/temp$ git clone ssh://<system1_ip>/home/git_root/mypicture.git
Cloning into 'mypicture'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Debug with this command:

GIT_SSH_COMMAND="ssh -vvv" git clone ssh://system1_ip/home/git_root/mypicture.git

Part of dump shows it cannot find the private key:

...
debug1: SSH2_MSG_NEWKEYS received
debug2: key: /home/user1/.ssh/id_rsa ((nil))
debug2: key: /home/user1/.ssh/id_dsa ((nil))
debug2: key: /home/user1/.ssh/id_ecdsa ((nil))
debug2: key: /home/user1/.ssh/id_ed25519 ((nil))
....
debug1: Trying private key: /home/user1/.ssh/id_rsa
debug3: no such identity: /home/user1/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /home/user1/.ssh/id_dsa
debug3: no such identity: /home/user1/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/user1/.ssh/id_ecdsa
debug3: no such identity: /home/user1/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/user1/.ssh/id_ed25519
debug3: no such identity: /home/user1/.ssh/id_ed25519: No such file or directory

How to change ssh/git config or someghing else for user1@system1 to "git clone" this repository on system1?

Upvotes: 1

Views: 896

Answers (3)

orionlin
orionlin

Reputation: 207

Root cause is user1@system1 cannot recognize ssh://system1_ip while executing git clone.

${HOME}/.ssh/config only specify the key in Host system1 not Host system1_ip

So it works properly if user1@system1 to apply ssh://system1

BUT so far I have no idea why user1@system2 can specify the key if ssh://system1_ip .

Upvotes: 0

CodeWizard
CodeWizard

Reputation: 142612

Try the following:

Add the key to the ssh:

ssh-add

This will add the default key unless you provide the specific key you wish to add

ssh-add is a command for adding SSH private keys into the SSH authentication agent for implementing single sign-on with SSH. The agent process is called ssh-agent

read below see how to run it.

Start/restart the ssh=agent

eval $(ssh-agent)

This will start the ssh agent and will print out the PID of the servive.

The ssh-agent is a helper program that keeps track of user's identity keys and their passphrases. The agent can then use the keys to log into other servers without having the user type in a password or passphrase again.

Upvotes: 0

Ondrej K.
Ondrej K.

Reputation: 9679

I would venture a guess that too permissive ${HOME}/.ssh/config is tripping your ssh, try restricting it to 0600. Looking at the verbose output, it tries the default names of keys and not ~/.ssh/id_rsa_common You've specified.

You may also correct the permission on your system two. Usually $HOME/.ssh/ would be 0700 and config and keys as well as known_hosts and authorized_hosts would be 0600.

However, it's just a guess based on the available info. And one thing stomps me (but could be *buntu specific), my ssh would reject ${HOME}/.ssh/config with permbits as seen on your system, but it would also let me know it did so on the console with Bad owner or permissions on /home/user1/.ssh/config.

Hope this helps.

Upvotes: 2

Related Questions