克隆并推送到远程服务器存储库

时间:2017-09-20 20:03:09

标签: git openssh

我有一个可以克隆的git存储库的远程服务器...问题是我需要使用ssh访问该服务器,并使用我在本地计算机上保存的密钥文件身份验证...

我创建了一个空的本地文件夹,然后我做了:

git clone ssh://username@45.645.465.12:/path_to_my_rep/.git

但是,当然,我收到了一个权限被拒绝的错误..我怎么能说git在哪里选择我的ssh密钥文件???

我尝试在〜/ .ssh / conf上创建一个conf文件并添加以下行:

Host 45.645.465.12
    Hostname 45.645.465.12
    IdentityFile    ~/.ssh/myKeyFile.pem
    IdentitiesOnly yes

但是我收到了这个错误:

Cloning into 'gestioner'...
Permission denied (publickey).
fatal: Could not read from remote repository.

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

2 个答案:

答案 0 :(得分:0)

如果您已经生成了密钥对,则需要将您的公钥提供给git server admin,以便将其添加到授权密钥列表中。密钥应附加到authorized_keys dir。

内的.ssh/文件中

答案 1 :(得分:0)

我在〜/ .ssh /下更新了我的conf文件,它看起来像这样:

Host myhost
    User myUser
    IdentityFile /path_to_my_key_file

我的主要错误是我以root身份运行git clone而且因为openSSH没有在home / user /下读取我的conf文件,而是在/ root /...

在纠正了这两件事之后,git clone工作得很好:)

相关问题